Skip to content

Commit

Permalink
Fix joomla#58 ordering numbers for workflow, stages, transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
chmst committed Apr 23, 2020
1 parent ceabd4c commit c8d678f
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ protected function generateNewTitle($category_id, $alias, $title)

return array($title, $alias);
}



/**
* Method to get the new Ordering number
*
* @param string $table The anme of the table
*
* @return integer the next ordering number
*
* @since 4.0.0
*/
protected function getNextOrdering($table)
{
$db = Factory::getDbo();
$query = $db->getQuery(true);

$query
->select('MAX(' . $db->quoteName('ordering') . ') + 1')
->from($db->quoteName($table));

return $db->setQuery($query)->loadResult();
}

/**
* Method to save the form data.
Expand All @@ -87,6 +110,7 @@ public function save($data)
$extension = $app->getUserStateFromRequest($context . '.filter.extension', 'extension', null, 'cmd');
$data['extension'] = !empty($data['extension']) ? $data['extension'] : $extension;
$data['asset_id'] = 0;
$data['ordering'] = $this->getNextOrdering('#__workflows');

if ($input->get('task') == 'save2copy')
{
Expand All @@ -109,7 +133,9 @@ public function save($data)
if ($result && $input->getCmd('task') !== 'save2copy' && $this->getState($this->getName() . '.new'))
{
$workflow_id = (int) $this->getState($this->getName() . '.id');

$stageOrdering = $this->getNextOrdering('#__workflow_stages');
$transitionOrdering = $this->getNextOrdering('#__workflow_transitions');

$stages = [
[
'title' => 'JUNPUBLISHED',
Expand Down Expand Up @@ -147,6 +173,7 @@ public function save($data)
$table->published = 1;
$table->default = (int) !empty($stage['default']);
$table->description = '';
$table->ordering = $stageOrdering++;

$table->store();

Expand All @@ -160,6 +187,7 @@ public function save($data)
$transition->from_stage_id = -1;
$transition->to_stage_id = (int) $table->id;
$transition->options = $stage['options'];
$transition->ordering = $transitionOrdering++;

$transition->store();
}
Expand Down

0 comments on commit c8d678f

Please sign in to comment.