2014-05-03 23:48:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Patch testing component for the Joomla! CMS
|
|
|
|
*
|
2017-01-21 19:54:53 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
|
2014-05-03 23:48:08 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PatchTester\Model;
|
|
|
|
|
|
|
|
use Joomla\Registry\Registry;
|
|
|
|
|
2016-06-25 16:34:48 +00:00
|
|
|
use PatchTester\GitHub\Exception\UnexpectedResponse;
|
2014-05-03 23:48:08 +00:00
|
|
|
use PatchTester\Helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Model class for the pulls list view
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
class PullsModel extends \JModelDatabase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The object context
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected $context;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of fields the list can be sorted on
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2016-02-20 16:34:23 +00:00
|
|
|
protected $sortFields = array('a.pull_id', 'a.title', 'applied');
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate the model.
|
|
|
|
*
|
|
|
|
* @param string $context The model context.
|
|
|
|
* @param Registry $state The model state.
|
|
|
|
* @param \JDatabaseDriver $db The database adpater.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function __construct($context, Registry $state = null, \JDatabaseDriver $db = null)
|
|
|
|
{
|
|
|
|
parent::__construct($state, $db);
|
|
|
|
|
2016-02-20 16:34:23 +00:00
|
|
|
$this->context = $context;
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 16:55:17 +00:00
|
|
|
/**
|
|
|
|
* Method to get an array of branches.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @since __DEPLOY_VERSION__
|
|
|
|
*/
|
|
|
|
public function getBranches()
|
|
|
|
{
|
|
|
|
// Create a new query object.
|
|
|
|
$db = $this->getDb();
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
// Select distinct branches excluding empty values
|
|
|
|
$query->select('DISTINCT(branch) AS text')
|
|
|
|
->from('#__patchtester_pulls')
|
|
|
|
->where($db->quoteName('branch') . ' != ' . $db->quote(''))
|
|
|
|
->order('branch ASC');
|
|
|
|
|
|
|
|
return $db->setQuery($query)->loadAssocList();
|
|
|
|
}
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
/**
|
|
|
|
* Method to get an array of data items.
|
|
|
|
*
|
|
|
|
* @return mixed An array of data items on success, false on failure.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function getItems()
|
|
|
|
{
|
|
|
|
// Get a storage key.
|
|
|
|
$store = $this->getStoreId();
|
|
|
|
|
|
|
|
// Try to load the data from internal storage.
|
|
|
|
if (isset($this->cache[$store]))
|
|
|
|
{
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:36:53 +00:00
|
|
|
// Load the list items and add the items to the internal cache.
|
|
|
|
$this->cache[$store] = $this->_getList($this->_getListQuery(), $this->getStart(), $this->getState()->get('list.limit'));
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
|
|
|
|
*
|
|
|
|
* @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function getListQuery()
|
|
|
|
{
|
|
|
|
// Create a new query object.
|
|
|
|
$db = $this->getDb();
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
// Select the required fields from the table.
|
2016-03-11 16:36:53 +00:00
|
|
|
$query->select('a.*');
|
2016-03-16 04:14:19 +00:00
|
|
|
$query->from('#__patchtester_pulls AS a');
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
// Join the tests table to get applied patches
|
2016-03-11 16:36:53 +00:00
|
|
|
$query->select('t.id AS applied');
|
|
|
|
$query->join('LEFT', '#__patchtester_tests AS t ON t.pull_id = a.pull_id');
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
// Filter by search
|
|
|
|
$search = $this->getState()->get('filter.search');
|
|
|
|
|
|
|
|
if (!empty($search))
|
|
|
|
{
|
2015-12-17 16:39:55 +00:00
|
|
|
if (stripos($search, 'id:') === 0)
|
2015-12-05 17:03:23 +00:00
|
|
|
{
|
2016-03-11 16:36:53 +00:00
|
|
|
$query->where('a.pull_id = ' . (int) substr($search, 3));
|
2015-12-05 17:03:23 +00:00
|
|
|
}
|
2015-12-17 16:39:55 +00:00
|
|
|
elseif (is_numeric($search))
|
|
|
|
{
|
2016-11-06 07:49:39 +00:00
|
|
|
$query->where('a.pull_id = ' . (int) $search);
|
2015-12-17 16:39:55 +00:00
|
|
|
}
|
2015-12-05 17:03:23 +00:00
|
|
|
else
|
|
|
|
{
|
2016-03-11 16:36:53 +00:00
|
|
|
$query->where('(a.title LIKE ' . $db->quote('%' . $db->escape($search, true) . '%') . ')');
|
2015-12-05 17:03:23 +00:00
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 23:44:35 +00:00
|
|
|
// Filter for applied patches
|
|
|
|
$applied = $this->getState()->get('filter.applied');
|
|
|
|
|
|
|
|
if (!empty($applied))
|
|
|
|
{
|
|
|
|
// Not applied patches have a NULL value, so build our value part of the query based on this
|
2015-12-05 17:43:54 +00:00
|
|
|
$value = $applied == 'no' ? ' IS NULL' : ' = 1';
|
2015-02-22 23:44:35 +00:00
|
|
|
|
|
|
|
$query->where($db->quoteName('applied') . $value);
|
|
|
|
}
|
|
|
|
|
2017-04-22 16:55:17 +00:00
|
|
|
// Filter for branch
|
|
|
|
$branch = $this->getState()->get('filter.branch');
|
|
|
|
|
|
|
|
if (!empty($branch))
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName('branch') . ' = ' . $db->quote($branch));
|
|
|
|
}
|
|
|
|
|
2016-03-27 18:39:34 +00:00
|
|
|
// Filter for RTC patches
|
|
|
|
$applied = $this->getState()->get('filter.rtc');
|
|
|
|
|
|
|
|
if (!empty($applied))
|
|
|
|
{
|
|
|
|
// Not applied patches have a NULL value, so build our value part of the query based on this
|
|
|
|
$value = $applied == 'no' ? '0' : '1';
|
|
|
|
|
|
|
|
$query->where($db->quoteName('is_rtc') . ' = ' . $value);
|
|
|
|
}
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
// Handle the list ordering.
|
|
|
|
$ordering = $this->getState()->get('list.ordering');
|
|
|
|
$direction = $this->getState()->get('list.direction');
|
|
|
|
|
|
|
|
if (!empty($ordering))
|
|
|
|
{
|
|
|
|
$query->order($db->escape($ordering) . ' ' . $db->escape($direction));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If $ordering is by applied patches, then append sort on pull_id also
|
|
|
|
if ($ordering === 'applied')
|
|
|
|
{
|
|
|
|
$query->order('a.pull_id ' . $db->escape($direction));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get a JPagination object for the data set.
|
|
|
|
*
|
|
|
|
* @return \JPagination A JPagination object for the data set.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function getPagination()
|
|
|
|
{
|
|
|
|
// Get a storage key.
|
|
|
|
$store = $this->getStoreId('getPagination');
|
|
|
|
|
|
|
|
// Try to load the data from internal storage.
|
|
|
|
if (isset($this->cache[$store]))
|
|
|
|
{
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:36:53 +00:00
|
|
|
// Create the pagination object and add the object to the internal cache.
|
|
|
|
$this->cache[$store] = new \JPagination($this->getTotal(), $this->getStart(), (int) $this->getState()->get('list.limit', 20));
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the array of authorized sort fields
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function getSortFields()
|
|
|
|
{
|
|
|
|
return $this->sortFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get a store id based on the model configuration state.
|
|
|
|
*
|
|
|
|
* This is necessary because the model is used by the component and
|
|
|
|
* different modules that might need different sets of data or different
|
|
|
|
* ordering requirements.
|
|
|
|
*
|
|
|
|
* @param string $id An identifier string to generate the store id.
|
|
|
|
*
|
|
|
|
* @return string A store id.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function getStoreId($id = '')
|
|
|
|
{
|
|
|
|
// Add the list state to the store id.
|
|
|
|
$id .= ':' . $this->getState()->get('list.start');
|
|
|
|
$id .= ':' . $this->getState()->get('list.limit');
|
|
|
|
$id .= ':' . $this->getState()->get('list.ordering');
|
|
|
|
$id .= ':' . $this->getState()->get('list.direction');
|
|
|
|
|
|
|
|
return md5($this->context . ':' . $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get the starting number of items for the data set.
|
|
|
|
*
|
|
|
|
* @return integer The starting number of items available in the data set.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function getStart()
|
|
|
|
{
|
|
|
|
$store = $this->getStoreId('getStart');
|
|
|
|
|
|
|
|
// Try to load the data from internal storage.
|
|
|
|
if (isset($this->cache[$store]))
|
|
|
|
{
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:36:53 +00:00
|
|
|
$start = $this->getState()->get('list.start', 0);
|
|
|
|
$limit = $this->getState()->get('list.limit', 20);
|
2014-05-03 23:48:08 +00:00
|
|
|
$total = $this->getTotal();
|
|
|
|
|
|
|
|
if ($start > $total - $limit)
|
|
|
|
{
|
|
|
|
$start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the total to the internal cache.
|
|
|
|
$this->cache[$store] = $start;
|
|
|
|
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get the total number of items for the data set.
|
|
|
|
*
|
|
|
|
* @return integer The total number of items available in the data set.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function getTotal()
|
|
|
|
{
|
|
|
|
// Get a storage key.
|
|
|
|
$store = $this->getStoreId('getTotal');
|
|
|
|
|
|
|
|
// Try to load the data from internal storage.
|
|
|
|
if (isset($this->cache[$store]))
|
|
|
|
{
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:36:53 +00:00
|
|
|
// Load the total and add the total to the internal cache.
|
|
|
|
$this->cache[$store] = (int) $this->_getListCount($this->_getListQuery());
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to request new data from GitHub
|
|
|
|
*
|
2015-02-23 01:49:59 +00:00
|
|
|
* @param integer $page The page of the request
|
|
|
|
*
|
|
|
|
* @return array
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @throws \RuntimeException
|
|
|
|
*/
|
2015-02-23 01:49:59 +00:00
|
|
|
public function requestFromGithub($page)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
// If on page 1, dump the old data
|
|
|
|
if ($page === 1)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
$this->getDb()->truncateTable('#__patchtester_pulls');
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2015-02-23 01:49:59 +00:00
|
|
|
try
|
2015-02-22 22:59:02 +00:00
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
// TODO - Option to configure the batch size
|
2016-06-25 16:54:03 +00:00
|
|
|
$batchSize = 100;
|
|
|
|
|
2016-06-25 16:34:48 +00:00
|
|
|
$pullsResponse = Helper::initializeGithub()->getOpenIssues(
|
2016-06-25 16:54:03 +00:00
|
|
|
$this->getState()->get('github_user'), $this->getState()->get('github_repo'), $page, $batchSize
|
2015-02-23 01:49:59 +00:00
|
|
|
);
|
2016-06-25 16:34:48 +00:00
|
|
|
|
|
|
|
$pulls = json_decode($pullsResponse->body);
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
2016-06-25 16:34:48 +00:00
|
|
|
catch (UnexpectedResponse $e)
|
2015-02-22 22:59:02 +00:00
|
|
|
{
|
2015-06-16 19:14:41 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_GITHUB_FETCH', $e->getMessage()), $e->getCode(), $e);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
2015-02-22 22:59:02 +00:00
|
|
|
|
2016-06-25 16:54:03 +00:00
|
|
|
// If this is page 1, let's check to see if we need to paginate
|
|
|
|
if ($page === 1)
|
|
|
|
{
|
|
|
|
// Default this to being a single page of results
|
|
|
|
$lastPage = 1;
|
|
|
|
|
|
|
|
if (isset($pullsResponse->headers['Link']))
|
|
|
|
{
|
2017-04-22 17:09:19 +00:00
|
|
|
$linkHeader = $pullsResponse->headers['Link'];
|
|
|
|
|
|
|
|
// The `joomla/http` 2.0 package uses PSR-7 Responses which has a different format for headers, check for this
|
|
|
|
if (is_array($linkHeader))
|
|
|
|
{
|
|
|
|
$linkHeader = $linkHeader[0];
|
|
|
|
}
|
|
|
|
|
2017-05-05 00:45:13 +00:00
|
|
|
preg_match('/(\?page=[0-9]{1,3}&per_page=' . $batchSize . '+>; rel=\"last\")/', $linkHeader, $matches);
|
2016-06-25 16:54:03 +00:00
|
|
|
|
|
|
|
if ($matches && isset($matches[0]))
|
|
|
|
{
|
|
|
|
$pageSegment = str_replace('&per_page=' . $batchSize, '', $matches[0]);
|
|
|
|
|
|
|
|
preg_match('/\d+/', $pageSegment, $pages);
|
|
|
|
$lastPage = (int) $pages[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 01:49:59 +00:00
|
|
|
// If there are no pulls to insert then bail, assume we're finished
|
2016-06-25 17:57:24 +00:00
|
|
|
if (count($pulls) === 0)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
return array('complete' => true);
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
foreach ($pulls as $pull)
|
|
|
|
{
|
2016-03-26 22:42:18 +00:00
|
|
|
if (isset($pull->pull_request))
|
|
|
|
{
|
2017-04-22 16:28:43 +00:00
|
|
|
// Check if this PR is RTC and has a `PR-` branch label
|
|
|
|
$isRTC = false;
|
|
|
|
$branch = '';
|
2016-03-27 18:39:34 +00:00
|
|
|
|
|
|
|
foreach ($pull->labels as $label)
|
|
|
|
{
|
|
|
|
if ($label->name === 'RTC')
|
|
|
|
{
|
|
|
|
$isRTC = true;
|
2017-04-22 16:28:43 +00:00
|
|
|
}
|
|
|
|
elseif (substr($label->name, 0, 3) === 'PR-')
|
|
|
|
{
|
|
|
|
$branch = substr($label->name, 3);
|
2016-03-27 18:39:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 22:42:18 +00:00
|
|
|
// Build the data object to store in the database
|
|
|
|
$pullData = array(
|
|
|
|
(int) $pull->number,
|
|
|
|
$this->getDb()->quote(\JHtml::_('string.truncate', $pull->title, 150)),
|
|
|
|
$this->getDb()->quote(\JHtml::_('string.truncate', $pull->body, 100)),
|
2016-04-05 10:03:23 +00:00
|
|
|
$this->getDb()->quote($pull->pull_request->html_url),
|
2016-03-27 18:39:34 +00:00
|
|
|
(int) $isRTC,
|
2017-04-22 16:28:43 +00:00
|
|
|
$this->getDb()->quote($branch),
|
2016-03-26 22:42:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$data[] = implode($pullData, ',');
|
|
|
|
}
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 17:57:24 +00:00
|
|
|
// If there are no pulls to insert then bail, assume we're finished
|
|
|
|
if (count($data) === 0)
|
|
|
|
{
|
|
|
|
return array('complete' => true);
|
|
|
|
}
|
|
|
|
|
2015-02-22 22:59:02 +00:00
|
|
|
$this->getDb()->setQuery(
|
2015-05-23 14:57:30 +00:00
|
|
|
$this->getDb()->getQuery(true)
|
2016-03-11 16:36:53 +00:00
|
|
|
->insert('#__patchtester_pulls')
|
2017-04-22 16:28:43 +00:00
|
|
|
->columns(array('pull_id', 'title', 'description', 'pull_url', 'is_rtc', 'branch'))
|
2015-02-22 22:59:02 +00:00
|
|
|
->values($data)
|
|
|
|
);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->getDb()->execute();
|
|
|
|
}
|
|
|
|
catch (\RuntimeException $e)
|
|
|
|
{
|
2015-06-16 19:14:41 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_INSERT_DATABASE', $e->getMessage()), $e->getCode(), $e);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
2015-02-23 01:49:59 +00:00
|
|
|
|
|
|
|
// Need to make another request
|
2016-06-25 16:54:03 +00:00
|
|
|
return array('complete' => false, 'page' => ($page + 1), 'lastPage' => isset($lastPage) ? $lastPage : false);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 22:08:01 +00:00
|
|
|
/**
|
|
|
|
* Truncates the pulls table
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function truncateTable()
|
|
|
|
{
|
|
|
|
$this->getDb()->truncateTable('#__patchtester_pulls');
|
|
|
|
}
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
/**
|
|
|
|
* Gets an array of objects from the results of database query.
|
|
|
|
*
|
|
|
|
* @param \JDatabaseQuery|string $query The query.
|
|
|
|
* @param integer $limitstart Offset.
|
|
|
|
* @param integer $limit The number of records.
|
|
|
|
*
|
|
|
|
* @return array An array of results.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @throws RuntimeException
|
|
|
|
*/
|
|
|
|
protected function _getList($query, $limitstart = 0, $limit = 0)
|
|
|
|
{
|
2016-03-11 16:36:53 +00:00
|
|
|
return $this->getDb()->setQuery($query, $limitstart, $limit)->loadObjectList();
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a record count for the query.
|
|
|
|
*
|
|
|
|
* @param \JDatabaseQuery|string $query The query.
|
|
|
|
*
|
|
|
|
* @return integer Number of rows for query.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function _getListCount($query)
|
|
|
|
{
|
|
|
|
// Use fast COUNT(*) on JDatabaseQuery objects if there no GROUP BY or HAVING clause:
|
|
|
|
if ($query instanceof \JDatabaseQuery && $query->type == 'select' && $query->group === null && $query->having === null)
|
|
|
|
{
|
|
|
|
$query = clone $query;
|
|
|
|
$query->clear('select')->clear('order')->select('COUNT(*)');
|
|
|
|
|
|
|
|
$this->getDb()->setQuery($query);
|
|
|
|
|
|
|
|
return (int) $this->getDb()->loadResult();
|
|
|
|
}
|
2015-02-23 00:07:05 +00:00
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
// Otherwise fall back to inefficient way of counting all results.
|
2015-02-23 00:07:05 +00:00
|
|
|
$this->getDb()->setQuery($query)->execute();
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2015-02-23 00:07:05 +00:00
|
|
|
return (int) $this->getDb()->getNumRows();
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to cache the last query constructed.
|
|
|
|
*
|
|
|
|
* This method ensures that the query is constructed only once for a given state of the model.
|
|
|
|
*
|
|
|
|
* @return \JDatabaseQuery A JDatabaseQuery object
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function _getListQuery()
|
|
|
|
{
|
|
|
|
// Capture the last store id used.
|
|
|
|
static $lastStoreId;
|
|
|
|
|
|
|
|
// Compute the current store id.
|
|
|
|
$currentStoreId = $this->getStoreId();
|
|
|
|
|
|
|
|
// If the last store id is different from the current, refresh the query.
|
|
|
|
if ($lastStoreId != $currentStoreId || empty($this->query))
|
|
|
|
{
|
|
|
|
$lastStoreId = $currentStoreId;
|
|
|
|
$this->query = $this->getListQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->query;
|
|
|
|
}
|
|
|
|
}
|