Is there a way to make a script where I can do stuff like $this->EE->db
(i.e. using Expression Engine's classes, for example to access the database), but that can be run in the command line?
I tried searching for it, but the docs don't seem to contain this information (please correct me if I'm wrong). I'm using EE 2.4 (the link above should point to 2.4 docs).
The following article seems to have a possible approach: Bootstrapping EE for CLI Access
- Duplicate your index.php file and name it cli.php.
- Move the index.php file outside your DOCUMENT_ROOT. Now, technically, this isn’t required, but there’s no reason for prying eyes to see your hard work so why not protect it.
- Inside cli.php update the $system_path on line 26 to point to your system folder.
- Inside cli.php update the $routing['controller'] on line 96 to be cli.
- Inside cli.php update the APPPATH on line 96 to be $system_path.'cli/'.
- Duplicate the system/expressionengine directory and name it system/cli.
- Duplicate the cli/controllers/ee.php file and name it cli/controllers/cli.php.
- Finally, update the class name in cli/controllers/cli.php to be Cli and remove the methods.
- By default EE calls the index method, so add in an index method to do what you need.