Skip to content

Commit

Permalink
Parameterized queries
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ committed Jun 16, 2020
1 parent cefaa7b commit 54466e4
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\Database\ParameterType;
use Joomla\Input\Input;

/**
Expand Down Expand Up @@ -182,14 +183,16 @@ public function postSaveHook(BaseDatabaseModel $model, $validData = array())

$key = $table->getKeyName();

$recordId = $this->input->getInt($key);
$recordId = (int) $this->input->getInt($key);

// @todo Moves queries out of the controller.
$db = $model->getDbo();
$query = $db->getQuery(true);

$query->select('*')
->from($db->quoteName('#__workflow_stages'))
->where($db->quoteName('workflow_id') . ' = ' . (int) $recordId);
->where($db->quoteName('workflow_id') . ' = :id')
->bind(':id', $recordId, ParameterType::INTEGER);

$statuses = $db->setQuery($query)->loadAssocList();

Expand All @@ -215,11 +218,11 @@ public function postSaveHook(BaseDatabaseModel $model, $validData = array())
$mapping[$oldID] = (int) $table->id;
}

$query->clear();

$query->select('*')
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__workflow_transitions'))
->where($db->quoteName('workflow_id') . ' = ' . (int) $recordId);
->where($db->quoteName('workflow_id') . ' = :id')
->bind(':id', $recordId, ParameterType::INTEGER);

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

Expand Down

0 comments on commit 54466e4

Please sign in to comment.