From add6b0457d2f6656d8c0de034811e50d8d862339 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Mon, 3 Sep 2018 09:46:52 +0200 Subject: [PATCH] Add stage id for new articles --- plugins/sampledata/multilang/multilang.php | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 9746b66a3d52b..d05b0258f7a25 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -400,7 +400,7 @@ public function onAjaxSampledataApplyStep6() $groupedAssociations['com_categories.item'][$siteLang->language] = $tableCategory->id; - if (!$tableArticle = $this->addArticle($siteLang, $tableCategory->id)) + if (!$tableArticle = $this->addArticle($siteLang, $tableCategory->id, $tableWorkflow->stageId)) { $response = array(); $response['success'] = false; @@ -1007,6 +1007,14 @@ public function addWorkflow($itemLanguage) $workflow = $workflowModel->getItem(); + $query = $this->db->getQuery(true) + ->select($this->db->quoteName('id')) + ->from($this->db->quoteName('#__workflow_stages')) + ->where($this->db->quoteName('workflow_id') . ' = ' . (int) $workflow->id) + ->where($this->db->quoteName('default') . ' = 1'); + + $workflow->stageId = (int) $this->db->setQuery($query)->loadResult(); + return $workflow; } @@ -1020,7 +1028,7 @@ public function addWorkflow($itemLanguage) * * @since 4.0.0 */ - public function addCategory($itemLanguage, $workflow_id = 0) + public function addCategory($itemLanguage, $workflowId = 0) { $newlanguage = new Language($itemLanguage->language, false); $newlanguage->load('joomla', JPATH_ADMINISTRATOR, $itemLanguage->language, true); @@ -1035,7 +1043,7 @@ public function addCategory($itemLanguage, $workflow_id = 0) 'description' => '', 'published' => 1, 'access' => 1, - 'params' => '{"target":"","image":"", "workflow_id":"' . (int) $workflow_id . '"}', + 'params' => '{"target":"","image":"", "workflow_id":"' . (int) $workflowId . '"}', 'metadesc' => '', 'metakey' => '', 'metadata' => '{"page_title":"","author":"","robots":""}', @@ -1078,12 +1086,13 @@ public function addCategory($itemLanguage, $workflow_id = 0) * * @param stdClass $itemLanguage Language Object. * @param integer $categoryId The id of the category where we want to add the article. + * @param integer $stageId The id of the initial stage. * * @return JTable|boolean Article Object. False otherwise. * * @since 4.0.0 */ - private function addArticle($itemLanguage, $categoryId) + private function addArticle($itemLanguage, $categoryId, $stageId) { $db = Factory::getDbo(); @@ -1107,7 +1116,6 @@ private function addArticle($itemLanguage, $categoryId) . 'debet libris consulatu.

', 'images' => json_encode(array()), 'urls' => json_encode(array()), - 'state' => 1, 'created' => $currentDate, 'created_by' => (int) $this->getAdminId(), 'created_by_alias' => 'Joomla', @@ -1160,6 +1168,21 @@ private function addArticle($itemLanguage, $categoryId) return false; } + $assoc = new stdClass; + + $assoc->item_id = $newId; + $assoc->stage_id = $stageId; + $assoc->extension = 'com_content'; + + try + { + $db->insertObject('#__workflow_associations', $assoc); + } + catch (JDatabaseExceptionExecuting $e) + { + return false; + } + return $article; }