31
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-09-27 12:09:01 +00:00

Reformat to Joomla CS

This commit is contained in:
Michael Babker 2013-07-12 21:26:21 -05:00
parent 8ff29492fe
commit b8170b3993
14 changed files with 494 additions and 361 deletions

View File

@ -1,35 +1,26 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// No direct access
defined('_JEXEC') or die;
/**
* PatchTester Controller
*
* @package PatchTester
* @since 1.0
*/
class PatchTesterController extends JControllerLegacy
{
protected $default_view = 'Pulls';
/**
* Method to display a view.
* The default view for the display method.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @since 1.5
* @var string
* @since 1.0
*/
public function display($cachable = false, $urlparams = false)
{
parent::display();
return $this;
}
protected $default_view = 'pulls';
}

View File

@ -1,56 +1,68 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// No direct access
defined('_JEXEC') or die;
/**
* Pull controller class
*
* @package PatchTester
* @package PatchTester
* @since 1.0
*/
class PatchtesterControllerPull extends JControllerLegacy
{
/**
* Method to apply a patch
*
* @return void
*
* @since 1.0
*/
public function apply()
{
try
{
$this->getModel('pull')
->apply(JFactory::getApplication()->input->getInt('pull_id'));
$this->getModel('pull')->apply(JFactory::getApplication()->input->getInt('pull_id'));
$msg = JText::_('COM_PATCHTESTER_APPLY_OK');
$msg = JText::_('COM_PATCHTESTER_APPLY_OK');
$type = 'message';
}
catch (Exception $e)
{
$msg = $e->getMessage();
$msg = $e->getMessage();
$type = 'error';
}
$this->setRedirect(JRoute::_('index.php?option=com_patchtester&view=pulls', false), $msg, $type);
}
/**
* Method to revert a patch
*
* @return void
*
* @since 1.0
*/
public function revert()
{
try
{
$this->getModel('pull')
->revert(JFactory::getApplication()->input->getInt('pull_id'));
$this->getModel('pull')->revert(JFactory::getApplication()->input->getInt('pull_id'));
$msg = JText::_('COM_PATCHTESTER_REVERT_OK');
$msg = JText::_('COM_PATCHTESTER_REVERT_OK');
$type = 'message';
}
catch (Exception $e)
{
$msg = $e->getMessage();
$msg = $e->getMessage();
$type = 'error';
}
$this->setRedirect(JRoute::_('index.php?option=com_patchtester&view=pulls', false), $msg, $type);
}
}

View File

@ -1,30 +1,50 @@
<?php
/**
* User: elkuku
* Date: 08.09.12
* Time: 19:08
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
/**
* Extended JGithub class allowing additional JGithubObject instances to be used
*
* @property-read PTGithubRepos $repos GitHub API object for repos.
*
* @package PatchTester
* @since 2.0
*/
class PTGithub extends JGithub
{
/**
* @var PTGithubRepos
*/
protected $repos;
/**
* @var PTGithubRepos
* @since 2.0
*/
protected $repos;
public function __get($name)
{
if ($name == 'repos')
{
if ($this->repos == null)
{
$this->repos = new PTGithubRepos($this->options, $this->client);
}
/**
* Magic method to lazily create API objects
*
* @param string $name Name of property to retrieve
*
* @return JGithubObject GitHub API object (gists, issues, pulls, etc).
*
* @since 2.0
*/
public function __get($name)
{
if ($name == 'repos')
{
if ($this->repos == null)
{
$this->repos = new PTGithubRepos($this->options, $this->client);
}
return $this->repos;
}
return $this->repos;
}
return parent::__get($name);
}
return parent::__get($name);
}
}

View File

@ -1,58 +1,53 @@
<?php
/**
* User: elkuku
* Date: 08.09.12
* Time: 18:54
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
/**
* A.
* GitHub API Repos class.
*
* @package PatchTester
* @since 2.0
*/
class PTGithubRepos extends JGithubObject
{
public function get($user, $repo)
{
$path = '/repos/'.$user.'/'.$repo;
/**
* Retrieve information about the specified repository
*
* @param string $user The username or organization name of the repository owner
* @param string $repo The repository to retrieve
*
* @return object
*
* @since 2.0
* @throws DomainException
*/
public function get($user, $repo)
{
$path = '/repos/' . $user . '/' . $repo;
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
// Validate the response code.
if($response->code != 200)
{
// Decode the error response and throw an exception.
$error = json_decode($response->body);
/**
* List public repositories for the specified user.
*
* @param string $user The username to retrieve repositories for
*
* @return object
*
* @since 2.0
* @throws DomainException
*/
public function getPublicRepos($user)
{
$path = '/users/' . $user . '/repos';
throw new DomainException($error->message, $response->code);
}
return json_decode($response->body);
}
/**
* @param string $user
* @param string $type all, owner, public, private, member. Default: all.
* @param string $sort created, updated, pushed, full_name, default: full_name.
* @param string $direction asc or desc, default: when using full_name: asc, otherwise desc.
*
* @return mixed
* @throws DomainException
*/
public function getPublicRepos($user, $type = 'all', $sort = 'full_name', $direction = 'desc')
{
$path = '/users/'.$user.'/repos';
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
// Validate the response code.
if($response->code != 200)
{
// Decode the error response and throw an exception.
$error = json_decode($response->body);
throw new DomainException($error->message, $response->code);
}
return json_decode($response->body);
}
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
}

View File

@ -1,36 +1,38 @@
COM_PATCHTESTER="Patch Tester"
COM_PATCHTESTER_CONFIGURATION="Patch Tester Settings"
COM_PATCHTESTER_NOT_APPLIED="Not Applied"
; Joomla! Project
; Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
; License GNU General Public License version 2 or later
; Note : All ini files need to be saved as UTF-8
COM_PATCHTESTER="Joomla! Patch Tester"
COM_PATCHTESTER_API_LIMIT_ACTION="The GitHub API rate limit has been reached for this resource, could not connect to GitHub to perform the requested action. The rate limit will reset at %s"
COM_PATCHTESTER_API_LIMIT_LIST="The GitHub API rate limit has been reached for this resource, could not connect to GitHub for updated data. The rate limit will reset at %s"
COM_PATCHTESTER_APPLIED="Applied"
COM_PATCHTESTER_REVERT_PATCH="Revert Patch"
COM_PATCHTESTER_APPLY_OK="Patch successfully applied"
COM_PATCHTESTER_APPLY_PATCH="Apply Patch"
COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch"
COM_PATCHTESTER_COMPONENT_LABEL="Patch Tester"
COM_PATCHTESTER_COMPONENT_DESC="Patch Tester Configuration Values"
COM_PATCHTESTER_COMPONENT_DESC="Joomla! Patch Tester Configuration Values"
COM_PATCHTESTER_COMPONENT_LABEL="Joomla! Patch Tester"
COM_PATCHTESTER_CONFIGURATION="Joomla! Patch Tester Settings"
COM_PATCHTESTER_CONFLICT_S="The patch could not be applied because it conflicts with a previously applied patch: %s"
COM_PATCHTESTER_FIELD_GH_PASSWORD_LABEL="GitHub Account Password"
COM_PATCHTESTER_FIELD_GH_PASSWORD_DESC="Password for the account entered in the "_QQ_"GitHub Account"_QQ_" field"
COM_PATCHTESTER_FIELD_GH_USER_LABEL="GitHub Account"
COM_PATCHTESTER_FIELD_GH_USER_DESC="Name of account on GitHub of which to authenticate to the API with"
COM_PATCHTESTER_FIELD_ORG_LABEL="GitHub Username"
COM_PATCHTESTER_FIELD_ORG_DESC="Name of account on GitHub of which to monitor pull requests"
COM_PATCHTESTER_FIELD_REPO_LABEL="GitHub Repository"
COM_PATCHTESTER_FIELD_REPO_DESC="Name of repository on GitHub of which to monitor pull requests"
COM_PATCHTESTER_FIELD_GH_USER_LABEL="GitHub Account"
COM_PATCHTESTER_FIELD_GH_USER_DESC="Name of account on GitHub of which to authenticate to the API with"
COM_PATCHTESTER_FIELD_GH_PASSWORD_LABEL="GitHub Account Password"
COM_PATCHTESTER_FIELD_GH_PASSWORD_DESC="Password for the account entered in the "_QQ_"GitHub Account"_QQ_" field"
COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S="The file marked for deletion does not exist: %s"
COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="The file marked for modification does not exist: %s"
COM_PATCHTESTER_JOOMLACODE_ISSUE="Joomlacode Issue"
COM_PATCHTESTER_PULL_ID="Pull ID"
COM_PATCHTESTER_NO_CREDENTIALS="No user credentials are saved, this will allow only 60 requests to the GitHub API per hour. Saving user credentials will allow 5,000 requests per hour."
COM_PATCHTESTER_NOT_APPLIED="Not Applied"
COM_PATCHTESTER_OPEN_IN_GITHUB="Open in GitHub"
COM_PATCHTESTER_OPEN_IN_JOOMLACODE="Open in JoomlaCode"
COM_PATCHTESTER_REPO_IS_GONE="The patch could not be applied because the repository is missing"
COM_PATCHTESTER_REVERT_OK="Patch successfully reverted"
COM_PATCHTESTER_REVERT_PATCH="Revert Patch"
COM_PATCHTESTER_SEARCH_IN_PULL_ID="Pull ID"
COM_PATCHTESTER_SEARCH_IN_TITLE="Pull title"
COM_PATCHTESTER_SORT="Sort:"
;messages
COM_PATCHTESTER_REPO_IS_GONE="The patch could not be applied because the repository is missing"
COM_PATCHTESTER_CONFLICT_S="The patch could not be applied because it conflicts with a previously applied patch: %s"
COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S="The file marked for deletion does not exist: %s"
COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="The file marked for modification does not exist: %s"
COM_PATCHTESTER_API_LIMIT_ACTION="The GitHub API rate limit has been reached for this resource, could not connect to GitHub to perform the requested action. The rate limit will reset at %s"
COM_PATCHTESTER_API_LIMIT_LIST="The GitHub API rate limit has been reached for this resource, could not connect to GitHub for updated data. The rate limit will reset at %s"
COM_PATCHTESTER_NO_CREDENTIALS="No user credentials are saved, this will allow only 60 requests to the GitHub API per hour. Saving user credentials will allow 5,000 requests per hour."
COM_PATCHTESTER_OPEN_IN_GITHUB="Open in GitHub"
COM_PATCHTESTER_OPEN_IN_JOOMLACODE="Open in JoomlaCode"
COM_PATCHTESTER_APPLY_OK="Patch successfully applied"
COM_PATCHTESTER_REVERT_OK="Patch successfully reverted"
COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch"

View File

@ -1,3 +1,8 @@
COM_PATCHTESTER="Patch Tester"
; Joomla! Project
; Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
; License GNU General Public License version 2 or later
; Note : All ini files need to be saved as UTF-8
COM_PATCHTESTER="Joomla! Patch Tester"
COM_PATCHTESTER_XML_DESCRIPTION="Component for pull request management testing"

View File

@ -1,8 +1,9 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
@ -10,26 +11,30 @@ defined('_JEXEC') or die;
/**
* Methods supporting pull requests.
*
* @package PatchTester
* @package PatchTester
* @since 1.0
*/
class PatchtesterModelPull extends JModelLegacy
{
/**
* @var JHttp
* @var JHttp
* @since 2.0
*/
protected $transport;
/**
* Github object
*
* @var PTGithub
* @var PTGithub
* @since 2.0
*/
protected $github;
/**
* Object containing the rate limit data
*
* @var object
* @var object
* @since 2.0
*/
protected $rate;
@ -38,8 +43,7 @@ class PatchtesterModelPull extends JModelLegacy
*
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
*
* @since 12.2
* @throws Exception
* @since 2.0
*/
public function __construct($config = array())
{
@ -73,9 +77,10 @@ class PatchtesterModelPull extends JModelLegacy
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
* @return void
*
* @since 1.6
* @note Calling getState() in this method will result in recursion.
* @since 1.0
*/
protected function populateState()
{
@ -88,6 +93,15 @@ class PatchtesterModelPull extends JModelLegacy
parent::populateState();
}
/**
* Method to parse a patch and extract the affected files
*
* @param string $patch Patch file to parse
*
* @return array Array of files within a patch
*
* @since 1.0
*/
protected function parsePatch($patch)
{
$state = 0;
@ -104,8 +118,10 @@ class PatchtesterModelPull extends JModelLegacy
{
$state = 1;
}
$file = new stdClass;
$file = new stdClass;
$file->action = 'modified';
break;
case 1:
@ -136,15 +152,27 @@ class PatchtesterModelPull extends JModelLegacy
if (strpos($line, '@@') === 0)
{
$state = 0;
$state = 0;
$files[] = $file;
}
break;
}
}
return $files;
}
/**
* Patches the code with the supplied pull request
*
* @param integer $id ID of the pull request to apply
*
* @return boolean
*
* @since 1.0
* @throws Exception
*/
public function apply($id)
{
// Only act if there are API hits remaining
@ -181,8 +209,7 @@ class PatchtesterModelPull extends JModelLegacy
throw new Exception(sprintf(JText::_('COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S'), $file->old));
}
$url = 'https://raw.github.com/' . $pull->head->user->login . '/' . $pull->head->repo->name . '/' .
$pull->head->ref . '/' . $file->new;
$url = 'https://raw.github.com/' . $pull->head->user->login . '/' . $pull->head->repo->name . '/' . $pull->head->ref . '/' . $file->new;
$file->body = $this->transport->get($url)->body;
}
@ -198,8 +225,9 @@ class PatchtesterModelPull extends JModelLegacy
{
if (!JFile::copy(JPath::clean(JPATH_ROOT . '/' . $file->old), JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'))
{
throw new Exception(sprintf('Can not copy file %s to %s'
, JPATH_ROOT . '/' . $file->old, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'));
throw new Exception(
sprintf('Can not copy file %s to %s', JPATH_ROOT . '/' . $file->old, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt')
);
}
}
@ -211,6 +239,7 @@ class PatchtesterModelPull extends JModelLegacy
{
throw new Exception(sprintf('Can not write the file: %s', JPATH_ROOT . '/' . $file->new));
}
break;
case 'deleted':
@ -218,15 +247,16 @@ class PatchtesterModelPull extends JModelLegacy
{
throw new Exception(sprintf('Can not delete the file: %s', JPATH_ROOT . '/' . $file->old));
}
break;
}
}
$table = JTable::getInstance('tests', 'PatchTesterTable');
$table->pull_id = $pull->number;
$table->data = json_encode($files);
$table->patched_by = JFactory::getUser()->id;
$table->applied = 1;
$table = JTable::getInstance('tests', 'PatchTesterTable');
$table->pull_id = $pull->number;
$table->data = json_encode($files);
$table->patched_by = JFactory::getUser()->id;
$table->applied = 1;
$table->applied_version = JVERSION;
if (!$table->store())
@ -242,6 +272,16 @@ class PatchtesterModelPull extends JModelLegacy
return true;
}
/**
* Reverts the specified pull request
*
* @param integer $id ID of the pull request to Reverts
*
* @return boolean
*
* @since 1.0
* @throws Exception
*/
public function revert($id)
{
$table = JTable::getInstance('tests', 'PatchTesterTable');
@ -259,8 +299,7 @@ class PatchtesterModelPull extends JModelLegacy
if (!$files)
{
throw new Exception(sprintf(JText::_('%s - Error retrieving table data (%s)')
, __METHOD__, htmlentities($table->data)));
throw new Exception(sprintf(JText::_('%s - Error retrieving table data (%s)'), __METHOD__, htmlentities($table->data)));
}
jimport('joomla.filesystem.file');
@ -271,32 +310,30 @@ class PatchtesterModelPull extends JModelLegacy
{
case 'deleted':
case 'modified':
if (!JFile::copy(
JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'
, JPATH_ROOT . '/' . $file->old)
)
if (!JFile::copy(JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt', JPATH_ROOT . '/' . $file->old))
{
throw new Exception(sprintf(
JText::_('Can not copy file %s to %s')
, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'
, JPATH_ROOT . '/' . $file->old));
throw new Exception(
sprintf(
JText::_('Can not copy file %s to %s'),
JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt',
JPATH_ROOT . '/' . $file->old
)
);
}
if (!JFile::delete(JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'))
{
throw new Exception(sprintf(
JText::_('Can not delete the file: %s')
, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'));
throw new Exception(sprintf(JText::_('Can not delete the file: %s'), JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'));
}
break;
case 'added':
if (!JFile::delete(JPath::clean(JPATH_ROOT . '/' . $file->new)))
{
throw new Exception(sprintf(
JText::_('Can not delete the file: %s')
, JPATH_ROOT . '/' . $file->new));
throw new Exception(sprintf(JText::_('Can not delete the file: %s'), JPATH_ROOT . '/' . $file->new));
}
break;
}
}
@ -305,5 +342,4 @@ class PatchtesterModelPull extends JModelLegacy
return true;
}
}

View File

@ -1,32 +1,34 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
* Methods supporting a list of pull request.
* Methods supporting a list of pull requests.
*
* @package PatchTester
* @package PatchTester
* @since 1.0
*/
class PatchtesterModelPulls extends JModelList
{
/**
* Github object
*
* @var PTGithub
* @var PTGithub
* @since 2.0
*/
protected $github;
/**
* Object containing the rate limit data
*
* @var object
* @var object
* @since 2.0
*/
protected $rate;
@ -36,7 +38,7 @@ class PatchtesterModelPulls extends JModelList
* @param array $config An optional associative array of configuration settings.
*
* @see JController
* @since 11.1
* @since 1.0
*/
public function __construct($config = array())
{
@ -81,13 +83,16 @@ class PatchtesterModelPulls extends JModelList
}
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @since 1.6
* @return void
*
* @note Calling getState() in this method will result in recursion.
* @since 1.0
*/
protected function populateState($ordering = null, $direction = null)
{
@ -98,32 +103,58 @@ class PatchtesterModelPulls extends JModelList
$searchId = $this->getUserStateFromRequest($this->context . '.filter.searchid', 'filter_searchid');
$this->setState('filter.searchid', $searchId);
// Load the parameters.
$params = JComponentHelper::getParams('com_patchtester');
// Load the parameters.
$params = JComponentHelper::getParams('com_patchtester');
$this->setState('params', $params);
$this->setState('github_user', $params->get('org', 'joomla'));
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
$this->setState('params', $params);
$this->setState('github_user', $params->get('org', 'joomla'));
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
// List state information.
parent::populateState('number', 'desc');
// List state information.
parent::populateState('number', 'desc');
// GitHub's default list limit is 30
$this->setState('list.limit', 30);
// GitHub's default list limit is 30
$this->setState('list.limit', 30);
}
/**
* Retrieves a list of applied patches
*
* @return mixed
*
* @since 1.0
*/
public function getAppliedPatches()
{
$query = $this->_db->getQuery(true);
$query->select('*');
$query->from('#__patchtester_tests');
$query->where('applied = 1');
$db = $this->getDbo();
$query = $db->getQuery(true)
->select('*')
->from('#__patchtester_tests')
->where('applied = 1');
$this->_db->setQuery($query);
$tests = $this->_db->loadObjectList('pull_id');
return $tests;
$db->setQuery($query);
try
{
$tests = $db->loadObjectList('pull_id');
return $tests;
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
}
/**
* Method to get an array of data items.
*
* @return mixed An array of data items on success, false on failure.
*
* @since 1.0
*/
public function getItems()
{
if ($this->getState('github_user') == '' || $this->getState('github_repo') == '')
@ -133,10 +164,10 @@ class PatchtesterModelPulls extends JModelList
$this->ordering = $this->getState('list.ordering', 'title');
$this->orderDir = $this->getState('list.direction', 'asc');
$search = $this->getState('filter.search');
$searchId = $this->getState('filter.searchid');
$search = $this->getState('filter.search');
$searchId = $this->getState('filter.searchid');
$page = $this->getPagination()->pagesCurrent;
$page = $this->getPagination()->pagesCurrent;
try
{
@ -161,7 +192,7 @@ class PatchtesterModelPulls extends JModelList
continue;
}
// Try to find a joomlacode issue number
// Try to find a Joomlacode issue number
$pulls[$i]->joomlacode_issue = 0;
$matches = array();
@ -203,6 +234,16 @@ class PatchtesterModelPulls extends JModelList
}
}
/**
* Method to sort the items array
*
* @param object $a First sort object
* @param object $b Second sort object
*
* @return mixed
*
* @since 1.0
*/
public function sortItems($a, $b)
{
switch ($this->ordering)
@ -216,15 +257,22 @@ class PatchtesterModelPulls extends JModelList
}
}
public function getTotal()
{
if ($this->rate->remaining > 0)
{
return $this->github->repos->get('joomla', 'joomla-cms')->open_issues_count;
}
else
{
return 0;
}
}
/**
* 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()
{
if ($this->rate->remaining > 0)
{
return $this->github->repos->get('joomla', 'joomla-cms')->open_issues_count;
}
else
{
return 0;
}
}
}

View File

@ -1,12 +1,11 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// no direct access
defined('_JEXEC') or die;
// Access check.
@ -15,7 +14,7 @@ if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester'))
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}
JLoader::registerPrefix('PT', __DIR__.'/helpers');
JLoader::registerPrefix('PT', __DIR__ . '/helpers');
$controller = JControllerLegacy::getInstance('PatchTester');
$controller->execute(JFactory::getApplication()->input->getCmd('task'));

View File

@ -3,11 +3,11 @@
<name>com_patchtester</name>
<author>Ian MacLennan</author>
<creationDate>October 2011</creationDate>
<copyright>(C) 2011 Ian MacLennan. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<copyright>(C) 2011 - 2012 Ian MacLennan, (C) 2013 Open Source Matters, Inc. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later</license>
<authorEmail>ianlenmac@gmail.com</authorEmail>
<authorUrl>http://github.com/ianmacl</authorUrl>
<version>1.5.0.alpha</version>
<version>2.0.0.alpha</version>
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
<install>
<sql>

View File

@ -1,24 +1,27 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// No direct access
defined('_JEXEC') or die;
/**
* Tests Table class
*
* @package PatchTester
* @package PatchTester
* @since 1.0
*/
class PatchtesterTableTests extends JTable
{
/**
* Constructor
*
* @param JDatabase $db A database connector object
* @param JDatabaseDriver &$db JDatabaseDriver object.
*
* @since 1.0
*/
public function __construct(&$db)
{

View File

@ -1,18 +1,18 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// No direct access
defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
JHtml::_('behavior.modal');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<script type="text/javascript">
@ -22,32 +22,29 @@ $listDirn = $this->escape($this->state->get('list.direction'));
}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm"
id="adminForm">
<form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm" id="adminForm">
<div>
<button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button" class="btn"
onclick="document.id('filter_search').value='';document.id('filter_searchid').value='';this.form.submit();">
<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
</button>
</div>
<div>
<button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button" class="btn"
onclick="document.id('filter_search').value='';document.id('filter_searchid').value='';this.form.submit();">
<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
</button>
</div>
<table class="table table-striped table-hover table-condensed">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th width="8%">
<?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_searchid" id="filter_searchid" class="span10"
value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>" />
</th>
<?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_searchid" id="filter_searchid" class="span10" value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>" />
</th>
<th class="title">
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_search" id="filter_search"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>" />
</th>
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" />
</th>
<th>I</th>
<th class="title">
<?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?>
@ -61,25 +58,24 @@ $listDirn = $this->escape($this->state->get('list.direction'));
</tr>
</thead>
<tfoot>
<tr>
<td colspan="6">
</td>
</tr>
<tr>
<td colspan="6">
</td>
</tr>
</tfoot>
<tbody>
<?php echo $this->loadTemplate('items'); ?>
</tbody>
</table>
<div class="well">
<div class="well">
<?php echo $this->pagination->getListFooter(); ?>
</div>
<div>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="pull_id" id="pull_id" value=""/>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
<?php echo JHtml::_('form.token'); ?>
<?php echo $this->pagination->getListFooter(); ?>
</div>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="pull_id" id="pull_id" value=""/>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
<?php echo JHtml::_('form.token'); ?>
</form>

View File

@ -1,83 +1,70 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// No direct access
defined('_JEXEC') or die;
foreach($this->items as $i => $item) :
$status = '';
if(isset($this->patches[$item->number])) :
$patch = $this->patches[$item->number];
$status = ($patch->applied) ? 'success' : '';
else :
$patch = false;
endif;
?>
<tr class="<?= $status ?>">
<td class="center">
<?php echo $item->number; ?>
</td>
<td>
<a class="icon icon16-github hasTip"
title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>"
href="<?php echo $item->html_url; ?>"
target="_blank">
<?php echo $item->title; ?>
</a>
</td>
<td>
<?php
if($item->body) :
echo JHtml::_('tooltip', htmlspecialchars($item->body), 'Info');
else :
echo '&nbsp;';
endif;
?>
</td>
<td>
<?php
if($item->joomlacode_issue)
{
$title = ' title="Open link::'.JText::_('COM_PATCHTESTER_OPEN_IN_JOOMLACODE').'"';
foreach ($this->items as $i => $item) :
$status = '';
if(is_int($item->joomlacode_issue))
{
echo '<a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=';
echo $item->joomlacode_issue.'"'.$title.' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#'.$item->joomlacode_issue.']</a>';
}
else
{
echo '<a href="'.$item->joomlacode_issue.'"'.$title;
echo ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#joomlacode]</a>';
}
}
?>
</td>
<td class="center">
<?php
if($patch && $patch->applied) :
echo '<div class="patchApplied" style="background-color: #adff2f;">';
echo JText::_('COM_PATCHTESTER_APPLIED');
echo '</div>';
else :
echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
endif;
?>
</td>
<td class="center">
<?php
if($patch && $patch->applied) :
echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>';
else :
echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>';
endif;
?>
</td>
if (isset($this->patches[$item->number])) :
$patch = $this->patches[$item->number];
$status = ($patch->applied) ? 'success' : '';
else :
$patch = false;
endif;
?>
<tr class="<?php echo $status ?>">
<td class="center">
<?php echo $item->number; ?>
</td>
<td>
<a class="icon icon16-github hasTip" title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>" href="<?php echo $item->html_url; ?>" target="_blank">
<?php echo $item->title; ?>
</a>
</td>
<td>
<?php if ($item->body) :
echo JHtml::_('tooltip', htmlspecialchars($item->body), 'Info');
else :
echo '&nbsp;';
endif;
?>
</td>
<td>
<?php if ($item->joomlacode_issue) :
$title = ' title="Open link::' . JText::_('COM_PATCHTESTER_OPEN_IN_JOOMLACODE') . '"';
if (is_int($item->joomlacode_issue)) :
echo '<a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=';
echo $item->joomlacode_issue . '"' . $title . ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#' . $item->joomlacode_issue . ']</a>';
else :
echo '<a href="' . $item->joomlacode_issue . '"' . $title;
echo ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#joomlacode]</a>';
endif;
endif; ?>
</td>
<td class="center">
<?php if ($patch && $patch->applied) :
echo '<div class="patchApplied" style="background-color: #adff2f;">';
echo JText::_('COM_PATCHTESTER_APPLIED');
echo '</div>';
else :
echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
endif; ?>
</td>
<td class="center">
<?php if ($patch && $patch->applied) :
echo '<a href="javascript:submitpatch(\'pull.revert\', ' . (int) $patch->id . ');">' . JText::_('COM_PATCHTESTER_REVERT_PATCH') . '</a>';
else :
echo '<a href="javascript:submitpatch(\'pull.apply\', ' . (int) $item->number . ');">' . JText::_('COM_PATCHTESTER_APPLY_PATCH') . '</a>';
endif; ?>
</td>
</tr>
<?php endforeach;

View File

@ -1,47 +1,83 @@
<?php
/**
* @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package PatchTester
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
// No direct access
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
/**
* View class for a list of pull requests.
*
* @package PatchTester
* @package PatchTester
* @since 1.0
*/
class PatchtesterViewPulls extends JViewLegacy
{
/**
* Array of open pull requests
*
* @var array
* @since 1.0
*/
protected $items;
protected $state;
protected $pagination;
/**
* Display the view
* Object containing data about applied patches
*
* @var object
* @since 1.0
*/
protected $patches;
/**
* State object
*
* @var JRegistry
* @since 1.0
*/
protected $state;
/**
* Pagination object
*
* @var JPagination
* @since 2.0
*/
protected $pagination;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise a Error object.
*
* @see fetch()
* @since 1.0
*/
public function display($tpl = null)
{
//@TODO: move the check
// TODO: move the check
$checkErrs = array();
if(false == extension_loaded ('openssl'))
if (!extension_loaded('openssl'))
{
$checkErrs[] = 'The OpenSSL extension must be installed and enabled in your php.ini';
}
if(false == in_array('https', stream_get_wrappers()))
if (!in_array('https', stream_get_wrappers()))
{
$checkErrs[] = 'https wrappers must be enabled';
}
if (count($checkErrs))
{
$application = JFactory::getApplication();
$application->enqueueMessage(
'Your system does not meet the requirements to run the PullTester extension:'
, 'error');
$application->enqueueMessage('Your system does not meet the requirements to run the PullTester extension:', 'error');
foreach ($checkErrs as $error)
{
@ -51,33 +87,36 @@ class PatchtesterViewPulls extends JViewLegacy
return $this;
}
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->patches = $this->get('AppliedPatches');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->patches = $this->get('AppliedPatches');
$this->pagination = $this->get('Pagination');
// Check for errors.
$errors = $this->get('Errors');
$errors = $this->get('Errors');
if (count($errors))
{
var_dump($errors);
var_dump($this->pagination);
// JError::raiseError(500, implode("\n", $errors));
// return false;
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->addToolbar();
parent::display($tpl);
return parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.0
*/
protected function addToolbar()
{
JToolBarHelper::title('Joomla! Patch Tester', 'patchtester');
JToolBarHelper::title(JText::_('COM_PATCHTESTER'), 'patchtester');
JToolBarHelper::preferences('com_patchtester');
JFactory::getDocument()->addStyleDeclaration(