-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.2] task start scheduler on friend site via webcron #37878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dd57bd3
3e016c2
33e02ac
a9ad2db
7346e9d
30dc143
97f91e8
4a31502
31b1109
9fe3383
2f286c3
f9a26af
86a58f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES | ||
| (0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 16, 0); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||
| INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES | ||||||
| (0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 16, 0); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ; Joomla! Project | ||
| ; (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| ; License GNU General Public License version 2 or later; see LICENSE.txt | ||
| ; Note : All ini files need to be saved as UTF-8 | ||
|
|
||
| PLG_TASK_WEBCRONSTART="Task - Start WebCron" | ||
| PLG_TASK_WEBCRONSTART_XML_DESCRIPTION="Start the webcron service for the friend site." | ||
| PLG_TASK_WEBCRONSTART_URL_LABEL="Site URL" | ||
| PLG_TASK_WEBCRONSTART_URL_DESC="The URL of the site to start the webcron service for." | ||
| PLG_TASK_WEBCRONSTART_TITLE="WebCron Starter" | ||
| PLG_TASK_WEBCRONSTART_DESC="Starts the WebCron service for the friend site." | ||
|
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please alphasort and add EOF |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ; Joomla! Project | ||
| ; (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| ; License GNU General Public License version 2 or later; see LICENSE.txt | ||
| ; Note : All ini files need to be saved as UTF-8 | ||
|
|
||
| PLG_TASK_WEBCRONSTART="Task - Start WebCron" | ||
| PLG_TASK_WEBCRONSTART_XML_DESCRIPTION="Start the webcron service for the friend site." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add EOF |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage Task.webcronstart | ||
| * | ||
| * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Extension\PluginInterface; | ||
| use Joomla\CMS\Plugin\PluginHelper; | ||
| use Joomla\DI\Container; | ||
| use Joomla\DI\ServiceProviderInterface; | ||
| use Joomla\Event\DispatcherInterface; | ||
| use Joomla\Plugin\Task\Webcronstart\Extension\Webcronstart; | ||
|
|
||
| return new class implements ServiceProviderInterface | ||
| { | ||
| /** | ||
| * Registers the service provider with a DI container. | ||
| * | ||
| * @param Container $container The DI container. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function register(Container $container) | ||
| { | ||
| $container->set( | ||
| PluginInterface::class, | ||
| function (Container $container) | ||
| { | ||
| $plugin = PluginHelper::getPlugin('task', 'webcronstart'); | ||
| $dispatcher = $container->get(DispatcherInterface::class); | ||
|
|
||
| $webcron = new Webcronstart( | ||
| $dispatcher, | ||
| (array) $plugin, | ||
| ); | ||
|
|
||
| return $webcron; | ||
| } | ||
| ); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Plugins | ||
| * @subpackage Task.Webcronstart | ||
| * | ||
| * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Plugin\Task\Webcronstart\Extension; | ||
|
|
||
| // Restrict direct access | ||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Plugin\CMSPlugin; | ||
| use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent; | ||
| use Joomla\Component\Scheduler\Administrator\Task\Status as TaskStatus; | ||
| use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait; | ||
| use Joomla\Event\SubscriberInterface; | ||
| use Joomla\CMS\Http\HttpFactory; | ||
| use Joomla\Registry\Registry; | ||
|
|
||
| /** | ||
| * Task plugin with routines that offer to start the scheduler via webcron on a friend site. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class Webcronstart extends CMSPlugin implements SubscriberInterface | ||
| { | ||
| use TaskPluginTrait; | ||
|
|
||
| /** | ||
| * @var string[] | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected const TASKS_MAP = [ | ||
| 'start' => [ | ||
| 'langConstPrefix' => 'PLG_TASK_WEBCRONSTART', | ||
| 'form' => 'start_parameters', | ||
| 'method' => 'webcronStart', | ||
| ], | ||
| ]; | ||
|
|
||
| /** | ||
| * @var boolean | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected $autoloadLanguage = true; | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| * | ||
| * @return string[] | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public static function getSubscribedEvents(): array | ||
| { | ||
| return [ | ||
| 'onTaskOptionsList' => 'advertiseRoutines', | ||
| 'onExecuteTask' => 'standardRoutineHandler', | ||
| 'onContentPrepareForm' => 'enhanceTaskItemForm', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @param ExecuteTaskEvent $event The onExecuteTask event | ||
| * | ||
| * @return integer The exit code | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| * @throws RuntimeException | ||
| * @throws LogicException | ||
| */ | ||
| protected function webcronStart(ExecuteTaskEvent $event): int | ||
| { | ||
| $params = $event->getArgument('params'); | ||
| $response = ''; | ||
| $options = new Registry; | ||
| $options->set('Content-Type', 'application/json'); | ||
|
|
||
| // Let the request take longer than 300 seconds to avoid timeout issues | ||
| try | ||
| { | ||
| $response = HttpFactory::getHttp($options)->get($params->url, [], 300); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. timeout parameter is not used here |
||
| } | ||
| catch (\Exception $e) | ||
| { | ||
| return TaskStatus::KNOCKOUT; | ||
| } | ||
|
|
||
| if ($response->code !== 200) | ||
| { | ||
| return TaskStatus::KNOCKOUT; | ||
| } | ||
|
|
||
| return TaskStatus::OK; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||
| <?xml version="1.0" encoding="utf-8" ?> | ||||||||||||||||||||||
| <form> | ||||||||||||||||||||||
| <fields name="params"> | ||||||||||||||||||||||
| <fieldset name="task_params"> | ||||||||||||||||||||||
| <field | ||||||||||||||||||||||
| name="url" | ||||||||||||||||||||||
| type="text" | ||||||||||||||||||||||
| label="PLG_TASK_WEBCRONSTART_URL_LABEL" | ||||||||||||||||||||||
| description="PLG_TASK_WEBCRONSTART_URL_DESC" | ||||||||||||||||||||||
| required="true" | ||||||||||||||||||||||
|
Comment on lines
+6
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| /> | ||||||||||||||||||||||
| <field | ||||||||||||||||||||||
| name="timeout" | ||||||||||||||||||||||
| type="number" | ||||||||||||||||||||||
| label="COM_SCHEDULER_CONFIG_TASK_TIMEOUT_LABEL" | ||||||||||||||||||||||
| default="300" | ||||||||||||||||||||||
| required="true" | ||||||||||||||||||||||
| min="10" | ||||||||||||||||||||||
| step="1" | ||||||||||||||||||||||
| validate="number" | ||||||||||||||||||||||
| filter="int" | ||||||||||||||||||||||
| /> | ||||||||||||||||||||||
| </fieldset> | ||||||||||||||||||||||
| </fields> | ||||||||||||||||||||||
| </form> | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <extension type="plugin" group="task" method="upgrade"> | ||
| <name>plg_task_webcronstart</name> | ||
| <author>Joomla! Project</author> | ||
| <creationDate>2022-05</creationDate> | ||
| <copyright>(C) 2022 Open Source Matters, Inc.</copyright> | ||
| <license>GNU General Public License version 2 or later; see LICENSE.txt</license> | ||
| <authorEmail>[email protected]</authorEmail> | ||
| <authorUrl>www.joomla.org</authorUrl> | ||
| <version>4.2.0</version> | ||
| <description>PLG_TASK_WEBCRONSTART_XML_DESCRIPTION</description> | ||
| <namespace path="src">Joomla\Plugin\Task\Webcronstart</namespace> | ||
| <files> | ||
| <folder plugin="webcronstart">services</folder> | ||
| <folder>src</folder> | ||
| </files> | ||
| <languages> | ||
| <language tag="en-GB">language/en-GB/plg_task_webcronstart.ini</language> | ||
| <language tag="en-GB">language/en-GB/plg_task_webcronstart.sys.ini</language> | ||
| </languages> | ||
| </extension> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add EOF |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 5 ??
https://github.com/joomla/joomla-cms/blob/4.2-dev/administrator/components/com_admin/sql/updates/postgresql/4.1.0-2021-11-20.sql#L47-L53
i've choosed 16 cause is bigger than 15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm ... in base.sql all task scheduler plugins seem to have values 0 to 5. No idea why it was done differently in that update SQL script. Maybe someone else has an idea.