Skip to content
Merged
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
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions administrator/components/com_content/Helper/ContentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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))
{
Expand Down
23 changes: 11 additions & 12 deletions libraries/src/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions libraries/src/Workflow/WorkflowServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Workflow;

defined('JPATH_PLATFORM') or die;

/**
* The workflow service.
*
* @since __DEPLOY_VERSION__
*/
interface WorkflowServiceInterface
{
/**
* Method to filter transitions by given id of state.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function filterTransitions($transitions, $pk): array;

/**
* 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;
}