开发者

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

开发者 https://www.devze.com 2023-03-20 21:50 出处:网络
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 ev

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开发者_StackOverflow中文版 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:password@www.mysite.com/joomla/administrator....) but it doesn't work. Is there anyway other way to send login credentials, or any other way to do this?


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.


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


Mostly corn urls works from front-end even if your component deals with administrator only in Joomla. So whatever your code in admin cron get it to front-end & so that your cronurl becomes like index.php?option=com_yourcomponent&task=cronjob. Use this url to set cron using cPanel.

However this solution doesn't need to see whether admin is logged or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号