diff --git a/administrator/components/com_content/Extension/ContentComponent.php b/administrator/components/com_content/Extension/ContentComponent.php index 7fcdace8f789b..aa4440d1a3a35 100644 --- a/administrator/components/com_content/Extension/ContentComponent.php +++ b/administrator/components/com_content/Extension/ContentComponent.php @@ -22,6 +22,8 @@ use Joomla\CMS\HTML\HTMLRegistryAwareTrait; use Joomla\CMS\MVC\Factory\MVCFactoryServiceTrait; use Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface; +use Joomla\CMS\Workflow\WorkflowServiceInterface; +use Joomla\Component\Content\Administrator\Helper\ContentHelper; use Joomla\Component\Content\Administrator\Service\HTML\AdministratorService; use Joomla\Component\Content\Administrator\Service\HTML\Icon; use Psr\Container\ContainerInterface; @@ -32,7 +34,7 @@ * @since __DEPLOY_VERSION__ */ class ContentComponent extends Component implements - BootableExtensionInterface, MVCFactoryServiceInterface, CategoriesServiceInterface, FieldsServiceInterface, AssociationServiceInterface + BootableExtensionInterface, MVCFactoryServiceInterface, CategoriesServiceInterface, FieldsServiceInterface, AssociationServiceInterface, WorkflowServiceInterface { use MVCFactoryServiceTrait; use CategoriesServiceTrait; @@ -130,4 +132,31 @@ protected function getTableNameForSection(string $section = null) { return '#__content'; } + + /** + * Method to filter transitions by given id of state. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function filterTransitions($transitions, $pk): array + { + return ContentHelper::filterTransitions($transitions, $pk); + } + + /** + * Method to change state of multiple ids + * + * @param array $pks Array of IDs + * @param int $condition Condition of the workflow state + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public static function updateContentState($pks, $condition): bool + { + return ContentHelper::updateContentState($pks, $condition); + } } diff --git a/administrator/components/com_content/Helper/ContentHelper.php b/administrator/components/com_content/Helper/ContentHelper.php index 2f0b0c2c81b5c..f6bc3c16d808d 100644 --- a/administrator/components/com_content/Helper/ContentHelper.php +++ b/administrator/components/com_content/Helper/ContentHelper.php @@ -337,7 +337,7 @@ public static function canDeleteState($stateID) * * @since __DEPLOY_VERSION__ */ - public static function filterTransitions($transitions, $pk) + public static function filterTransitions($transitions, $pk): array { return array_values( array_filter( @@ -353,14 +353,14 @@ function ($var) use ($pk) /** * Method to change state of multiple ids * - * @param int $pks Array of IDs - * @param int $condition Condition of the workflow state + * @param array $pks Array of IDs + * @param int $condition Condition of the workflow state * * @return boolean * * @since __DEPLOY_VERSION__ */ - public static function updateContentState($pks, $condition) + public static function updateContentState($pks, $condition): bool { if (empty($pks)) { diff --git a/libraries/src/Workflow/Workflow.php b/libraries/src/Workflow/Workflow.php index 2015b5548fe5a..128e9599ae672 100644 --- a/libraries/src/Workflow/Workflow.php +++ b/libraries/src/Workflow/Workflow.php @@ -118,19 +118,21 @@ public function executeTransition($pks, $transition_id) $select = $db->quoteName( [ - 'id', - 'to_state_id', - 'from_state_id' + 't.id', + 't.to_state_id', + 't.from_state_id', + 's.condition', ] ); $query ->select($select) - ->from($db->quoteName('#__workflow_transitions')) - ->where($db->quoteName('id') . ' = ' . (int) $transition_id); + ->from($db->quoteName('#__workflow_transitions', 't')) + ->leftJoin($db->quoteName('#__workflow_states', 's') . ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('t.to_state_id')) + ->where($db->quoteName('t.id') . ' = ' . (int) $transition_id); if (!empty($this->options['published'])) { - $query ->where($db->quoteName('published') . ' = 1'); + $query ->where($db->quoteName('t.published') . ' = 1'); } $transition = $db->setQuery($query)->loadObject(); @@ -150,14 +152,11 @@ public function executeTransition($pks, $transition_id) $component = reset($parts); - $eName = ucfirst(str_replace('com_', '', $component)); - $cName = $eName . 'Helper'; + $componentInterface = Factory::getApplication()->bootComponent($component); - $class = '\\Joomla\\Component\\' . $eName . '\\Administrator\\Helper\\' . $cName; - - if (class_exists($class) && is_callable([$class, 'executeTransition'])) + if ($componentInterface instanceof WorkflowServiceInterface) { - return call_user_func([$class, 'executeTransition']); + $componentInterface->updateContentState($pks, $transition->condition); } return $this->updateAssociations($pks, $transition->to_state_id); diff --git a/libraries/src/Workflow/WorkflowServiceInterface.php b/libraries/src/Workflow/WorkflowServiceInterface.php new file mode 100644 index 0000000000000..6d09800c78c62 --- /dev/null +++ b/libraries/src/Workflow/WorkflowServiceInterface.php @@ -0,0 +1,40 @@ +