From dd57bd3a1ef59471acadda36892e99d286c272f4 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 15:34:41 +0200 Subject: [PATCH 01/12] webcronstart --- .../task/webcronstart/services/provider.php | 48 +++++++++ .../src/extension/Webcronstart.php | 101 ++++++++++++++++++ .../src/extension/forms/start_parameters.xml | 25 +++++ plugins/task/webcronstart/webcronstart.xml | 21 ++++ 4 files changed, 195 insertions(+) create mode 100644 plugins/task/webcronstart/services/provider.php create mode 100644 plugins/task/webcronstart/src/extension/Webcronstart.php create mode 100644 plugins/task/webcronstart/src/extension/forms/start_parameters.xml create mode 100644 plugins/task/webcronstart/webcronstart.xml diff --git a/plugins/task/webcronstart/services/provider.php b/plugins/task/webcronstart/services/provider.php new file mode 100644 index 0000000000000..3f53868097795 --- /dev/null +++ b/plugins/task/webcronstart/services/provider.php @@ -0,0 +1,48 @@ + + * @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; + } + ); + } +}; \ No newline at end of file diff --git a/plugins/task/webcronstart/src/extension/Webcronstart.php b/plugins/task/webcronstart/src/extension/Webcronstart.php new file mode 100644 index 0000000000000..cb295f7f2ab40 --- /dev/null +++ b/plugins/task/webcronstart/src/extension/Webcronstart.php @@ -0,0 +1,101 @@ + + * @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 4.1.0 + */ + 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); + } + catch (\Exception $e) + { + return TaskStatus::KNOCKOUT; + } + + if ($response->code !== 200) + { + return TaskStatus::KNOCKOUT; + } + + return TaskStatus::OK; + } +} diff --git a/plugins/task/webcronstart/src/extension/forms/start_parameters.xml b/plugins/task/webcronstart/src/extension/forms/start_parameters.xml new file mode 100644 index 0000000000000..5e59ae09002f8 --- /dev/null +++ b/plugins/task/webcronstart/src/extension/forms/start_parameters.xml @@ -0,0 +1,25 @@ + +
+ +
+ + +
+
+
diff --git a/plugins/task/webcronstart/webcronstart.xml b/plugins/task/webcronstart/webcronstart.xml new file mode 100644 index 0000000000000..ca9876b808483 --- /dev/null +++ b/plugins/task/webcronstart/webcronstart.xml @@ -0,0 +1,21 @@ + + + plg_task_webcronstart + Joomla! Project + 2022-05 + (C) 2020 Open Source Matters, Inc. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 4.0.0 + PLG_TASK_WEBCRONSTART_XML_DESCRIPTION + Joomla\Plugin\Task\Webcronstart + + services + src + + + language/en-GB/plg_task_webcronstart.ini + language/en-GB/plg_task_webcronstart.sys.ini + + \ No newline at end of file From 3e016c239af3bafe132d2cc3410887cee1e4149b Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 15:37:18 +0200 Subject: [PATCH 02/12] languages --- .../language/en-GB/plg_task_webcronstart.ini | 11 +++++++++++ .../language/en-GB/plg_task_webcronstart.sys.ini | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 administrator/language/en-GB/plg_task_webcronstart.ini create mode 100644 administrator/language/en-GB/plg_task_webcronstart.sys.ini diff --git a/administrator/language/en-GB/plg_task_webcronstart.ini b/administrator/language/en-GB/plg_task_webcronstart.ini new file mode 100644 index 0000000000000..e258ccec9f982 --- /dev/null +++ b/administrator/language/en-GB/plg_task_webcronstart.ini @@ -0,0 +1,11 @@ +; Joomla! Project +; (C) 2022 Open Source Matters, Inc. +; 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." \ No newline at end of file diff --git a/administrator/language/en-GB/plg_task_webcronstart.sys.ini b/administrator/language/en-GB/plg_task_webcronstart.sys.ini new file mode 100644 index 0000000000000..47bcaffbb7997 --- /dev/null +++ b/administrator/language/en-GB/plg_task_webcronstart.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; (C) 2022 Open Source Matters, Inc. +; 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." \ No newline at end of file From 33e02acb3f60cf8dbbadee2fb6e7722e62dffb96 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 17:15:24 +0200 Subject: [PATCH 03/12] Update provider.php --- plugins/task/webcronstart/services/provider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task/webcronstart/services/provider.php b/plugins/task/webcronstart/services/provider.php index 3f53868097795..6d320c905cdf3 100644 --- a/plugins/task/webcronstart/services/provider.php +++ b/plugins/task/webcronstart/services/provider.php @@ -45,4 +45,4 @@ function (Container $container) } ); } -}; \ No newline at end of file +} From a9ad2db9adef6d39967abb4a97dac97236ca6f25 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 17:39:30 +0200 Subject: [PATCH 04/12] Update plugins/task/webcronstart/webcronstart.xml Co-authored-by: Konstantin Kolos --- plugins/task/webcronstart/webcronstart.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task/webcronstart/webcronstart.xml b/plugins/task/webcronstart/webcronstart.xml index ca9876b808483..3a5a82905b6ea 100644 --- a/plugins/task/webcronstart/webcronstart.xml +++ b/plugins/task/webcronstart/webcronstart.xml @@ -7,7 +7,7 @@ GNU General Public License version 2 or later; see LICENSE.txt admin@joomla.org www.joomla.org - 4.0.0 + 4.2.0 PLG_TASK_WEBCRONSTART_XML_DESCRIPTION Joomla\Plugin\Task\Webcronstart From 7346e9d52ed012aa57fab968182c266bcb15c24f Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 17:39:39 +0200 Subject: [PATCH 05/12] Update plugins/task/webcronstart/webcronstart.xml Co-authored-by: Konstantin Kolos --- plugins/task/webcronstart/webcronstart.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task/webcronstart/webcronstart.xml b/plugins/task/webcronstart/webcronstart.xml index 3a5a82905b6ea..0cfbea3c9db97 100644 --- a/plugins/task/webcronstart/webcronstart.xml +++ b/plugins/task/webcronstart/webcronstart.xml @@ -3,7 +3,7 @@ plg_task_webcronstart Joomla! Project 2022-05 - (C) 2020 Open Source Matters, Inc. + (C) 2022 Open Source Matters, Inc. GNU General Public License version 2 or later; see LICENSE.txt admin@joomla.org www.joomla.org From 30dc1434f173b79086b67e92ffabe352b561819b Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 18:42:40 +0200 Subject: [PATCH 06/12] cs --- plugins/task/webcronstart/src/extension/Webcronstart.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/task/webcronstart/src/extension/Webcronstart.php b/plugins/task/webcronstart/src/extension/Webcronstart.php index cb295f7f2ab40..36cff85acf1f3 100644 --- a/plugins/task/webcronstart/src/extension/Webcronstart.php +++ b/plugins/task/webcronstart/src/extension/Webcronstart.php @@ -75,7 +75,6 @@ public static function getSubscribedEvents(): array */ protected function webcronStart(ExecuteTaskEvent $event): int { - // $params = $event->getArgument('params'); $response = ''; $options = new Registry; @@ -85,7 +84,7 @@ protected function webcronStart(ExecuteTaskEvent $event): int try { $response = HttpFactory::getHttp($options)->get($params->url, [], 300); - } + } catch (\Exception $e) { return TaskStatus::KNOCKOUT; From 4a31502b9471f0ea386fdf40879dffaf79ba0197 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 20:49:10 +0200 Subject: [PATCH 07/12] sql --- .../components/com_admin/sql/updates/mysql/4.2.0-2022-05-24.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 administrator/components/com_admin/sql/updates/mysql/4.2.0-2022-05-24.sql diff --git a/administrator/components/com_admin/sql/updates/mysql/4.2.0-2022-05-24.sql b/administrator/components/com_admin/sql/updates/mysql/4.2.0-2022-05-24.sql new file mode 100644 index 0000000000000..10205ff6c3c7c --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/4.2.0-2022-05-24.sql @@ -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); From 31b11091c002387c89c329b0c7add08a51b7ba80 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 20:51:48 +0200 Subject: [PATCH 08/12] sql --- .../com_admin/sql/updates/postgresql/4.2.0-2022-05-24.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 administrator/components/com_admin/sql/updates/postgresql/4.2.0-2022-05-24.sql diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.2.0-2022-05-24.sql b/administrator/components/com_admin/sql/updates/postgresql/4.2.0-2022-05-24.sql new file mode 100644 index 0000000000000..d713764a2d2c3 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/4.2.0-2022-05-24.sql @@ -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); From 9fe3383de39741973ff05f9a698c29265f976fd6 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 20:53:33 +0200 Subject: [PATCH 09/12] sql --- installation/sql/mysql/base.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index 454d2898761c0..8a8cbb33284a2 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -350,6 +350,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_task_demotasks', 'plugin', 'demotasks', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0), (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 0, '', '{}', '', 3, 0), (0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 0, '', '{}', '', 4, 0), +(0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 5, 0), (0, 'plg_twofactorauth_totp', 'plugin', 'totp', 'twofactorauth', 0, 0, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_twofactorauth_yubikey', 'plugin', 'yubikey', 'twofactorauth', 0, 0, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_user_contactcreator', 'plugin', 'contactcreator', 'user', 0, 0, 1, 0, 1, '', '{"autowebpage":"","category":"4","autopublish":"0"}', '', 1, 0), From 2f286c3ef6a32a5b328edbe343ce5b9fb47bd1a0 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 24 May 2022 20:55:00 +0200 Subject: [PATCH 10/12] sql --- installation/sql/postgresql/base.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index 1078a8cf3aa79..148ce167ffc50 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -356,6 +356,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_task_demotasks', 'plugin', 'demotasks', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0), (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 0, '', '{}', '', 3, 0), (0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 0, '', '{}', '', 4, 0), +(0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 5, 0), (0, 'plg_twofactorauth_totp', 'plugin', 'totp', 'twofactorauth', 0, 0, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_twofactorauth_yubikey', 'plugin', 'yubikey', 'twofactorauth', 0, 0, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_user_contactcreator', 'plugin', 'contactcreator', 'user', 0, 0, 1, 0, 1, '', '{"autowebpage":"","category":"4","autopublish":"0"}', '', 1, 0), From f9a26af57e07af9b878a638a1fa351c27bec8263 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Wed, 25 May 2022 08:58:49 +0200 Subject: [PATCH 11/12] missed ; --- plugins/task/webcronstart/services/provider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task/webcronstart/services/provider.php b/plugins/task/webcronstart/services/provider.php index 6d320c905cdf3..b73bc11f2b4cd 100644 --- a/plugins/task/webcronstart/services/provider.php +++ b/plugins/task/webcronstart/services/provider.php @@ -45,4 +45,4 @@ function (Container $container) } ); } -} +}; From 86a58f93876ba425302015bccad80b18af1479e6 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Wed, 25 May 2022 11:37:51 +0200 Subject: [PATCH 12/12] Update plugins/task/webcronstart/src/extension/Webcronstart.php Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- plugins/task/webcronstart/src/extension/Webcronstart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task/webcronstart/src/extension/Webcronstart.php b/plugins/task/webcronstart/src/extension/Webcronstart.php index 36cff85acf1f3..2df72c02193c8 100644 --- a/plugins/task/webcronstart/src/extension/Webcronstart.php +++ b/plugins/task/webcronstart/src/extension/Webcronstart.php @@ -44,7 +44,7 @@ class Webcronstart extends CMSPlugin implements SubscriberInterface /** * @var boolean - * @since 4.1.0 + * @since __DEPLOY_VERSION__ */ protected $autoloadLanguage = true;