RO CSVI

Setting up a cron job in RO CSVI

Setting up a cron job in RO CSVI varies based on your Joomla version. This document will explain how to setup a cron job in the different Joomla versions.

Joomla 3

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
  • --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
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)
    • Specify the template ID to use a specific template using the option template, replace X with the ID of the template
      --template="X"
  •  --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:

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

 

Joomla 4

The cron command is a combination of a few settings:

  1. The PHP executable
  2. The path to joomla.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 joomla.php file

The file that manages all CLI jobs is called joomla.php, this file can be called directly from the command line. The file is located in /cli/joomla.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 joomla.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/cli/joomla.php
  • /www/cli/joomla.php

Import

php joomla.php -vvv rocsvi:import --template_id=582 --key=phoca

To set the import file location in cron command

php joomla.php -vvv rocsvi:import --template_id=493 --key=xyz123 --file=/home/domain/public_html/joomla4/content.csv

You can also use form fields as agrs in import and export cron commands.

Few examples:

To set language field in VirtueMart Product import template

php joomla.php -vvv rocsvi:import --template_id=485 --key=xyz123 --form_fields=language="nl-NL"

To Keep content ID field in Joomla content import template

php joomla.php -vvv rocsvi:import --template_id=493 --key=xyz123 --form_fields=keepid=1

Export

php joomla.php rocsvi:export --template_id=527 --key=secret --form_fields=recordstart=2 --form_fields=recordend=4

An example to use sort fields in an export template

php joomla.php rocsvi:export --template_id=483 --key=xyz123 --form_fields=sortfields="product_sku#ASC|category_id#ASC"

An example to use Groupby fields in an export template

php joomla.php rocsvi:export --template_id=483 --key=xyz123 --form_fields=groupbyfields="virtuemart_order_item_id|virtuemart_order_id"

Other Arguments for import and export are

Instead of template_id you can also use

  • --template_name
  • --template_alias

Maintenance

RO CSVI

Update Available Fields

php joomla.php rocsvi:maintenance --addon csvi --operation updateavailablefields

Clean temp folder

php joomla.php rocsvi:maintenance --addon csvi --operation cleantemp

ICEcat indexes

php joomla.php rocsvi:maintenance --addon csvi --operation icecatindex --icecat_index 1 --icecat_supplier 1 --icecat_gzip 0

--icecatlocation /var/www/html/joomlacms.test/tmp/com_csvi

--icecat_gzip 0/1

--icecat_index 0/1

--icecat_supplier 0/1

--loadtype 0/1

0 mean to import the file as 1 big file using LOAD DATA. The LOAD DATA options must be enabled for this to work.

1 means to import the file line by line and no extra options need to be enabled.

Backup templates

php joomla.php rocsvi:maintenance --addon csvi --operation backuptemplates --templates 104,103,87

These backups are always stored on the server

Restore templates

php joomla.php rocsvi:maintenance --addon csvi --operation restoretemplates --server_file /var/www/html/tmp/backup.xml

--useexistingrules 0/1

--overwriteexisting 0/1

Install example templates

php joomla.php rocsvi:maintenance --addon csvi --operation exampletemplates --addons com_contact --addons com_content

--enablelog 0/1

Optimize tables

php joomla.php rocsvi:maintenance --addon csvi --operation optimizetables

Delete RO CSVI tables

php joomla.php rocsvi:maintenance --addon csvi --operation deletetables

HikaShop

Remove product prices

php joomla.php rocsvi:maintenance --addon hikashop --operation removeproductprices

--manufacturer The ID of the brand to delete prices for

Empty database

php joomla.php rocsvi:maintenance --addon hikashop --operation emptydatabase

Refresh SEF URLs

php joomla.php rocsvi:maintenance --addon hikashop --operation refreshsefurls

--template The template ID to use the settings from

--emptytable 0/1

J2Store

Remove product prices

php joomla.php rocsvi:maintenance --addon j2store --operation removeproductprices

-- manufacturer The ID of the brand to delete prices for

Empty database

php joomla.php rocsvi:maintenance --addon j2store --operation emptydatabase

Refresh SEF URLs

php joomla.php rocsvi:maintenance --addon j2store --operation refreshsefurls

--template The template ID to use the settings from

--emptytable 0/1

Joomla Content

Refresh SEF URLs

php joomla.php rocsvi:maintenance --addon content --operation refreshsefurls

--template The template ID to use the settings from

--emptytable 0/1

VirtueMart

Sort Categories

php joomla.php rocsvi:maintenance --addon virtuemart --operation sortcategories

--language The country language tag all lowercase and separated by an underscore for example nl_nl

Remove Empty Categories

php joomla.php rocsvi:maintenance --addon virtuemart --operation removeemptycategories

Remove product prices

php joomla.php rocsvi:maintenance --addon virtuemart --operation removeproductprices

--manufacturer The ID of the manufacturer to delete prices for

Unpublish Product By Category

php joomla.php rocsvi:maintenance --addon virtuemart --operation unpublishproductbycategory

Remove Product Media Link

php joomla.php rocsvi:maintenance --addon virtuemart --operation removeproductmedialink

Backup VirtueMart

php joomla.php rocsvi:maintenance --addon virtuemart --operation backupvm

--droptable 0/1

Empty database

php joomla.php rocsvi:maintenance --addon virtuemart --operation emptydatabase

Load VirtueMart Exchange Rates

php joomla.php rocsvi:maintenance --addon virtuemart --operation vmexchangerates

Load European Central Bank Exchange Rates

php joomla.php rocsvi:maintenance --addon virtuemart --operation ecbexchangerates

Clean Media Files

php joomla.php rocsvi:maintenance --addon virtuemart --operation cleanmediafiles

Check Duplicate SKUs

php joomla.php rocsvi:maintenance --addon virtuemart --operation checkduplicateskus

Refresh SEF URLs

php joomla.php rocsvi:maintenance --addon virtuemart --operation refreshsefurls

--template The template ID to use the settings from

--emptytable 0/1

Check Duplicate SKUs

php joomla.php rocsvi:maintenance --addon virtuemart --operation checkduplicateskus

Fix Related Product/Categories Duplicates

php joomla.php rocsvi:maintenance --addon virtuemart --operation relatedproductsduplicates

Patch vmpsplugin.php File

php joomla.php rocsvi:maintenance --addon virtuemart --operation patchvmpspluginfile

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.