JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5.0] New task plugin for check in items #402

Closed joomlapl-bot closed 7 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/37842 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-08-26.sql b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-08-26.sql new file mode 100644 index 0000000000000..6126e568478e7 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-08-26.sql @@ -0,0 +1,3 @@ +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_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 5, 0); + diff --git a/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-08-26.sql b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-08-26.sql new file mode 100644 index 0000000000000..ce78be2301d1a --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-08-26.sql @@ -0,0 +1,3 @@ +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_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 5, 0); + diff --git a/administrator/language/en-GB/plg_task_globalcheckin.ini b/administrator/language/en-GB/plg_task_globalcheckin.ini new file mode 100644 index 0000000000000..d7463afd2bf63 --- /dev/null +++ b/administrator/language/en-GB/plg_task_globalcheckin.ini @@ -0,0 +1,10 @@ +; Joomla! Project +; (C) 2023 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_GLOBALCHECKIN="Task - Global Check-in" +PLG_TASK_GLOBALCHECKIN_DELAY_LABEL="Minimum Period Before Checkin (hours)" +PLG_TASK_GLOBALCHECKIN_DESC="Check in checked out items." +PLG_TASK_GLOBALCHECKIN_TITLE="Global Check-in" +PLG_TASK_GLOBALCHECKIN_XML_DESCRIPTION="Plugin to global check in checked out items." diff --git a/administrator/language/en-GB/plg_task_globalcheckin.sys.ini b/administrator/language/en-GB/plg_task_globalcheckin.sys.ini new file mode 100644 index 0000000000000..a4f0a5500e67a --- /dev/null +++ b/administrator/language/en-GB/plg_task_globalcheckin.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; (C) 2023 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_GLOBALCHECKIN="Task - Global Check-in" +PLG_TASK_GLOBALCHECKIN_XML_DESCRIPTION="Plugin to global check in checked out items." diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index 1988640faee51..00b7defeb6eba 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -366,6 +366,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_system_updatenotification', 'plugin', 'updatenotification', 'system', 0, 1, 1, 0, 1, '', '', '', 25, 0), (0, 'plg_system_webauthn', 'plugin', 'webauthn', 'system', 0, 1, 1, 0, 1, '', '{}', '', 26, 0), (0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 1, '', '{}', '', 1, 0), +(0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0), (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 3, 0), (0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), (0, 'plg_multifactorauth_totp', 'plugin', 'totp', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 1, 0), diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index 4aecba83b5f36..7186f3063b22e 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -372,6 +372,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_system_updatenotification', 'plugin', 'updatenotification', 'system', 0, 1, 1, 0, 1, '', '', '', 25, 0), (0, 'plg_system_webauthn', 'plugin', 'webauthn', 'system', 0, 1, 1, 0, 1, '', '{}', '', 26, 0), (0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 1, '', '{}', '', 1, 0), +(0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0), (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 3, 0), (0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), (0, 'plg_multifactorauth_totp', 'plugin', 'totp', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 1, 0), diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index 105c591d4ce1d..a48c06decb91f 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -320,6 +320,7 @@ class ExtensionHelper // Core plugin extensions - task scheduler ['plugin', 'checkfiles', 'task', 0], + ['plugin', 'globalcheckin', 'task', 0], ['plugin', 'requests', 'task', 0], ['plugin', 'sitestatus', 'task', 0], diff --git a/plugins/task/globalcheckin/forms/globalcheckin_params.xml b/plugins/task/globalcheckin/forms/globalcheckin_params.xml new file mode 100644 index 0000000000000..bb590d17e8dbb --- /dev/null +++ b/plugins/task/globalcheckin/forms/globalcheckin_params.xml @@ -0,0 +1,18 @@ + +
+ +
+ +
+
+
diff --git a/plugins/task/globalcheckin/globalcheckin.xml b/plugins/task/globalcheckin/globalcheckin.xml new file mode 100644 index 0000000000000..813a35010ec65 --- /dev/null +++ b/plugins/task/globalcheckin/globalcheckin.xml @@ -0,0 +1,21 @@ + + + plg_task_globalcheckin + Joomla! Project + 2023-06-22 + (C) 2023 Open Source Matters, Inc. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 5.0.0 + PLG_TASK_GLOBALCHECKIN_XML_DESCRIPTION + Joomla\Plugin\Task\Globalcheckin + + services + src + + + language/en-GB/plg_task_globalcheckin.ini + language/en-GB/plg_task_globalcheckin.sys.ini + + diff --git a/plugins/task/globalcheckin/services/provider.php b/plugins/task/globalcheckin/services/provider.php new file mode 100644 index 0000000000000..987565bc9dad4 --- /dev/null +++ b/plugins/task/globalcheckin/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\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 __DEPLOY_VERSION__ + */ + 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; + } + ); + } +}; diff --git a/plugins/task/globalcheckin/src/Extension/Globalcheckin.php b/plugins/task/globalcheckin/src/Extension/Globalcheckin.php new file mode 100644 index 0000000000000..72f8956469650 --- /dev/null +++ b/plugins/task/globalcheckin/src/Extension/Globalcheckin.php @@ -0,0 +1,125 @@ + + * @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 __DEPLOY_VERSION__ + */ +class Globalcheckin extends CMSPlugin implements SubscriberInterface +{ + use DatabaseAwareTrait; + use TaskPluginTrait; + + /** + * @var string[] + * @since __DEPLOY_VERSION__ + */ + protected const TASKS_MAP = [ + 'plg_task_globalcheckin_task_get' => [ + 'langConstPrefix' => 'PLG_TASK_GLOBALCHECKIN', + 'form' => 'globalcheckin_params', + 'method' => 'makeCheckin', + ], + ]; + + /** + * @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', + ]; + } + + /** + * Standard method for the checkin routine. + * + * @param ExecuteTaskEvent $event The onExecuteTask event + * + * @return integer The exit code + * + * @since __DEPLOY_VERSION__ + */ + 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; + } +} ```