first commit
This commit is contained in:
18
plugins/task/globalcheckin/forms/globalcheckin_params.xml
Normal file
18
plugins/task/globalcheckin/forms/globalcheckin_params.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<form>
|
||||
<fields name="params">
|
||||
<fieldset name="task_params">
|
||||
<field
|
||||
name="delay"
|
||||
type="number"
|
||||
label="PLG_TASK_GLOBALCHECKIN_DELAY_LABEL"
|
||||
default="1"
|
||||
required="true"
|
||||
min="0"
|
||||
step="1"
|
||||
validate="number"
|
||||
filter="int"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
||||
21
plugins/task/globalcheckin/globalcheckin.xml
Normal file
21
plugins/task/globalcheckin/globalcheckin.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<extension type="plugin" group="task" method="upgrade">
|
||||
<name>plg_task_globalcheckin</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2023-06-22</creationDate>
|
||||
<copyright>(C) 2023 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>5.0.0</version>
|
||||
<description>PLG_TASK_GLOBALCHECKIN_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Task\Globalcheckin</namespace>
|
||||
<files>
|
||||
<folder plugin="globalcheckin">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_task_globalcheckin.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_task_globalcheckin.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
48
plugins/task/globalcheckin/services/provider.php
Normal file
48
plugins/task/globalcheckin/services/provider.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Task.Globalcheckin
|
||||
*
|
||||
* @copyright (C) 2023 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\Database\DatabaseInterface;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Task\Globalcheckin\Extension\Globalcheckin;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = PluginHelper::getPlugin('task', 'globalcheckin');
|
||||
$dispatcher = $container->get(DispatcherInterface::class);
|
||||
|
||||
$checkin = new Globalcheckin(
|
||||
$dispatcher,
|
||||
(array) $plugin
|
||||
);
|
||||
$checkin->setDatabase($container->get(DatabaseInterface::class));
|
||||
|
||||
return $checkin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
125
plugins/task/globalcheckin/src/Extension/Globalcheckin.php
Normal file
125
plugins/task/globalcheckin/src/Extension/Globalcheckin.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugins
|
||||
* @subpackage Task.Globalcheckin
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Task\Globalcheckin\Extension;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
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\Database\DatabaseAwareTrait;
|
||||
use Joomla\Database\Exception\ExecutionFailureException;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
|
||||
/**
|
||||
* Task plugin with routines to check in a checked out item.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
class Globalcheckin extends CMSPlugin implements SubscriberInterface
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
use TaskPluginTrait;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @since 5.0.0
|
||||
*/
|
||||
protected const TASKS_MAP = [
|
||||
'plg_task_globalcheckin_task_get' => [
|
||||
'langConstPrefix' => 'PLG_TASK_GLOBALCHECKIN',
|
||||
'form' => 'globalcheckin_params',
|
||||
'method' => 'makeCheckin',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @since 5.0.0
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'onTaskOptionsList' => 'advertiseRoutines',
|
||||
'onExecuteTask' => 'standardRoutineHandler',
|
||||
'onContentPrepareForm' => 'enhanceTaskItemForm',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard method for the checkin routine.
|
||||
*
|
||||
* @param ExecuteTaskEvent $event The onExecuteTask event
|
||||
*
|
||||
* @return integer The exit code
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
protected function makeCheckin(ExecuteTaskEvent $event): int
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$tables = $db->getTableList();
|
||||
$prefix = $db->getPrefix();
|
||||
$delay = (int) $event->getArgument('params')->delay ?? 1;
|
||||
$failed = false;
|
||||
|
||||
foreach ($tables as $tn) {
|
||||
// Make sure we get the right tables based on prefix.
|
||||
if (stripos($tn, $prefix) !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fields = $db->getTableColumns($tn, false);
|
||||
|
||||
if (!(isset($fields['checked_out']) && isset($fields['checked_out_time']))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName($tn))
|
||||
->set($db->quoteName('checked_out') . ' = NULL')
|
||||
->set($db->quoteName('checked_out_time') . ' = NULL');
|
||||
|
||||
if ($fields['checked_out']->Null === 'YES') {
|
||||
$query->where($db->quoteName('checked_out') . ' IS NOT NULL');
|
||||
} else {
|
||||
$query->where($db->quoteName('checked_out') . ' > 0');
|
||||
}
|
||||
|
||||
if ($delay > 0) {
|
||||
$delayTime = Factory::getDate('now', 'UTC')->sub(new \DateInterval('PT' . $delay . 'H'))->toSql();
|
||||
$query->where(
|
||||
$db->quoteName('checked_out_time') . ' < ' . $db->quote($delayTime)
|
||||
);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (ExecutionFailureException $e) {
|
||||
// This failure isn't critical, don't care too much
|
||||
$failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $failed ? TaskStatus::INVALID_EXIT : TaskStatus::OK;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user