Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow remove #53

Merged
merged 6 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormFactoryInterface;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\MVC\Model\WorkflowBehaviorTrait;
use Joomla\CMS\MVC\Model\WorkflowModelInterface;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Table\Category;
Expand All @@ -41,8 +45,10 @@
* @since 1.6
*/

class ArticleModel extends AdminModel
class ArticleModel extends AdminModel implements WorkflowModelInterface
{
use WorkflowBehaviorTrait;

/**
* The prefix to use with controller messages.
*
Expand All @@ -67,6 +73,13 @@ class ArticleModel extends AdminModel
*/
protected $associationsContext = 'com_content.item';

public function __construct($config = array(), MVCFactoryInterface $factory = null, FormFactoryInterface $formFactory = null) {

parent::__construct($config, $factory, $formFactory);

$this->setUpWorkflow('com_content.article');
}

/**
* Function that can be overriden to do any data cleanup after batch copying data
*
Expand Down Expand Up @@ -1274,6 +1287,8 @@ protected function preprocessForm(Form $form, $data, $group = 'content')
}
}

$this->preprocessFormWorkflow($form, $data);

parent::preprocessForm($form, $data, $group);
}

Expand Down
16 changes: 2 additions & 14 deletions components/com_content/src/Model/ArchiveModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,8 @@ public function getYears()
$years = $query->year($db->quoteName('c.created'));

$query->select('DISTINCT ' . $years)
->from(
[
$db->quoteName('#__content', 'c'),
$db->quoteName('#__workflow_associations', 'wa'),
$db->quoteName('#__workflow_stages', 'ws'),
]
)
->where(
[
$db->quoteName('c.id') . ' = ' . $db->quoteName('wa.item_id'),
$db->quoteName('ws.id') . ' = ' . $db->quoteName('wa.stage_id'),
$db->quoteName('ws.condition') . ' = ' . ContentComponent::CONDITION_ARCHIVED,
]
)
->from($db->quoteName('#__content', 'c'))
->where($db->quoteName('c.state') . ' = ' . ContentComponent::CONDITION_ARCHIVED)
->extendWhere(
'AND',
[
Expand Down
16 changes: 2 additions & 14 deletions components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public function getItem($pk = null)
[
$db->quoteName('fp.featured_up'),
$db->quoteName('fp.featured_down'),
$db->quoteName('ws.condition'),
$db->quoteName('c.title', 'category_title'),
$db->quoteName('c.alias', 'category_alias'),
$db->quoteName('c.access', 'category_access'),
Expand All @@ -156,16 +155,6 @@ public function getItem($pk = null)
]
)
->from($db->quoteName('#__content', 'a'))
->join(
'INNER',
$db->quoteName('#__workflow_associations', 'wa'),
$db->quoteName('a.id') . ' = ' . $db->quoteName('wa.item_id')
)
->join(
'INNER',
$db->quoteName('#__workflow_stages', 'ws'),
$db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('ws.id')
)
->join(
'INNER',
$db->quoteName('#__categories', 'c'),
Expand All @@ -178,7 +167,6 @@ public function getItem($pk = null)
->where(
[
$db->quoteName('a.id') . ' = :pk',
$db->quoteName('wa.extension') . ' = ' . $db->quote('com_content'),
$db->quoteName('c.published') . ' > 0',
]
)
Expand Down Expand Up @@ -222,7 +210,7 @@ public function getItem($pk = null)

if (is_numeric($published))
{
$query->whereIn($db->quoteName('ws.condition'), [(int) $published, (int) $archived]);
$query->whereIn($db->quoteName('a.state'), [(int) $published, (int) $archived]);
}

$db->setQuery($query);
Expand All @@ -235,7 +223,7 @@ public function getItem($pk = null)
}

// Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived)) && ($data->condition != $published && $data->condition != $archived))
if ((is_numeric($published) || is_numeric($archived)) && ($data->state != $published && $data->state != $archived))
{
throw new \Exception(Text::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND'), 404);
}
Expand Down
20 changes: 7 additions & 13 deletions components/com_content/src/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function __construct($config = array())
'checked_out_time', 'a.checked_out_time',
'catid', 'a.catid', 'category_title',
'state', 'a.state',
'stage_condition', 'ws.condition',
'access', 'a.access', 'access_level',
'created', 'a.created',
'created_by', 'a.created_by',
Expand Down Expand Up @@ -243,13 +242,10 @@ protected function getListQuery()
[
$db->quoteName('fp.featured_up'),
$db->quoteName('fp.featured_down'),
$db->quoteName('wa.stage_id', 'stage_id'),
$db->quoteName('ws.title', 'state_title'),
$db->quoteName('ws.condition', 'stage_condition'),
// Published/archived article in archived category is treated as archived article. If category is not published then force 0.
'CASE WHEN ' . $db->quoteName('c.published') . ' = 2 AND ' . $db->quoteName('ws.condition') . ' > 0 THEN ' . $conditionArchived
'CASE WHEN ' . $db->quoteName('c.published') . ' = 2 AND ' . $db->quoteName('a.state') . ' > 0 THEN ' . $conditionArchived
. ' WHEN ' . $db->quoteName('c.published') . ' != 1 THEN ' . $conditionUnpublished
. ' ELSE ' . $db->quoteName('ws.condition') . ' END AS ' . $db->quoteName('state'),
. ' ELSE ' . $db->quoteName('a.state') . ' END AS ' . $db->quoteName('state'),
$db->quoteName('c.title', 'category_title'),
$db->quoteName('c.path', 'category_route'),
$db->quoteName('c.access', 'category_access'),
Expand All @@ -270,8 +266,6 @@ protected function getListQuery()
]
)
->from($db->quoteName('#__content', 'a'))
->join('LEFT', $db->quoteName('#__workflow_associations', 'wa'), $db->quoteName('wa.item_id') . ' = ' . $db->quoteName('a.id'))
->join('LEFT', $db->quoteName('#__workflow_stages', 'ws'), $db->quoteName('ws.id') . ' = ' . $db->quoteName('wa.stage_id'))
->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid'))
->join('LEFT', $db->quoteName('#__users', 'ua'), $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'))
->join('LEFT', $db->quoteName('#__users', 'uam'), $db->quoteName('uam.id') . ' = ' . $db->quoteName('a.modified_by'))
Expand Down Expand Up @@ -341,8 +335,8 @@ protected function getListQuery()
* If category is archived then article has to be published or archived.
* Or categogy is published then article has to be archived.
*/
$query->where('((' . $db->quoteName('c.published') . ' = 2 AND ' . $db->quoteName('ws.condition') . ' > :conditionUnpublished)'
. ' OR (' . $db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('ws.condition') . ' = :conditionArchived))'
$query->where('((' . $db->quoteName('c.published') . ' = 2 AND ' . $db->quoteName('a.state') . ' > :conditionUnpublished)'
. ' OR (' . $db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('a.state') . ' = :conditionArchived))'
)
->bind(':conditionUnpublished', $conditionUnpublished, ParameterType::INTEGER)
->bind(':conditionArchived', $conditionArchived, ParameterType::INTEGER);
Expand All @@ -352,14 +346,14 @@ protected function getListQuery()
$condition = (int) $condition;

// Category has to be published
$query->where($db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('ws.condition') . ' = :wsCondition')
->bind(':wsCondition', $condition, ParameterType::INTEGER);
$query->where($db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('a.state') . ' = :condition')
->bind(':condition', $condition, ParameterType::INTEGER);
}
elseif (is_array($condition))
{
// Category has to be published
$query->where(
$db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('ws.condition')
$db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('a.state')
. ' IN (' . implode(',', $query->bindArray($condition)) . ')'
);
}
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/src/Model/CategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected function populateState($ordering = null, $direction = null)
}
else
{
$this->setState('filter.condition', array(0, 1));
$this->setState('filter.condition', [0, 1]);
}

// Process show_noauth parameter
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/src/Model/FeaturedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function populateState($ordering = null, $direction = null)
}
else
{
$this->setState('filter.condition', array(ContentComponent::CONDITION_UNPUBLISHED, ContentComponent::CONDITION_PUBLISHED));
$this->setState('filter.condition', [ContentComponent::CONDITION_UNPUBLISHED, ContentComponent::CONDITION_PUBLISHED]);
}

// Process show_noauth parameter
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/tmpl/article/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<h2 itemprop="headline">
<?php echo $this->escape($this->item->title); ?>
</h2>
<?php if ($this->item->condition == ContentComponent::CONDITION_UNPUBLISHED) : ?>
<?php if ($this->item->state == ContentComponent::CONDITION_UNPUBLISHED) : ?>
<span class="badge badge-warning"><?php echo Text::_('JUNPUBLISHED'); ?></span>
<?php endif; ?>
<?php if (strtotime($this->item->publish_up) > strtotime(Factory::getDate())) : ?>
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/tmpl/category/blog_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<?php echo LayoutHelper::render('joomla.content.intro_image', $this->item); ?>

<div class="item-content">
<?php if ($this->item->stage_condition == ContentComponent::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
<?php if ($this->item->state == ContentComponent::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
|| (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
<div class="system-unpublished">
<?php endif; ?>
Expand Down Expand Up @@ -86,7 +86,7 @@

<?php endif; ?>

<?php if ($this->item->stage_condition == ContentComponent::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
<?php if ($this->item->state == ContentComponent::CONDITION_UNPUBLISHED || strtotime($this->item->publish_up) > strtotime(Factory::getDate())
|| (!is_null($this->item->publish_down) && strtotime($this->item->publish_down) < strtotime(Factory::getDate()))) : ?>
</div>
<?php endif; ?>
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/tmpl/category/default_articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<?php endif; ?>
<tbody>
<?php foreach ($this->items as $i => $article) : ?>
<?php if ($this->items[$i]->stage_condition == ContentComponent::CONDITION_UNPUBLISHED) : ?>
<?php if ($this->items[$i]->state == ContentComponent::CONDITION_UNPUBLISHED) : ?>
<tr class="system-unpublished cat-list-row<?php echo $i % 2; ?>">
<?php else : ?>
<tr class="cat-list-row<?php echo $i % 2; ?>" >
Expand Down Expand Up @@ -225,7 +225,7 @@
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<?php if ($article->stage_condition == ContentComponent::CONDITION_UNPUBLISHED) : ?>
<?php if ($article->state == ContentComponent::CONDITION_UNPUBLISHED) : ?>
<span class="list-published badge badge-warning">
<?php echo Text::_('JUNPUBLISHED'); ?>
</span>
Expand Down
22 changes: 1 addition & 21 deletions libraries/src/Helper/ContentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public static function countRelations(&$items, $config)
'2' => 'count_archived',
);

$usesWorkflows = (isset($config->uses_workflows) && $config->uses_workflows === true);

// Index category objects by their ID
$records = array();

Expand All @@ -87,7 +85,7 @@ public static function countRelations(&$items, $config)

// Table alias for related data table below will be 'c', and state / condition column is inside related data table
$related_tbl = '#__' . $config->related_tbl;
$state_col = ($usesWorkflows ? 's.' : 'c.') . $config->state_col;
$state_col = 'c.' . $config->state_col;

// Supported cases
switch ($config->relation_type)
Expand Down Expand Up @@ -117,24 +115,6 @@ public static function countRelations(&$items, $config)
return $items;
}

if ($usesWorkflows)
{
$query->from(
[
$db->quoteName('#__workflow_stages', 's'),
$db->quoteName('#__workflow_associations', 'a'),
]
)
->where(
[
$db->quoteName('s.id') . ' = ' . $db->quoteName('a.stage_id'),
$db->quoteName('a.extension') . ' = :component',
$db->quoteName('a.item_id') . ' = ' . $db->quoteName('c.id'),
]
)
->bind(':component', $config->workflows_component);
}

/**
* Get relation counts for all category objects with single query
* NOTE: 'state IN', allows counting specific states / conditions only, also prevents warnings with custom states / conditions, do not remove
Expand Down
Loading