Skip to content

Commit

Permalink
Add stage id for new articles
Browse files Browse the repository at this point in the history
  • Loading branch information
bembelimen committed Sep 3, 2018
1 parent 356e15d commit add6b04
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions plugins/sampledata/multilang/multilang.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -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":""}',
Expand Down Expand Up @@ -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();

Expand All @@ -1107,7 +1116,6 @@ private function addArticle($itemLanguage, $categoryId)
. 'debet libris consulatu.</p>',
'images' => json_encode(array()),
'urls' => json_encode(array()),
'state' => 1,
'created' => $currentDate,
'created_by' => (int) $this->getAdminId(),
'created_by_alias' => 'Joomla',
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit add6b04

Please sign in to comment.