Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f64c9ca
Prevent trashing of active items
bembelimen Aug 13, 2018
61d9c0b
Fix wrong method name
bembelimen Aug 13, 2018
6be26a1
Improve translation
bembelimen Aug 13, 2018
b25c0b3
Improve translation
bembelimen Aug 13, 2018
647092d
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Aug 13, 2018
b1eebd6
Reorder xml structure
bembelimen Aug 13, 2018
ab6369e
Remove blank line
bembelimen Aug 13, 2018
0a2cb77
Order use statements
bembelimen Aug 13, 2018
f21b84b
Add point
bembelimen Aug 13, 2018
d4428d7
Merge branch '4.0-dev' into workflow-prevent-trashing
wilsonge Aug 13, 2018
974c564
Merge branch '4.0-dev' into workflow-prevent-trashing
wilsonge Aug 14, 2018
272fcf8
Sniffer satisfaction
bembelimen Aug 14, 2018
fac863e
Sniffer satisfaction
bembelimen Aug 14, 2018
102d260
Merge branch '4.0-dev' into workflow-prevent-trashing
wilsonge Aug 14, 2018
85b4ff1
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Aug 18, 2018
069fc8b
Remove parameter check
bembelimen Aug 18, 2018
899805c
Fix comment
bembelimen Aug 18, 2018
85223e5
Code sniffer
bembelimen Aug 19, 2018
07b7a44
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Aug 20, 2018
9305a49
Merge branch '4.0-dev' into workflow-prevent-trashing
bembelimen Aug 23, 2018
ff70dc6
Merge branch '4.0-dev' into workflow-prevent-trashing
bembelimen Aug 24, 2018
e93e017
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Sep 8, 2018
e762553
Merge branch '4.0-dev' into workflow-prevent-trashing
wilsonge Sep 8, 2018
d9b2b2d
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Sep 9, 2018
e204edf
Merge branch 'workflow-prevent-trashing' of github.com:bembelimen/joo…
bembelimen Sep 9, 2018
22b2446
Fix trashing over edit view
bembelimen Sep 9, 2018
9c066cc
Remove unused string
bembelimen Sep 9, 2018
10d8bc0
Merge branch '4.0-dev' into workflow-prevent-trashing
bembelimen Sep 9, 2018
14fcc14
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Sep 10, 2018
0843fbc
Remove unused "use statement"
bembelimen Sep 10, 2018
4e68625
Merge branch '4.0-dev' into workflow-prevent-trashing
bembelimen Sep 22, 2018
5f31e9f
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into workflow-…
bembelimen Nov 19, 2018
a9b60ff
Merge branch '4.0-dev' into workflow-prevent-trashing
wilsonge Dec 10, 2018
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 @@ -177,6 +177,20 @@ protected function getTableNameForSection(string $section = null)
return '#__content';
}

/**
* Returns a table name for the state association
*
* @param string $section An optional section to differ different areas in the component
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

differ different

typo?

*
* @return string
*
* @since __DEPLOY_VERSION__
*/
protected function getWorkflowTableBySection(string $section = null)
{
return '#__content';
}

/**
* Method to filter transitions by given id of state.
*
Expand Down
4 changes: 3 additions & 1 deletion administrator/language/en-GB/en-GB.com_workflow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ COM_WORKFLOW_MODIFIED_AT_DESC="Date Modified descending"
COM_WORKFLOW_MODIFIED_DESC="Date Modified"
COM_WORKFLOW_MODIFIED_LABEL="Date Modified"
COM_WORKFLOW_MSG_DELETE_DEFAULT="You are trying to delete the default item."
COM_WORKFLOW_MSG_FROM_TO_STAGE="From Stage and To Stage must have different names."
COM_WORKFLOW_MSG_DELETE_IS_ASSIGNED="This item is in use by the component."
COM_WORKFLOW_MSG_DELETE_IS_DEFAULT="You can't delete the default item."
COM_WORKFLOW_MSG_FROM_TO_STAGE="From Stage and To Stage must have different names."
COM_WORKFLOW_MSG_WORKFLOWS_DELETE_ERROR="There was a problem while deleting the item: "
COM_WORKFLOW_MSG_WORKFLOW_IS_NOT_SUPPORTED="This item is in use by the component."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?
The constant doesn't seem to match the meaning in the value but i cant see it being used to advise

COM_WORKFLOW_NA="N/A"
COM_WORKFLOW_NAME="Name"
COM_WORKFLOW_NEW="New"
Expand Down
2 changes: 0 additions & 2 deletions administrator/language/en-GB/en-GB.plg_content_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
PLG_CONTENT_JOOMLA="Content - Joomla"
PLG_CONTENT_JOOMLA_FIELD_CHECK_CATEGORIES_DESC="Check that categories are fully empty before they are deleted."
PLG_CONTENT_JOOMLA_FIELD_CHECK_CATEGORIES_LABEL="Check Category Deletion"
PLG_CONTENT_JOOMLA_FIELD_CHECK_STAGES_DESC="Check that stages are not assigned to an item before they are deleted."
PLG_CONTENT_JOOMLA_FIELD_CHECK_STAGES_LABEL="Check Stages Deletion"
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_FE_DESC="Email users if 'Send email' is on when there is a new article submitted via the Frontend."
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_FE_LABEL="Email on New Site Article"
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_STAGE_DESC="Email users if 'Send email' is on when there is a status change of an article."
Expand Down
31 changes: 29 additions & 2 deletions libraries/src/MVC/Model/AdminModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ abstract class AdminModel extends FormModel
*/
protected $event_before_save = null;

/**
* The event to trigger before changing the published state of the data.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $event_before_change_state = null;

/**
* The event to trigger after changing the published state of the data.
*
Expand Down Expand Up @@ -214,6 +222,15 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
$this->event_before_save = 'onContentBeforeSave';
}

if (isset($config['event_before_change_state']))
{
$this->event_before_change_state = $config['event_before_change_state'];
}
elseif (empty($this->event_before_change_state))
{
$this->event_before_change_state = 'onContentBeforeChangeState';
}

if (isset($config['event_change_state']))
{
$this->event_change_state = $config['event_change_state'];
Expand Down Expand Up @@ -1004,6 +1021,8 @@ public function publish(&$pks, $value = 1)
$table = $this->getTable();
$pks = (array) $pks;

$context = $this->option . '.' . $this->name;

// Include the plugins for the change of state event.
\JPluginHelper::importPlugin($this->events_map['change_state']);

Expand Down Expand Up @@ -1037,6 +1056,16 @@ public function publish(&$pks, $value = 1)
}
}

// Trigger the change state event.
$result = Factory::getApplication()->triggerEvent($this->event_before_change_state, array($context, $pks, $value));

if (in_array(false, $result, true))
{
$this->setError($table->getError());

return false;
}

// Attempt to change the state of the records.
if (!$table->publish($pks, $value, $user->get('id')))
{
Expand All @@ -1045,8 +1074,6 @@ public function publish(&$pks, $value = 1)
return false;
}

$context = $this->option . '.' . $this->name;

// Trigger the change state event.
$result = Factory::getApplication()->triggerEvent($this->event_change_state, array($context, $pks, $value));

Expand Down
12 changes: 12 additions & 0 deletions libraries/src/Workflow/WorkflowServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ public static function updateContentState($pks, $condition): bool;
* @since __DEPLOY_VERSION__
*/
public static function getConditions($extension): array;

/**
* Returns the table for the count items functions for the given section.
*
* @param array $stage_ids The stage ids to test for
* @param string $section The section
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
public function canDeleteStages(array $stage_ids, string $section = '') : bool;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than canDeleteStages please can we make this isWorkflowsEnabled. If workflows is enabled for a core extension then we need the requirement checks. So instead of doing all the logic here, leave it in the plugin and just use the components enabled check

}
71 changes: 71 additions & 0 deletions libraries/src/Workflow/WorkflowServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Factory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't needed

use Joomla\Utilities\ArrayHelper;

/**
* Trait for component workflow service.
*
Expand All @@ -30,4 +33,72 @@ public static function getConditions($extension): array
{
return defined('self::CONDITION_NAMES') ? self::CONDITION_NAMES : Workflow::CONDITION_NAMES;
}

/**
* Returns the table for the count items functions for the given section.
*
* @param array $stage_ids The stage ids to test for
* @param string $section The section
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
public function canDeleteStages(array $stage_ids, string $section = '') : bool
{
$db = Factory::getDbo();

$parts = explode('.', $extension);

$stage_ids = ArrayHelper::toInteger($stage_ids);
$stage_ids = array_filter($stage_ids);

$section = '';

if (!empty($parts[1]))
{
$section = $parts[1];
}

$table = $this->getWorkflowTableBySection($section);

if (empty($stage_ids) || !$table)
{
return true;
}

$query = $db->getQuery(true);

$query ->select('COUNT(' . $db->quoteName('b.id') . ')')
->from($query->quoteName('#__workflow_associations', 'wa'))
->from($query->quoteName('#__workflow_stages', 's'))
->from($db->quoteName($table, 'b'))
->where($db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('s.id'))
->where($db->quoteName('wa.item_id') . ' = ' . $db->quoteName('b.id'))
->whereIn($db->quoteName('s.id'), $stage_ids);

try {
return (int) $db->setQuery($query)->loadResult() === 0;
}
catch (Exception $ex)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}

return false;
}

/**
* Returns a table name for the state association
*
* @param string $section An optional section to differ different areas in the component
*
* @return string|null
*
* @since __DEPLOY_VERSION__
*/
protected function getWorkflowTableBySection(string $section = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no point in this. Just remove it and force people to implement it in the interface

{
return null;
}
}
Loading