Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run an admin task in joomla with a cron job?

Tags:

cron

joomla

I wrote a custom component in Joomla! that pulls in content from an XML feed and stores it in the Joomla database. I want the admin URL (/administrator/index?option=com_mycomp) to run via cron once every night to run the component. I can't figure out how to make this work, though, since the component is an administrator task and you have to be logged in to run it.

How do I get by this? I tried including my user/pw in the url (http:admin:[email protected]/joomla/administrator....) but it doesn't work. Is there anyway other way to send login credentials, or any other way to do this?

like image 491
ygetarts Avatar asked Jul 18 '11 15:07

ygetarts


2 Answers

I know this thread is very old, but here's how I handled a similar task.

The "trick" is to take the custom PHP code you have created, and embed it into an article within your Joomla website.

I did this by using the JUMI extension, that allows custom PHP code to be stored within the Joomla repository and embedded, as required, within an article.

Then, create a CRON task that will activate the appropriate URL for the page containing the code you want to run.

like image 52
JEfromCanada Avatar answered Sep 19 '22 13:09

JEfromCanada


Just put your script in the administrator directory of the component like

/administrator/components/com_yourcomponent/cron.yourcomponent.php

This is how FeedGator handles cron tasks [Sounds very similar to what you're trying to do.] ... you can also write a frontend controller in your component per one of the comments

========== [Update] ============

I created this ultra-simple installable component that could also be used for this purpose. It allows for a frontend menu item to be assigned to a php page (including the route as suggested). So you:

  1. install the component
  2. create new menu item, (may want to use a 'hidden' menu) select the 'show' view option and enter the script to run via cron in 'file to include' like path/yourcron.php
  3. call the 'page' in your cron or test using: yourjoomlasite.com/index.php?option=com_show or yourjoomlasite.com/your-menu-alias
like image 27
idea34 Avatar answered Sep 17 '22 13:09

idea34