Closed joomlapl-bot closed 1 year ago
PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/31120 Poniżej zmiany w oryginale:
PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/31120 Poniżej zmiany w oryginale:
Click to expand the diff!
```diff diff --git a/administrator/language/en-GB/com_workflow.ini b/administrator/language/en-GB/com_workflow.ini index 65ece0af09ca..d627a14271ef 100644 --- a/administrator/language/en-GB/com_workflow.ini +++ b/administrator/language/en-GB/com_workflow.ini @@ -46,7 +46,7 @@ COM_WORKFLOW_MODIFIED_AT_ASC="Date Modified ascending" COM_WORKFLOW_MODIFIED_AT_DESC="Date Modified descending" COM_WORKFLOW_MODIFIED_LABEL="Date Modified" COM_WORKFLOW_MSG_DELETE_IS_DEFAULT="You can't delete the default item." -COM_WORKFLOW_MSG_DELETE_STAGE_IS_ASSIGNED="This stage is in use by the component." +COM_WORKFLOW_MSG_DELETE_STAGE_IS_ASSIGNED="This stage is assigned to an item of this component and has to remain in a published state." COM_WORKFLOW_MSG_DELETE_WORKFLOW_IS_ASSIGNED="This workflow is in use by the component." COM_WORKFLOW_MSG_DISABLE_DEFAULT="The default item has to stay published." COM_WORKFLOW_MSG_WORKFLOWS_DELETE_ERROR="There was a problem while deleting the item: %s" diff --git a/plugins/content/joomla/joomla.php b/plugins/content/joomla/joomla.php index 55d570c88216..704c36867c84 100644 --- a/plugins/content/joomla/joomla.php +++ b/plugins/content/joomla/joomla.php @@ -16,6 +16,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Table\CoreContent; +use Joomla\CMS\Table\Table; use Joomla\CMS\User\User; use Joomla\CMS\Workflow\WorkflowServiceInterface; use Joomla\Component\Workflow\Administrator\Table\StageTable; @@ -70,7 +71,7 @@ public function onContentBeforeSave($context, $table, $isNew, $data) } // Check we are handling the frontend edit form. - if (!in_array($context, ['com_workflow.stage', 'com_workflow.workflow']) || $isNew) { + if (!in_array($context, ['com_workflow.stage', 'com_workflow.workflow']) || $isNew || !$table->hasField('published')) { return true; } @@ -78,13 +79,15 @@ public function onContentBeforeSave($context, $table, $isNew, $data) $item->load($table->id); - if ($item->published != -2 && $data['published'] == -2) { + $publishedField = $item->getColumnAlias('published'); + + if ($item->$publishedField > 0 && isset($data[$publishedField]) && $data[$publishedField] < 1) { switch ($context) { case 'com_workflow.workflow': - return $this->_canDeleteWorkflow($item->id); + return $this->_workflowNotUsed($item->id); case 'com_workflow.stage': - return $this->_canDeleteStage($item->id); + return $this->_stageNotUsed($item->id); } } @@ -181,10 +184,10 @@ public function onContentBeforeDelete($context, $data) return $this->_canDeleteCategories($data); case 'com_workflow.workflow': - return $this->_canDeleteWorkflow($data->id); + return $this->_workflowNotUsed($data->id); case 'com_workflow.stage': - return $this->_canDeleteStage($data->id); + return $this->_stageNotUsed($data->id); } } @@ -201,7 +204,7 @@ public function onContentBeforeDelete($context, $data) */ public function onContentBeforeChangeState($context, $pks, $value) { - if ($value != -2 || !in_array($context, ['com_workflow.workflow', 'com_workflow.stage'])) { + if ($value > 0 || !in_array($context, ['com_workflow.workflow', 'com_workflow.stage'])) { return true; } @@ -210,14 +213,16 @@ public function onContentBeforeChangeState($context, $pks, $value) foreach ($pks as $id) { switch ($context) { case 'com_workflow.workflow': - return $result && $this->_canDeleteWorkflow($id); + $result = $result && $this->_workflowNotUsed($id); + break; case 'com_workflow.stage': - $result = $result && $this->_canDeleteStage($id); + $result = $result && $this->_stageNotUsed($id); + break; } } - return true; + return $result; } /** @@ -296,7 +301,7 @@ private function _canDeleteCategories($data) * * @since 4.0.0 */ - private function _canDeleteWorkflow($pk) + private function _workflowNotUsed($pk) { // Check if this workflow is the default stage $table = new WorkflowTable($this->db); @@ -356,7 +361,7 @@ private function _canDeleteWorkflow($pk) * * @since 4.0.0 */ - private function _canDeleteStage($pk) + private function _stageNotUsed($pk) { $table = new StageTable($this->db); @@ -550,9 +555,9 @@ public function onContentChangeState($context, $pks, $value) { $pks = ArrayHelper::toInteger($pks); - if ($context === 'com_workflow.stage' && $value == -2) { + if ($context === 'com_workflow.stage' && $value < 1) { foreach ($pks as $pk) { - if (!$this->_canDeleteStage($pk)) { + if (!$this->_stageNotUsed($pk)) { return false; } } ```