RO CSVI

Setting up a cron job

Cron command requirements

The cron command is a combination of a few settings:

  1. The PHP executable
  2. The path to cron.php
  3. The arguments

Let's take a closer look at these requirements.

PHP executable

The PHP executable is the program that processes the cron script. How the PHP executable is called completely depends on your host, check with them where your PHP executable resides. Some examples of the PHP executable are:

  • php
  • /usr/local/bin/php

Path to the cron.php file

The file that starts the import or export is called cron.php, this file can be called directly from the command line. The file is located in /administrator/components/com_csvi/helper/cron.php. It is important to know where the file is as you need to use the path to build the cron command. The full path needs to be the complete path to the cron.php file. The full path depends on your host, check with them what your path needs to be. Some examples of the full path are:

  • /home/domain/public_html/administrator/components/com_csvi/helper/cron.php
  • /www/administrator/components/com_csvi/helper/cron.php

Arguments for import and export

There are several arguments that need to be passed on to make the cron work. These arguments are:

The secret key as specified in the template

  • --key

The password belonging to the supplied username.

  • --template_name
  • --template_id

The name of the template that needs to be used. This must exactly match the name of the template in the template list. Instead of using the template name, the template ID can also be used.

  • --file
The full path and name of the file to import. This is only used for imports. It is also possible to store the filename in the template by setting the source to load from server and specify the full path to the filename. Some examples of the full path and name are:
  • /home/domain/public_html/example.csv
  • /www/example.csv

Optional: the template option to override

  • --form.<fieldname>

Replace <fieldname> with the name of the field you want to override. To know the name of the fieldname, edit your template and click on the Cron button to show the field names.
CSVI cron help

Clicking on the Cron button will show the field names below the options in italic. Clicking the Cron button again, will hide the field names.

Arguments for maintenance

The maintenance task takes several arguments to run. These arguments are:

The task to execute, this is always maintenance

  • --task="maintenance"

The name of the extension to run the maintenance task for. This is always the internal name of the extension. 

  • --addon

For example for VirtueMart the arguement addon will be --addon="virtuemart".

The name of the operation to run.

  • --operation

Maintenance operations supported by addons are listed below.

VirtueMart

  • --operation="sortcategories"      (Sorting Categories)
  • --operation="removeemptycategories"  (Removing empty categories)
  • --operation="removeproductprices"  (Removing Product prices)
  • --operation="unpublishproductbycategory" (Unpublish products if the category it belong to is unpublished)
  • --operation="removeproductmedialink" (Remove link between Product and images)
  • --operation="backupvm" (Backup VirtueMart Database. Backup file will be saved at tmp/com_csvi)
  • --operation="emptydatabase" (Empty VirtueMart tables)
  • --operation="vmexchangerates" (Load exchange rates for VirtueMart)
  • --operation="ecbexchangerates" (Load European central bank exchange rates)
  • --operation="cleanmediafiles"  (Clean media files for which images are missing)
  • --operation="checkduplicateskus" (Check if there are duplicate SKUs in VirtueMart tables)
  • --operation="refreshsefurls" (Refresh SEF URLs)
  •  --operation="relatedproductsduplicates" (Check for Duplicate related products and categories)

HikaShop

  • --operation="removeproductprices"  (Remove prices linked to products)
  • --operation="emptydatabase" (Empty HikaShop Tables)
  • --operation="refreshsefurls" (Refresh SEF URLs for product export)

K2

  • --operation="refreshsefurls" (Refresh SEF URLs for product export)

J2Store

  • --operation="removeproductprices" (Remove prices linked to products)
  • --operation="emptydatabase"  (Empty J2Store Tables)

Joomla Content

  • --operation="refreshsefurls" (Refresh SEF URLs for export)

Build the cron command

With all the requirements in place we can build the cron command. The command is build up in this order:
PHP executable path to the cron.php arguments
 
Including the arguments the full command for an import can look like this:

/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword" --template_name="CSVI Product import" --file="/home/domain/public_html/example.csv"
/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword" --template_id="123" --file="/home/domain/public_html/example.csv"

Including the arguments the full command for an export can look like this:

/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword" --template_name="CSVI Product export"
/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword" --template_id="124"
/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword" --template_id="124" --form.language="nl-NL"

Including the arguments the full command for a maintenance task can look like this:

/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --task="maintenance" --addon="csvi" --operation="optimizetables"

Make sure this command is all on one line. In a cronjob you cannot span a command across multiple lines.

Need help?

The cron command comes with a built-in help screen. You can get the help screen by issueing this command:

/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --help

Setting up the cron command

How to setup the cron command depends on your host. Check with them how to set it up for your site. There are 2 control panel systems used often, these are cPanel and DirectAdmin, instructions for these follow here.

cPanel

  1. Login to cPanel for your site
  2. Click on Cron Jobs in the Advanced area.
    cPanel advanced cron
  3. Select the time you want the job to run in the Add New Cron Job
  4. Fill in your cron command in the Command box
    cPanel cron setting
  5. Click on Add New Cron Job
  6. The job is now scheduled

DirectAdmin

  1. Login to DirectAdmin for your site
  2. Click on Cronjobs in the Advanced Features area
    directadmin advanced cron
  3. Fill in the time you want the job to run in the Create a New Cron Job
  4. Fill in your cron command in the Command box
    directadmin cron setting
  5. Click on Add
  6. The job is now scheduled

The output

The output has been optimized for command line output, this means there is no HTML code. This can be forwarded (piped) to a file for later analyzes.

More articles on this subject