OCOK

OCOK: OpenCart OK commandline utility

View project on GitHub

Installation

Composer (global)

OCOK can be installed globally via composer

composer global require beyondit/ocok

Make sure to place the ~/.composer/vendor/bin directory in your PATH (or C:\%HOMEPATH%\AppData\Roaming\Composer\vendor\bin if working with Windows) so the ocok executable is found when you run the ocok command in your terminal.

Composer (local)

OCOK can be installed locally via composer

  • Add "beyondit/ocok": "*" to composer.json.
  • Run composer install
  • Use vendor/bin/ocok to execute OCOK commands in your terminal.

Phar

OCOK can be installed globally as Phar package

Download ocok.phar

wget http://beyond-it.github.io/ocok/ocok.phar

To install globally put ocok.phar in /usr/local/bin/.

sudo chmod +x ocok.phar && mv ocok.phar /usr/local/bin/ocok

Now you can use it just like `ocok` in your terminal.

Commands (Usage)

Backup

The backup command allows for backing up the images folder and the database, depending on the image (-i) or on the database (-d) option.


ocok backup -i -d

The execution of the above command would create a zip file inside the opencart folder, which would contain an SQL dump and all the images.

Cli Task

The cli task can call controllers through a command line interface (CLI) just as easily as through a web browser. This functionality can be used e.g. to automate tasks with cron jobs or anything else that needs to interface over the command line.

Getting started is as easy as creating a new controller inside the admin or as well inside the catalog package. When calling the controller's actions via CLI a is_cli variable (set to true) is available.

The following code snippet shows a controller, which is stored as admin/controller/task/example.php.


class ControllerTaskExample extends Controller {
    public function index() {
        if (isset($this->is_cli) && $this->is_cli === true) {
            // work done by the controller

            if (isset($this->request->get['param1'])) {
                echo "param1 is " . $this->request->get['param1'] . "\n";
            }

            if (isset($this->request->get['param2'])) {
                echo "param2 is " . $this->request->get['param2'] . "\n";
            }

        }
    }
} 

Simply call the ocok run command inside the Opencart folder like so:


ocok run task/example

It is also possible to add parameters to the call, which are set as GET or POST parameters inside the controller.


ocok run task/example param1=foo param2=bar

The above stated command would output:
param1 is foo
param2 is bar

Additionally, it is possible to run controllers from the catalog package. This requires to add the -c option to the command line call. This of course requires a controller catalog/controller/task/example.php inside the catalog package.


ocok run task/example -c

Another option (-p) is available which allows setting the given parameters as POST parameters.


ocok run task/example -p param1=bar param2=foo

Finally, running OCOK cli tasks as scheduled cron jobs is simple. After adding the following line to a crontab file, the examplary controller would be executed every minute.


* * * * * (cd /path/to/opencart/folder; /path/to/ocok run task/example param1=foo param2=bar)

Install

The install command provides a wrapper around the opencart cli_install.php script. Additionally, it can download Opencart if it is not found on the current foler.

Running the following command within an empty folder downloads and installs the latest version of Opencart, with the stated database and Opencart configurations.


ocok install -d mysqli -o localhost -u dbuser -p dbpassword -b dbname -x dbprefix -U ocadmin -P ocpass -e example@ocok.com -s http://localhost/opencart/