Cron command requirements
The cron command is a combination of a few settings:
- The PHP executable
- The path to cron.php
- 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
- --template_alias
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 alias or the template ID can also be used.
- --file
- /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.
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)
- Specify the template ID to use a specific template using the option template, replace X with the ID of the template
--template="X"
- Specify the template ID to use a specific template using the option template, replace X with the ID of the template
- --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
Using template name in argument
/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"
Using template ID in argument
/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:
Using template name in argument
/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword"
--template_name="CSVI Product export"
Using template ID in argument
/usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword"
--template_id="124"
Using language name in argument
/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:
Below command is an example for optiomizetables Maintenance task using CSVI cron
/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.
Using repeatable form names in argument
It is also possible to include repeatable field values in cron command. In the export templates the Group By Fields and the Sort Fields are repeatable fields. You can include these field values in cron command like
usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword"
--template_id="124" --form.sortfields="alias#ASC|catid#ASC"
Here alias and catid are the name of the fields and ASC is the order for sorting the export data. Name and order are separated by # and multiple sort fields are separated by |.
usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword"
--template_id="124" --form.groupbyfields="alias|catid"
Here alias and catid are the name of the fields by which export data is grouped.
Using multiple filter values in cron command
You can include multiple filter values for the templates which support them. For example in Joomla content export template multiple categories are used for filtering export data. Multiple categories are separated by |.
Cron command to filter by multiple categories
usr/local/bin/php /home/domain/public_html/administrator/components/com_csvi/helper/cron.php --key="mysecretword"
--template_id="124" ----form.content_categories="2|3"
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
- Login to cPanel for your site
- Click on Cron Jobs in the Advanced area.
- Select the time you want the job to run in the Add New Cron Job
- Fill in your cron command in the Command box
- Click on Add New Cron Job
- The job is now scheduled
DirectAdmin
- Login to DirectAdmin for your site
- Click on Cronjobs in the Advanced Features area
- Fill in the time you want the job to run in the Create a New Cron Job
- Fill in your cron command in the Command box
- Click on Add
- 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.