Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 16, 0);
(0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 5, 0);

Copy link
Contributor Author

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

-- Add plugins to "#__extensions"
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_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 0, '', '{}', '', 15, 0),
(0, 'plg_system_tasknotification', 'plugin', 'tasknotification', 'system', 0, 1, 1, 0, 1, '', '', '', 22, 0),
(0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 0, '', '{}', '', 15, 0),
(0, 'plg_task_demotasks', 'plugin', 'demotasks', 'task', 0, 1, 1, 0, 0, '', '{}', '', 15, 0),
(0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 0, '', '{}', '', 15, 0),
(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 0, '', '{}', '', 15, 0);

i've choosed 16 cause is bigger than 15

Copy link
Member

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.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 16, 0);
(0, 'plg_task_webcronstart', 'plugin', 'webcronstart', 'task', 0, 1, 1, 0, 0, '', '{}', '', 5, 0);

11 changes: 11 additions & 0 deletions administrator/language/en-GB/plg_task_webcronstart.ini
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please alphasort and add EOF

7 changes: 7 additions & 0 deletions administrator/language/en-GB/plg_task_webcronstart.sys.ini
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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add EOF

1 change: 1 addition & 0 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
48 changes: 48 additions & 0 deletions plugins/task/webcronstart/services/provider.php
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;
}
);
}
};
100 changes: 100 additions & 0 deletions plugins/task/webcronstart/src/extension/Webcronstart.php
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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
}
25 changes: 25 additions & 0 deletions plugins/task/webcronstart/src/extension/forms/start_parameters.xml
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name="url"
type="text"
label="PLG_TASK_WEBCRONSTART_URL_LABEL"
description="PLG_TASK_WEBCRONSTART_URL_DESC"
required="true"
name="url"
type="text"
label="PLG_TASK_WEBCRONSTART_URL_LABEL"
description="PLG_TASK_WEBCRONSTART_URL_DESC"
required="true"

/>
<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>
21 changes: 21 additions & 0 deletions plugins/task/webcronstart/webcronstart.xml
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add EOF