2011-10-11 13:02:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-06-12 18:42:45 +00:00
|
|
|
* @package PatchTester
|
|
|
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
jimport('joomla.application.component.modellist');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Methods supporting a list of pull request.
|
|
|
|
*
|
2012-06-12 18:42:45 +00:00
|
|
|
* @package PatchTester
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
|
|
|
class PatchtesterModelPulls extends JModelList
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2012-06-12 18:42:45 +00:00
|
|
|
* @param array $config An optional associative array of configuration settings.
|
|
|
|
*
|
|
|
|
* @see JController
|
|
|
|
* @since 11.1
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
|
|
|
public function __construct($config = array())
|
|
|
|
{
|
2012-06-12 18:42:45 +00:00
|
|
|
if (empty($config['filter_fields']))
|
|
|
|
{
|
2011-10-11 13:02:57 +00:00
|
|
|
$config['filter_fields'] = array(
|
|
|
|
'id', 'id',
|
|
|
|
'title', 'title',
|
|
|
|
'updated_at', 'updated_at',
|
|
|
|
'user', 'user'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to auto-populate the model state.
|
|
|
|
*
|
|
|
|
* Note. Calling getState in this method will result in recursion.
|
|
|
|
*
|
2012-06-12 18:42:45 +00:00
|
|
|
* @since 1.6
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
|
|
|
protected function populateState($ordering = null, $direction = null)
|
|
|
|
{
|
2011-10-13 17:58:22 +00:00
|
|
|
// Load the filter state.
|
2012-06-12 18:42:45 +00:00
|
|
|
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
2011-10-13 17:58:22 +00:00
|
|
|
$this->setState('filter.search', $search);
|
|
|
|
|
2012-06-12 18:42:45 +00:00
|
|
|
$searchId = $this->getUserStateFromRequest($this->context . '.filter.searchid', 'filter_searchid');
|
2011-10-15 07:10:25 +00:00
|
|
|
$this->setState('filter.searchid', $searchId);
|
|
|
|
|
2011-10-11 13:02:57 +00:00
|
|
|
// Load the parameters.
|
|
|
|
$params = JComponentHelper::getParams('com_patchtester');
|
2011-10-13 17:58:22 +00:00
|
|
|
|
2011-10-11 13:02:57 +00:00
|
|
|
$this->setState('params', $params);
|
2011-10-13 02:13:19 +00:00
|
|
|
$this->setState('github_user', $params->get('org', 'joomla'));
|
|
|
|
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
|
2011-10-13 17:58:22 +00:00
|
|
|
|
2011-10-11 13:02:57 +00:00
|
|
|
// List state information.
|
2011-10-13 17:58:22 +00:00
|
|
|
parent::populateState('number', 'desc');
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get a store id based on 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.
|
|
|
|
*
|
2012-06-12 18:42:45 +00:00
|
|
|
* @param string $id A prefix for the store id.
|
|
|
|
*
|
|
|
|
* @return string A store id.
|
|
|
|
* @since 1.6
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
|
|
|
protected function getStoreId($id = '')
|
|
|
|
{
|
|
|
|
return parent::getStoreId($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAppliedPatches()
|
|
|
|
{
|
|
|
|
$query = $this->_db->getQuery(true);
|
|
|
|
$query->select('*');
|
2012-06-12 18:42:45 +00:00
|
|
|
$query->from('#__patchtester_tests');
|
2011-10-11 13:02:57 +00:00
|
|
|
$query->where('applied = 1');
|
2011-10-13 17:58:22 +00:00
|
|
|
|
2011-10-11 13:02:57 +00:00
|
|
|
$this->_db->setQuery($query);
|
|
|
|
$tests = $this->_db->loadObjectList('pull_id');
|
|
|
|
return $tests;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getItems()
|
|
|
|
{
|
|
|
|
jimport('joomla.client.github');
|
|
|
|
|
2012-06-12 18:42:45 +00:00
|
|
|
if ($this->getState('github_user') == '' || $this->getState('github_repo') == '')
|
|
|
|
{
|
2011-10-11 13:02:57 +00:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2011-10-13 17:58:22 +00:00
|
|
|
$this->ordering = $this->getState('list.ordering', 'title');
|
|
|
|
$this->orderDir = $this->getState('list.direction', 'asc');
|
|
|
|
$search = $this->getState('filter.search');
|
2011-10-15 07:10:25 +00:00
|
|
|
$searchId = $this->getState('filter.searchid');
|
2011-10-13 17:58:22 +00:00
|
|
|
|
2012-06-12 18:42:45 +00:00
|
|
|
try
|
|
|
|
{
|
2011-10-15 01:13:59 +00:00
|
|
|
$github = new JGithub();
|
2012-06-12 18:42:45 +00:00
|
|
|
$pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'));
|
2011-10-15 01:13:59 +00:00
|
|
|
usort($pulls, array($this, 'sortItems'));
|
|
|
|
|
2012-06-12 18:42:45 +00:00
|
|
|
foreach ($pulls as $i => &$pull)
|
2011-10-15 01:13:59 +00:00
|
|
|
{
|
2012-06-12 18:42:45 +00:00
|
|
|
if ($search && false === strpos($pull->title, $search))
|
|
|
|
{
|
2011-10-15 01:13:59 +00:00
|
|
|
unset($pulls[$i]);
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-12 18:42:45 +00:00
|
|
|
|
|
|
|
if ($searchId && $pull->number != $searchId)
|
|
|
|
{
|
2011-10-27 20:23:10 +00:00
|
|
|
unset($pulls[$i]);
|
|
|
|
continue;
|
2011-10-27 19:50:18 +00:00
|
|
|
}
|
2012-06-12 18:42:45 +00:00
|
|
|
|
|
|
|
// Try to find a joomlacode issue number
|
|
|
|
$pulls[$i]->joomlacode_issue = 0;
|
|
|
|
|
2011-10-15 01:13:59 +00:00
|
|
|
$matches = array();
|
2012-06-12 18:42:45 +00:00
|
|
|
|
2011-10-15 01:13:59 +00:00
|
|
|
preg_match('#\[\#([0-9]+)\]#', $pull->title, $matches);
|
2012-06-12 18:42:45 +00:00
|
|
|
|
|
|
|
if (isset($matches[1]))
|
|
|
|
{
|
|
|
|
$pulls[$i]->joomlacode_issue = (int) $matches[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preg_match('#(http://joomlacode[-\w\./\?\S]+)#', $pull->body, $matches);
|
|
|
|
|
|
|
|
if (isset($matches[1]))
|
|
|
|
{
|
|
|
|
preg_match('#tracker_item_id=([0-9]+)#', $matches[1], $matches);
|
|
|
|
|
|
|
|
if (isset($matches[1]))
|
|
|
|
{
|
|
|
|
$pulls[$i]->joomlacode_issue = (int) $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-13 17:58:22 +00:00
|
|
|
}
|
2011-10-15 01:13:59 +00:00
|
|
|
|
|
|
|
return $pulls;
|
2012-06-12 18:42:45 +00:00
|
|
|
}
|
|
|
|
catch (Exception $e)
|
|
|
|
{
|
2011-10-15 18:13:31 +00:00
|
|
|
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
2011-10-15 01:13:59 +00:00
|
|
|
|
|
|
|
return array();
|
2011-10-13 02:13:19 +00:00
|
|
|
}
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function sortItems($a, $b)
|
|
|
|
{
|
2011-10-13 17:58:22 +00:00
|
|
|
switch ($this->ordering)
|
|
|
|
{
|
|
|
|
case 'title' :
|
|
|
|
return ($this->orderDir == 'asc') ? strcasecmp($a->title, $b->title) : strcasecmp($b->title, $a->title);
|
|
|
|
|
|
|
|
case 'number' :
|
|
|
|
default :
|
2012-06-12 18:42:45 +00:00
|
|
|
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
|
2011-10-13 17:58:22 +00:00
|
|
|
}
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
|
|
|
}
|