Automatic Publication at Scheduled Times (Cron job)
The jDownloads automatic monitoring can be started at a time schedule with a 'Cron job'.
Suppose you need to publish a large number of download files. These could have been setup on a test site and now you want to upload and publish them. Or maybe you allow certain other users to upload but you do not want to allow them to actually publish. Transfering a large number of files (downloads) in a directory structure (category structure) from your PC to your website is readily achieved using your favourite ftp program such as FileZilla. These downloads, and possibly new categories, will need creating into Downloads and publishing.
Before doing anything else if you want to enable monitoring and to allow automatic publication you need to look at the settings in the Monitoring section of the jD Configuration. These include Download directory monitoring?, Monitor all file types?, Monitor only the following file types and Automatically publish Downloads? So set those up first to suit your current needs. For example if you as the administrator are initially copying over large number of files you probably would set "Automatically publish Downloads?" to Yes. But later if you open it up to some general users then you may wish to review each Download before publishing it by setting "Automatically publish Downloads?". to No. That is set it whichever way suits your current needs.
However you are strongly recommended to set Download directory monitoring? to No. If you leave it at Yes then there may be a fight between the jD automatic monitoring and the cron initiated monitoring. It is not a good idea to have two 'scan' processes runing at the same time, they could both be actioning the same file with unknown consequences. So set it to No to avoid that possibility.
jDownloads provides facilities to automate the publication process. One of them is to activate the Automatic Monitoring in the Monitoring section of the Configuration. This actually runs every time you access the jDownloads control panel in the backend. If you have a large number of files the delay whilst monitoring is carried out can be frustrating, so this facility is often disabled. Another method is to click on the manual scan on the right hand side of the jDownloads control panel. Both of these methods require that you are actually present and accessing the jDownloads control panel.
Whichever way you choose you will need the relevant url link. This may be found by copying the link from the 'Check Download area now' on the jD Control Panel. The link will be something like the following
"https://<your-site>/administrator/components/com_jdownloads/helpers/scan.php?key=this-is-a-key" where the key part is unique to your specific site. This secret key is the one created by Joomla! for your site. It may be found in the Joomla! System - System Information - Configuration tab. Scroll down until you find the Secret key. It is usually a 32 character sequence such as for example say stoAs118BoemlusWO1mlaxoesPl9wrlU - the one shown is artificial and not real. jDownloads compares the key you supply with the one in your Joomla! configuration file so that no one else can initiate a Cron on your site.
Any Cron job consists of two parts: the scheduling time string, and the command which eventually get combined..
The time string is made up of 5 items specifying: minutes hours days months weekdays. The syntax is five space separated 'values'; but the values not always obvious! Some examples are given below but if you want to determine other time strings then you could look at https://crontab-generator.org/ . All times are usually UTC based so you may need to take that into account.
Time string */30 4 * * * would cause execution every day at 4:00 and 4:30.
Time string 3 4 * * * is once a day at 4:03 am
Time string */20 * * * * is every 20 minutes
The general structure of the command part for use with jDownloads is the unix command: "curl -s /dev/null https://websitename/script-name"
Specifically something like: curl -s /dev/null https://<your_site>/jda1/administrator/components/com_jdownloads/helpers/scan.php?key=qwertySS1zW0kIdQ1VZ7xxxyyy which also includes the Secret key specific to your site as described above. The key shown is not a real one!
Using cPanel Cron job
Most cPanel implementations have an Advanced section with a Cron job icon. These notes apply to cPanel version 54.0 (build 22) but all recent versions are similar.
After clicking on th Cron Job icon a screen such as opposite appears. The cPanel has the ability to send an email every time the cron job runs. You just put in your email address into the appropriate field. If you leave it blank then no emails are sent. If you have multiple cron jobs there is a way of seclectively setting which cron jobs will not send an email.
The email sent is a full html page that is the same text mixed with html tags as would have been generated if you had run the scan process manually from the jD control panel.
As is obvious from the picture opposite setting up the schedule times for the cron to run is reasonably simple. The easiest to use is the common settings which can be readily adjusted in the individual time parts. In the example shown opposite the schedule is twice a day at 00 and 12:00 on every day. One could edit the hour part to say 1 and 5 to give an unequal spacing.
The Command part is simply
where your-key is the Joomla! Secret key specific to your site (see System - Site Information - Configuration tab Secret field), and the <your_site> is replaced by www.yoursite.com as appropriate.
After clicking on the 'Add New Cron Job' button a line appears something like below
The resultant schedule and command are quite obvious. Importantly one is able to edit the 'cron line' to change say the schedule. For initial testing setting I set the cron job to run every five minutes with just a few files. It was then edited to run just twice a day..
If the cron job does not run then you should initially check with yout host site provider as they may have imposed some restricions such as a minimum time interval.
Joomla! Extension XTCronjob (previously known as JPrc Cronjobs)
This uses a regular Joomla extension that simulates a Cron job. One sets up the time and command as below but the time schedule is only examined when a user accesses the front end of the site That is one sets a 'target' time for executing the scan but it does not actually start at that time. The next time anyone, which maybe a web crawler or a real user, vists your site XTCronjob looks to see if the scan has become due and either initiates the scan or goes back to sleep. After running the scan it resets itself for the next target time after the current time, it does not run multiple scans to catch up but re- computes the next scheduled time.
The following modified instructions are based on those from jDownloads User: rblackman. Many thanks that he shared this with us.
One thing to note is that this extension requires the php exec() function so you may need to check with your hosting service that is enabled on your site.
Install the component as usual . Check that the plugin 'System - Extly XTCronjob' is enabled as that is vital (it is usually enabled but ...). XTCronjob works well but it is not what one would call 'polished'
Click on the XTCron job Comonent and select the Categories section.
Create a new category with a suitable name.
After creating the category, select Task and click on New.
This will show a form like the one opposite.
Add a title and select the category.
Now select the task type as Web Address fopen
The Command is simpler here, it is just the web address of the routine we want to run
Regretable the shedule selector does not seem to operate - maybe it will be fixed in a later release.
So enter the required string manually in the Cronjob Expression field . The examples are reproduced again for convenience
Time string */30 4 * * * would cause execution every day at 4:00 and 4:30.
The Publish and Auto lock buttons are no changeable here, so just Save & Close.
This gives a view such as below. The tool Bar on this screen, which is not shown here, allows for pulishing and unpublishing.
|If one clicks on the Cronjob name it goes to the task page. The current status and when last run are shown together with the text of the log file produced by jDownloads. This is actually the html output generated by jDownloads that would have been shown if the scan had been monitored manually.|
Another alternative is to use a web based cron service. There are a whole host of services, many free. To find some try searching with a phrase like 'cron services'. They just need to know the url of the jDownloads scan software. The free options are obviously more limited. The one I used for testing allowed a maximum frequency of once every 10 mimutes. The biggest pain with the free ones is that you need to renew every month.
Colin Mercer April 2016