Skip to content
Closed
Changes from all commits
Commits
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
39 changes: 38 additions & 1 deletion plugins/sampledata/multilang/multilang.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,31 @@ public function addCategory($itemLanguage)
// Initialize a new category.
$category = Table::getInstance('CategoryTable', '\\Joomla\\Component\\Categories\\Administrator\\Table\\');

// Get Joomla default workflow // Should be modified when the title is changed to a lang string!
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__workflows'))
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('title') . ' = ' . $db->quote('Joomla! Default'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not check for the title of the workflow but for the column default, so you get a default workflow, when the user changes it. But you don't need any workflow ID in the category itself (which I wouldn't set), because the default is always the fallback.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, if I choose the column default and it is not containing the published state as I wish, what can I do?

$db->setQuery($query);

try
{
$workflowId = $db->loadResult();
}
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}

$data = array(
'extension' => 'com_content',
'title' => $title . ' (' . strtolower($itemLanguage->language) . ')',
'description' => '',
'published' => 1,
'access' => 1,
'params' => '{"target":"","image":""}',
'params' => '{"target":"","image":"", "workflow_id":"' . $workflowId . '"}',
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't set the workflow_id here. Just let it away, so the default will be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I do not need the workflow id, then I do not need either the query as its only purpose is to get that id.
What I need here is definitely to set the articles to Published, and set the category to use the correct workflow id where Published is the default or can be obtained.

But what if another workflow is set as default and it is not using Published as its default state?
screen shot 2018-08-12 at 08 28 11

That one has Unpublished as default state
screen shot 2018-08-12 at 08 30 39

Therefore, basically, IF workflows IS enabled, I want to force using the default Joomla defaults which should NEVER be modifed or deleted. But we get there into other issues as we do not want save2copy to autopublish the copies, etc. which means Joomla Default workflow is not fit for save2copy....
A vicious circle...

'metadesc' => '',
'metakey' => '',
'metadata' => '{"page_title":"","author":"","robots":""}',
Expand Down Expand Up @@ -1107,6 +1125,25 @@ private function addArticle($itemLanguage, $categoryId)
}
catch (JDatabaseExceptionExecuting $e)
{
$this->setError($e->getMessage());

return false;
}

$query->clear()
->insert($db->qn('#__workflow_associations'))
->values($newId . ', 2,' . $db->quote('com_content'));
Copy link
Contributor

@bembelimen bembelimen Aug 11, 2018

Choose a reason for hiding this comment

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

You should not use 2 as hardcode value, but you should take the default state (it's a column, too) from the pool of states which is part of the default-workflow (from above)

Copy link
Member Author

Choose a reason for hiding this comment

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

what if that default state is NOT "published"?

Copy link
Member Author

@infograf768 infograf768 Aug 11, 2018

Choose a reason for hiding this comment

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

looks like we have first to find which workflow is the default, and then which states are proposed by this default workflow, and then the correct condition "1" (for published) from which we have to find the id to use. In our default Joomla, that id is 2


$db->setQuery($query);

try
{
$db->execute();
}
catch (JDatabaseExceptionExecuting $e)
{
$this->setError($e->getMessage());

return false;
}

Expand Down