Skip to content

Commit

Permalink
convert to prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
alikon committed Jun 11, 2019
1 parent 87a4670 commit 54c295f
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions administrator/components/com_content/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Joomla\Component\Content\Administrator\Helper\ContentHelper;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Component\Workflow\Administrator\Table\StageTable;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

Expand Down Expand Up @@ -384,21 +385,23 @@ public function publish(&$pks, $value = 1)
]
);

$query ->select($select)
->from($db->quoteName('#__workflow_transitions', 'wt'))
->from($db->quoteName('#__workflow_stages', 'ws'))
->from($db->quoteName('#__workflow_stages', 'ws2'))
->from($db->quoteName('#__workflow_associations', 'wa'))
->where('(' . $db->quoteName('wt.from_stage_id') . ' = -1 OR ' .
$value = (int) $value;
$query->select($select)
->from($db->quoteName('#__workflow_transitions', 'wt'))
->from($db->quoteName('#__workflow_stages', 'ws'))
->from($db->quoteName('#__workflow_stages', 'ws2'))
->from($db->quoteName('#__workflow_associations', 'wa'))
->where('(' . $db->quoteName('wt.from_stage_id') . ' = -1 OR ' .
$db->quoteName('wt.from_stage_id') . ' = ' . $db->quoteName('wa.stage_id') . ')')
->where($db->quoteName('wt.to_stage_id') . ' = ' . $db->quoteName('ws.id'))
->where($db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('ws2.id'))
->where($db->quoteName('wt.workflow_id') . ' = ' . $db->quoteName('ws.workflow_id'))
->where($db->quoteName('wt.workflow_id') . ' = ' . $db->quoteName('ws2.workflow_id'))
->where($db->quoteName('wt.to_stage_id') . ' != ' . $db->quoteName('wa.stage_id'))
->whereIn($db->quoteName('wa.item_id'), $pks)
->where($db->quoteName('wa.extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('ws.condition') . ' = ' . (int) $value);
->where($db->quoteName('wt.to_stage_id') . ' = ' . $db->quoteName('ws.id'))
->where($db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('ws2.id'))
->where($db->quoteName('wt.workflow_id') . ' = ' . $db->quoteName('ws.workflow_id'))
->where($db->quoteName('wt.workflow_id') . ' = ' . $db->quoteName('ws2.workflow_id'))
->where($db->quoteName('wt.to_stage_id') . ' != ' . $db->quoteName('wa.stage_id'))
->whereIn($db->quoteName('wa.item_id'), $pks)
->where($db->quoteName('wa.extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('ws.condition') . ' = :value')
->bind(':value', $value, ParameterType::INTEGER);

$transitions = $db->setQuery($query)->loadObjectList();

Expand Down Expand Up @@ -870,14 +873,16 @@ public function save($data)

// Set the new state
$query = $db->getQuery(true);
$transition = (int) $data['transition'];

$query ->select($db->quoteName(['ws.id', 'ws.condition']))
$query->select($db->quoteName(['ws.id', 'ws.condition']))
->from($db->quoteName('#__workflow_stages', 'ws'))
->from($db->quoteName('#__workflow_transitions', 'wt'))
->where($db->quoteName('wt.to_stage_id') . ' = ' . $db->quoteName('ws.id'))
->where($db->quoteName('wt.id') . ' = ' . (int) $data['transition'])
->where($db->quoteName('wt.id') . ' = :transition')
->where($db->quoteName('ws.published') . ' = 1')
->where($db->quoteName('wt.published') . ' = 1');
->where($db->quoteName('wt.published') . ' = 1')
->bind(':transition', $transition, ParameterType::INTEGER);

$stage = $db->setQuery($query)->loadObject();

Expand Down Expand Up @@ -1005,10 +1010,12 @@ public function featured($pks, $value = 0)
try
{
$db = $this->getDbo();
$value = (int) $value;
$query = $db->getQuery(true)
->update($db->quoteName('#__content'))
->set('featured = ' . (int) $value)
->where('id IN (' . implode(',', $pks) . ')');
->set($db->quoteName('featured') . ' = :value')
->whereIn($db->quoteName('id'), $pks)
->bind(':value', $value, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();

Expand All @@ -1018,7 +1025,7 @@ public function featured($pks, $value = 0)
// Clear the existing features settings.
$query = $db->getQuery(true)
->delete($db->quoteName('#__content_frontpage'))
->where('content_id IN (' . implode(',', $pks) . ')');
->whereIn($db->quoteName('content_id'), $pks);
$db->setQuery($query);
$db->execute();
}
Expand All @@ -1028,7 +1035,7 @@ public function featured($pks, $value = 0)
$query = $db->getQuery(true)
->select('f.content_id')
->from('#__content_frontpage AS f')
->where('content_id IN (' . implode(',', $pks) . ')');
->whereIn($db->quoteName('content_id'), $pks);
$db->setQuery($query);

$oldFeatured = $db->loadColumn();
Expand Down Expand Up @@ -1203,7 +1210,7 @@ public function delete(&$pks)
$db = $this->getDbo();
$query = $db->getQuery(true)
->delete($db->quoteName('#__content_frontpage'))
->where('content_id IN (' . implode(',', $pks) . ')');
->whereIn($db->quoteName('content_id'), $pks);
$db->setQuery($query);
$db->execute();

Expand Down Expand Up @@ -1261,6 +1268,7 @@ protected function getWorkflowByCategory($catId)
if ($workflow_id > 0)
{
$query = $db->getQuery(true);
$workflowId = (int) $workflow_id;

$query ->select(
$db->quoteName(
Expand All @@ -1277,7 +1285,8 @@ protected function getWorkflowByCategory($catId)
->where($db->quoteName('ws.default') . ' = 1')
->where($db->quoteName('w.published') . ' = 1')
->where($db->quoteName('ws.published') . ' = 1')
->where($db->quoteName('w.id') . ' = ' . (int) $workflow_id);
->where($db->quoteName('w.id') . ' = :id')
->bind(':id', $workflowId, ParameterType::INTEGER);

$workflow = $db->setQuery($query)->loadObject();

Expand Down Expand Up @@ -1348,7 +1357,7 @@ public function runTransition($pk, $transition_id)
PluginHelper::importPlugin($this->events_map['change_state']);

// Trigger the change stage event.
Factory::getApplication()->triggerEvent($this->event_change_state, [$context, [$pk], $workflow->getConditionForTransition($transition_id)]);
Factory::getApplication()->triggerEvent($this->event_change_state, [$context, [$pk], $transition_id]);

return true;
}
Expand Down

0 comments on commit 54c295f

Please sign in to comment.