Skip to content

Commit

Permalink
Fix contact submission query
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Jul 2, 2019
1 parent 5e89393 commit 0fd4c87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
7 changes: 7 additions & 0 deletions components/com_contact/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public function submit()
$model->setState('filter.published', 1);
$contact = $model->getItem($id);

if ($contact === false)
{
$this->setMessage($model->getError(), 'error');

return false;
}

// Get item params, take menu parameters into account if necessary
$active = $app->getMenu()->getActive();
$stateParams = clone $model->getState()->get('params');
Expand Down
23 changes: 15 additions & 8 deletions components/com_contact/Model/ContactModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Registry\Registry;

/**
Expand Down Expand Up @@ -194,16 +195,15 @@ public function getItem($pk = null)

// Join on category table.
->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
->leftJoin($db->quoteName('#__categories', 'c') . ' ON c.id = a.catid')
->join('LEFT', $db->quoteName('#__categories', 'c'), 'c.id = a.catid')

// Join over the categories to get parent category titles
->select('parent.title AS parent_title, parent.id AS parent_id, parent.path AS parent_route, parent.alias AS parent_alias')
->leftJoin($db->quoteName('#__categories', 'parent') . ' ON parent.id = c.parent_id')
->join('LEFT', $db->quoteName('#__categories', 'parent'), 'parent.id = c.parent_id')
->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $pk, ParameterType::INTEGER);

// Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate());
$nowDate = Factory::getDate()->toSql();

// Filter by published state.
Expand All @@ -212,11 +212,18 @@ public function getItem($pk = null)

if (is_numeric($published))
{
$query->where('(a.published = :published OR a.published = :archived)')
$queryString = 'a.published = :published';

if ($archived !== null)
{
$queryString = '(' . $queryString . ' OR a.published = :archived)';
$query->bind(':archived', $archived, ParameterType::INTEGER);
}

$query->where($queryString)
->where('(' . $query->isNullDatetime('a.publish_up') . ' OR a.publish_up <= :publish_up)')
->where('(' . $query->isNullDatetime('a.publish_down') . ' OR a.publish_down >= :publish_down)')
->bind(':published', $published, ParameterType::INTEGER)
->bind(':archived', $archived, ParameterType::INTEGER)
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
Expand Down Expand Up @@ -405,9 +412,9 @@ protected function buildContactExtendedData($contact)
/**
* Generate column expression for slug or catslug.
*
* @param \JDatabaseQuery $query Current query instance.
* @param string $id Column id name.
* @param string $alias Column alias name.
* @param QueryInterface $query Current query instance.
* @param string $id Column id name.
* @param string $alias Column alias name.
*
* @return string
*
Expand Down

0 comments on commit 0fd4c87

Please sign in to comment.