diff --git a/libraries/src/Button/TransitionButton.php b/libraries/src/Button/TransitionButton.php index 719b519373243..b8279c0d3d45f 100644 --- a/libraries/src/Button/TransitionButton.php +++ b/libraries/src/Button/TransitionButton.php @@ -51,8 +51,6 @@ public function __construct(array $options = []) * @param integer|null $value Current value of this item. * @param integer|null $row The row number of this item. * @param array $options The options to override group options. - * @param string|Date $publishUp The date which item publish up. - * @param string|Date $publishDown The date which item publish down. * * @return string Rendered HTML. * diff --git a/libraries/src/Event/View/DisplayEvent.php b/libraries/src/Event/View/DisplayEvent.php index 46a6f2c3e4e5f..325db2938d924 100644 --- a/libraries/src/Event/View/DisplayEvent.php +++ b/libraries/src/Event/View/DisplayEvent.php @@ -33,14 +33,24 @@ class DisplayEvent extends AbstractImmutableEvent */ public function __construct($name, array $arguments = array()) { - if (!isset($arguments['subject']) || !($arguments['subject'] instanceof ViewInterface)) + if (!isset($arguments['subject'])) { - throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided or is not of type 'ViewInterface'"); + throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided"); + } + + if (!($arguments['subject'] instanceof ViewInterface)) + { + throw new BadMethodCallException("Argument 'subject' of event {$this->name} is not of type 'ViewInterface'"); + } + + if (!isset($arguments['extension'])) + { + throw new BadMethodCallException("Argument 'extension' of event {$this->name} is required but has not been provided"); } if (!isset($arguments['extension']) || !is_string($arguments['extension'])) { - throw new BadMethodCallException("Argument 'extension' of event {$this->name} is required but has not been provided or is not of type 'string'"); + throw new BadMethodCallException("Argument 'extension' of event {$this->name} is not of type 'string'"); } if (strpos($arguments['extension'], '.') === false) diff --git a/libraries/src/Event/Workflow/WorkflowFunctionalityUsedEvent.php b/libraries/src/Event/Workflow/WorkflowFunctionalityUsedEvent.php index fb0b10af1e4a3..afb5938681b09 100644 --- a/libraries/src/Event/Workflow/WorkflowFunctionalityUsedEvent.php +++ b/libraries/src/Event/Workflow/WorkflowFunctionalityUsedEvent.php @@ -41,7 +41,11 @@ public function __construct($name, array $arguments = array()) /** * Set used parameter to true * - * @since 1.0 + * @param bool $value The value to set + * + * @return void + * + * @since 4.0.0 */ public function setUsed($value = true) { diff --git a/libraries/src/Event/Workflow/WorkflowTransitionEvent.php b/libraries/src/Event/Workflow/WorkflowTransitionEvent.php index 0b64831b916b9..58c68150abd4f 100644 --- a/libraries/src/Event/Workflow/WorkflowTransitionEvent.php +++ b/libraries/src/Event/Workflow/WorkflowTransitionEvent.php @@ -41,7 +41,11 @@ public function __construct($name, array $arguments = array()) /** * Set used parameter to true * - * @since 1.0 + * @param bool $value The value to set + * + * @return void + * + * @since 4.0.0 */ public function setStopTransition($value = true) { diff --git a/libraries/src/Workflow/Workflow.php b/libraries/src/Workflow/Workflow.php index 4aee23adbf582..5516c6d8d8ad2 100644 --- a/libraries/src/Workflow/Workflow.php +++ b/libraries/src/Workflow/Workflow.php @@ -178,11 +178,11 @@ public function executeTransition(array $pks, int $transition_id): bool $db->quoteName('t.workflow_id'), ] ) - ->from($db->quoteName('#__workflow_transitions', 't')) - ->join('LEFT', $db->quoteName('#__workflow_stages', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('t.to_stage_id')) - ->where($db->quoteName('t.id') . ' = :id') - ->where($db->quoteName('t.published') . ' = 1') - ->bind(':id', $transition_id, ParameterType::INTEGER); + ->from($db->quoteName('#__workflow_transitions', 't')) + ->join('LEFT', $db->quoteName('#__workflow_stages', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('t.to_stage_id')) + ->where($db->quoteName('t.id') . ' = :id') + ->where($db->quoteName('t.published') . ' = 1') + ->bind(':id', $transition_id, ParameterType::INTEGER); $transition = $db->setQuery($query)->loadObject(); @@ -202,7 +202,8 @@ public function executeTransition(array $pks, int $transition_id): bool if (!\in_array($transition->from_stage_id, [ $assoc->stage_id, -1 - ]) || $transition->workflow_id !== $assoc->workflow_id) + ] + ) || $transition->workflow_id !== $assoc->workflow_id) { return false; } @@ -272,17 +273,17 @@ public function createAssociation(int $pk, int $state): bool $query = $db->getQuery(true); $query->insert($db->quoteName('#__workflow_associations')) - ->columns( - [ - $db->quoteName('item_id'), - $db->quoteName('stage_id'), - $db->quoteName('extension'), - ] - ) - ->values(':pk, :state, :extension') - ->bind(':pk', $pk, ParameterType::INTEGER) - ->bind(':state', $state, ParameterType::INTEGER) - ->bind(':extension', $this->extension); + ->columns( + [ + $db->quoteName('item_id'), + $db->quoteName('stage_id'), + $db->quoteName('extension'), + ] + ) + ->values(':pk, :state, :extension') + ->bind(':pk', $pk, ParameterType::INTEGER) + ->bind(':state', $state, ParameterType::INTEGER) + ->bind(':extension', $this->extension); $db->setQuery($query)->execute(); } @@ -314,11 +315,11 @@ public function updateAssociations(array $pks, int $state): bool $query = $db->getQuery(true); $query->update($db->quoteName('#__workflow_associations')) - ->set($db->quoteName('stage_id') . ' = :state') - ->whereIn($db->quoteName('item_id'), $pks) - ->where($db->quoteName('extension') . ' = :extension') - ->bind(':state', $state, ParameterType::INTEGER) - ->bind(':extension', $this->extension); + ->set($db->quoteName('stage_id') . ' = :state') + ->whereIn($db->quoteName('item_id'), $pks) + ->where($db->quoteName('extension') . ' = :extension') + ->bind(':state', $state, ParameterType::INTEGER) + ->bind(':extension', $this->extension); $db->setQuery($query)->execute(); } @@ -385,19 +386,19 @@ public function getAssociation(int $item_id): ?\stdClass $db->quoteName('s.workflow_id'), ] ) - ->from($db->quoteName('#__workflow_associations', 'a')) - ->innerJoin( - $db->quoteName('#__workflow_stages', 's'), - $db->quoteName('a.stage_id') . ' = ' . $db->quoteName('s.id') - ) - ->where( - [ - $db->quoteName('item_id') . ' = :id', - $db->quoteName('extension') . ' = :extension', - ] - ) - ->bind(':id', $item_id, ParameterType::INTEGER) - ->bind(':extension', $this->extension); + ->from($db->quoteName('#__workflow_associations', 'a')) + ->innerJoin( + $db->quoteName('#__workflow_stages', 's'), + $db->quoteName('a.stage_id') . ' = ' . $db->quoteName('s.id') + ) + ->where( + [ + $db->quoteName('item_id') . ' = :id', + $db->quoteName('extension') . ' = :extension', + ] + ) + ->bind(':id', $item_id, ParameterType::INTEGER) + ->bind(':extension', $this->extension); return $db->setQuery($query)->loadObject(); } diff --git a/libraries/src/Workflow/WorkflowPluginTrait.php b/libraries/src/Workflow/WorkflowPluginTrait.php index c9efe14a80d0f..ec676df7b9333 100644 --- a/libraries/src/Workflow/WorkflowPluginTrait.php +++ b/libraries/src/Workflow/WorkflowPluginTrait.php @@ -24,8 +24,8 @@ trait WorkflowPluginTrait /** * Add different parameter options to the transition view, we need when executing the transition * - * @param Form $form The form - * @param \stdClass $data The data + * @param Form $form The form + * @param \stdClass $data The data * * @return boolean * @@ -56,7 +56,7 @@ protected function enhanceWorkflowTransitionForm(Form $form, $data) /** * Get the workflow for a given ID * - * @param int|null $workflow_id ID of the workflow + * @param int|null $workflow_id ID of the workflow * * @return CMSObject|boolean Object on success, false on failure. * @@ -72,15 +72,15 @@ protected function getWorkflow(int $workflow_id = null) } return $this->app->bootComponent('com_workflow') - ->getMVCFactory() - ->createModel('Workflow', 'Administrator', ['ignore_request' => true]) - ->getItem($workflow_id); + ->getMVCFactory() + ->createModel('Workflow', 'Administrator', ['ignore_request' => true]) + ->getItem($workflow_id); } /** * Check if the current plugin should execute workflow related activities * - * @param string $context Context to check + * @param string $context Context to check * * @return boolean * @@ -94,9 +94,9 @@ protected function isSupported($context) /** * Check if the context is listed in the whitelist or in the blacklist and return the result * - * @param string $context Context to check + * @param string $context Context to check * - * @return bool + * @return boolean */ protected function checkWhiteAndBlacklist($context) { @@ -133,15 +133,17 @@ protected function checkWhiteAndBlacklist($context) /** * Check if the context is listed in the whitelist or in the blacklist and return the result * - * @param string $context Context to check + * @param string $context Context to check + * @param string $functionality The funcationality * - * @return bool + * @return boolean */ protected function checkExtensionSupport($context, $functionality) { $parts = explode('.', $context); $component = $this->app->bootComponent($parts[0]); + if (!$component instanceof WorkflowServiceInterface || !$component->isWorkflowActive($context) || !$component->isFunctionalityActive($functionality, $context)) diff --git a/libraries/src/Workflow/WorkflowServiceTrait.php b/libraries/src/Workflow/WorkflowServiceTrait.php index dae9cb5cce884..6e8760c20faa0 100644 --- a/libraries/src/Workflow/WorkflowServiceTrait.php +++ b/libraries/src/Workflow/WorkflowServiceTrait.php @@ -69,22 +69,22 @@ public function supportFunctionality($functionality, $context): bool /** * Check if the functionality is activated in the component configuration * - * @param string $functionality - * @param string $extension + * @param string $functionality The functionality + * @param string $extension The extension * - * @return bool + * @return boolean * @throws \Exception * * @since 4.0.0 */ - public function isFunctionalityActive($functionality, $context): bool + public function isFunctionalityActive($functionality, $extension): bool { - if (!$this->isWorkflowActive($context)) + if (!$this->isWorkflowActive($extension)) { return false; } - $parts = explode('.', $context); + $parts = explode('.', $extension); $config = ComponentHelper::getParams($parts[0]); $option = 'workflow_functionality_' . str_replace('.', '_', $functionality); @@ -99,10 +99,10 @@ public function isFunctionalityActive($functionality, $context): bool /** * Check if the functionality is used by a plugin * - * @param string $functionality - * @param string $extension + * @param string $functionality The functionality + * @param string $extension The extension * - * @return bool + * @return boolean * @throws \Exception * * @since 4.0.0 diff --git a/plugins/workflow/featuring/featuring.php b/plugins/workflow/featuring/featuring.php index faf8a4be436f5..88c9fd675b2ba 100644 --- a/plugins/workflow/featuring/featuring.php +++ b/plugins/workflow/featuring/featuring.php @@ -132,7 +132,7 @@ protected function enhanceItemForm(Form $form, $data) $modelName = $component->getModelName($context); $table = $component->getMVCFactory()->createModel($modelName, $this->app->getName(), ['ignore_request' => true]) - ->getTable(); + ->getTable(); $fieldname = $table->getColumnAlias('featured'); @@ -278,7 +278,8 @@ public function onWorkflowBeforeTransition(WorkflowTransitionEvent $event) $context, $pks, $value - ]); + ] + ); // Release whitelist, the job is done $this->app->set('plgWorkflowFeaturing.' . $context, []); @@ -376,7 +377,9 @@ public function onContentBeforeChangeFeatured(EventInterface $event) public function onContentBeforeSave(EventInterface $event) { $context = $event->getArgument('0'); - /* @var TableInterface */ + + // @var TableInterface + $table = $event->getArgument('1'); $isNew = $event->getArgument('2'); $data = $event->getArgument('3'); diff --git a/plugins/workflow/notification/notification.php b/plugins/workflow/notification/notification.php index 81b3f4aee8d36..8a92c65ea292e 100644 --- a/plugins/workflow/notification/notification.php +++ b/plugins/workflow/notification/notification.php @@ -144,7 +144,7 @@ public function onWorkflowAfterTransition(WorkflowTransitionEvent $event) $user = $this->app->getIdentity(); // Prepare Language for messages - $default_language = ComponentHelper::getParams('com_languages')->get('administrator'); + $defaultLanguage = ComponentHelper::getParams('com_languages')->get('administrator'); $debug = $this->app->get('debug_lang'); $modelName = $component->getModelName($context); @@ -172,20 +172,21 @@ public function onWorkflowAfterTransition(WorkflowTransitionEvent $event) // Get the model for private messages $model_message = $this->app->bootComponent('com_messages') - ->getMVCFactory()->createModel('Message', 'Administrator'); + ->getMVCFactory()->createModel('Message', 'Administrator'); // Get the title of the stage $model_stage = $this->app->bootComponent('com_workflow') - ->getMVCFactory()->createModel('Stage', 'Administrator'); + ->getMVCFactory()->createModel('Stage', 'Administrator'); $toStage = $model_stage->getItem($transition->to_stage_id)->title; $hasGetItem = method_exists($model, 'getItem'); + $container = Factory::getContainer(); foreach ($pks as $pk) { // Get the title of the item which has changed - $title =''; + $title = ''; if ($hasGetItem) { @@ -195,10 +196,10 @@ public function onWorkflowAfterTransition(WorkflowTransitionEvent $event) // Send Email to receivers foreach ($userIds as $user_id) { - $receiver = Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById($user_id); + $receiver = $container->get(UserFactoryInterface::class)->loadUserById($user_id); // Load language for messaging - $lang = Factory::getContainer()->get(LanguageFactoryInterface::class)->createLanguage($user->getParam('admin_language', $default_language), $debug); + $lang = $container->get(LanguageFactoryInterface::class)->createLanguage($user->getParam('admin_language', $defaultLanguage), $debug); $lang->load('plg_workflow_notification'); $messageText = sprintf($lang->_('PLG_WORKFLOW_NOTIFICATION_ON_TRANSITION_MSG'), $title, $user->name, $lang->_($toStage)); @@ -254,7 +255,7 @@ private function getUsersFromGroup($data): Array if (!empty($groups)) { // UserIds from usergroups - $model = Factory::getApplication()->bootComponent('com_users') + $model = Factory::getApplication()->bootComponent('com_users') ->getMVCFactory()->createModel('Users', 'Administrator', ['ignore_request' => true]); $model->setState('list.select', 'id'); @@ -329,10 +330,10 @@ private function removeLocked(array $userIds): Array $query = $this->db->getQuery(true); $query->select($this->db->quoteName('user_id')) - ->from($this->db->quoteName('#__messages_cfg')) - ->whereIn($this->db->quoteName('user_id'), $userIds) - ->where($this->db->quoteName('cfg_name') . ' = ' . $this->db->quote('locked')) - ->where($this->db->quoteName('cfg_value') . ' = 1'); + ->from($this->db->quoteName('#__messages_cfg')) + ->whereIn($this->db->quoteName('user_id'), $userIds) + ->where($this->db->quoteName('cfg_name') . ' = ' . $this->db->quote('locked')) + ->where($this->db->quoteName('cfg_value') . ' = 1'); $locked = $this->db->setQuery($query)->loadColumn(); diff --git a/plugins/workflow/publishing/publishing.php b/plugins/workflow/publishing/publishing.php index 26310a2b38b14..6576eea577afe 100644 --- a/plugins/workflow/publishing/publishing.php +++ b/plugins/workflow/publishing/publishing.php @@ -156,7 +156,7 @@ protected function enhanceItemForm(Form $form, $data) $modelName = $component->getModelName($context); $table = $component->getMVCFactory()->createModel($modelName, $this->app->getName(), ['ignore_request' => true]) - ->getTable(); + ->getTable(); $fieldname = $table->getColumnAlias('published'); @@ -301,7 +301,8 @@ public function onWorkflowBeforeTransition(WorkflowTransitionEvent $event) $context, $pks, $value - ]); + ] + ); // Release whitelist, the job is done $this->app->set('plgWorkflowPublishing.' . $context, []); @@ -399,7 +400,9 @@ public function onContentBeforeChangeState(EventInterface $event) public function onContentBeforeSave(EventInterface $event) { $context = $event->getArgument('0'); - /* @var TableInterface */ + + // @var TableInterface + $table = $event->getArgument('1'); $isNew = $event->getArgument('2'); $data = $event->getArgument('3');