Cron Jobs

Top  Previous  Next

The following recurring tasks (cron jobs) must be sheduled on the Windows Server (Server Manager > Configuration > Task Sheduler > Task Sheduler Library). They automate the deletion of unneeded PDF files on the server, ensure synchronicity between the file system and  the mySQL database and between the 3P OpenCart Administration and 3P BackOffice. Make sure domain is the correct name of your domain:

1. c:\curl\curl.exe http://shop1.domain/3p_service/json_clean_folder.php

Removes upload folders (from old subshops) inside c:\<company>\3p_upload\ that don't have a valid subshopid.
Removes upload folders that don't have corresponding session records in oc_3p_upload. Usually this can only happen if the administrator manually removes records in the 3P BackOffice.
Removes all queue files that are not registered in the 3p_queue_product table anymore.
Schedule: run on a daily basis or more. These files are not used by the system (no db records), so it's not a problem to delete them daily.
 

2. c:\curl\curl.exe http://shop1.domain/3p_service/json_clean_upload.php

Option PurgeIncompleteUploadDays (table 3p_option): checks oc_3p_upload table for uploads that have not been ordered after a number of days. This also applies to items in the cart that were deleted by the customer. The upload records and its PDF files will then be removed.
Option CleanupOrphanFiles (table 3p_option): when a customer is deleted manually in the OpenCart Administration instead of the 3P BackOffice, all corresponding orders & PDF upload files will be removed.
Schedule: run on a daily basis or more.
 

3. c:\curl\curl.exe http://shop1.domain/3p_service/json_clean_orderbydays.php

Option PurgeOrderFilesDays (table 3p_option): will check the oc_order table, whether a Waiting for Payment (1) order has expired or a Shipping (3) order has not been re-ordered after defined days. Will send reminder mails to the customer, and after the deadline is passed, the order_status_id will be set to Order closed (5). All PDF files will then be deleted and the order items cannot be re-ordered anymore.
Clean up invalid orders (and files) that have an order_status_id of Undefined (0) and are at least 5 days old. These can result from an OpenCart bug, where cancelled payments create junk order records in the database. They have no effect on the functionality of the shop however.
Schedule: run on a daily basis only.
 

4. c:\curl\curl.exe http://shop1.domain/3p_service/json_check_status.php

Will check the job.xml status files in all print queue folders, if an order item was marked as Processing (15), Shipping (3) or Failed (10) by the printer inside the job.xml. Will then create a cron job change_order_status (see 5. below), which will change the order status in the database respectively. If an error message is posted by the printer during automatic processing in the OrderStatusMessage field, an email with this message is sent to the admin.
Option DeleteFilesOnFailDetect (table 3p_option): a job.xml status change to Failed (10) will create a cron job change_order_status, which will change the order status to 10 in the DB. If DeleteFilesOnFailDetect is false, it will preserve queue files, allowing the admin to discuss and possibly fix the problems with the printer.
If VisibleToDate and OrderByDate for a product is reached (see products.xml), this job will set the stock_status of the product to Expiring and Unavailable respectively, and disable this product in the store.
Schedule: run every 30 min

sign_warningOnly if the Admin sets the status back to Queued (2), the status value in the job.xml file will also be updated again, signaling to the printer to repeat the printing process.

lightbulb_onIf the printer changes status values of print jobs only in the 3P BackOffice interface instead of through SMB folder sharing (by editing the job.xml files), you can skip sheduling this cron job.
 

5. c:\curl\curl.exe http://shop1.domain/3p_service/json_cronjob.php

Will check table oc_3p_job for new status change jobs coming from json_check_status.php (see 4 above), resulting from changes by the printer in the job.xml files. The databases will then be updated by this cron job.
Schedule: run every 3 min

 

lightbulb_on

Installation

In the SVN subfolder \4all\3p_install, locate the file curl 7.3.4 win64.zip and unpack this to c:\curl\
Open opencart\3p_installer\create_crons.bat in Notepad++ and replace domain.name with your domain name. Run create_crons.bat to shedule the Cron Jobs.
For runtime protocoling, open Server Manager Configuration > Task Sheduler and call Enable all Tasks History.
For every task, set Run whether user is logged on or not (you will be asked for the Administrator password), otherwise the task will not run when you close the Remote Desktop Session.

sign_warning

Warnings

Before you do any maintenance on your database, or in case of migration to another disk, you must switch off all cron jobs to prevent file loss. Do a backup of all database and upload files before you modify a live system in any way!
Never change the customer_id of a customer! This will break the relation to the orders and cause the cron jobs to delete uploaded files.
Never change the subshopid or store_id of your shops! This will lead to a complete data loss.
Never rename any files or folders on the disk, unless you also rename the file names in the DB records! The cron jobs are designed to remove files that have no corresponding DB records.
If you find the cron jobs too dangerous, because uploaded files are automatically deleted in the background, then you can deactivate the jobs and run them manually from time to time. Or you could prolong the interval to monthly instead of daily.

2015 © 3P Photobook Publisher