-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Workflow prevent trashing of used stages/workflows #21579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
f64c9ca
61d9c0b
6be26a1
b25c0b3
647092d
b1eebd6
ab6369e
0a2cb77
f21b84b
d4428d7
974c564
272fcf8
fac863e
102d260
85b4ff1
069fc8b
899805c
85223e5
07b7a44
9305a49
ff70dc6
e93e017
e762553
d9b2b2d
e204edf
22b2446
9c066cc
10d8bc0
14fcc14
0843fbc
4e68625
5f31e9f
a9b60ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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." | ||
|
||
| COM_WORKFLOW_NA="N/A" | ||
| COM_WORKFLOW_NAME="Name" | ||
| COM_WORKFLOW_NEW="New" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ | |
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| use Joomla\CMS\Factory; | ||
|
||
| use Joomla\Utilities\ArrayHelper; | ||
|
|
||
| /** | ||
| * Trait for component workflow service. | ||
| * | ||
|
|
@@ -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) | ||
|
||
| { | ||
| return null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
differ different
typo?