31
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-09-27 20:19: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 <?php
/** /**
* @package PatchTester * @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved. *
* @license GNU General Public License version 2 or later; see LICENSE.txt * @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; defined('_JEXEC') or die;
/** /**
* PatchTester Controller * PatchTester Controller
* *
* @package PatchTester * @package PatchTester
* @since 1.0
*/ */
class PatchTesterController extends JControllerLegacy 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 * @var string
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * @since 1.0
*
* @return JController This object to support chaining.
* @since 1.5
*/ */
public function display($cachable = false, $urlparams = false) protected $default_view = 'pulls';
{
parent::display();
return $this;
}
} }

View File

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

View File

@ -1,30 +1,50 @@
<?php <?php
/** /**
* User: elkuku * @package PatchTester
* Date: 08.09.12 *
* Time: 19:08 * @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. * @property-read PTGithubRepos $repos GitHub API object for repos.
*
* @package PatchTester
* @since 2.0
*/ */
class PTGithub extends JGithub class PTGithub extends JGithub
{ {
/** /**
* @var PTGithubRepos * @var PTGithubRepos
*/ * @since 2.0
protected $repos; */
protected $repos;
public function __get($name) /**
{ * Magic method to lazily create API objects
if ($name == 'repos') *
{ * @param string $name Name of property to retrieve
if ($this->repos == null) *
{ * @return JGithubObject GitHub API object (gists, issues, pulls, etc).
$this->repos = new PTGithubRepos($this->options, $this->client); *
} * @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 <?php
/** /**
* User: elkuku * @package PatchTester
* Date: 08.09.12 *
* Time: 18:54 * @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 class PTGithubRepos extends JGithubObject
{ {
public function get($user, $repo) /**
{ * Retrieve information about the specified repository
$path = '/repos/'.$user.'/'.$repo; *
* @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. // Send the request.
$response = $this->client->get($this->fetchUrl($path)); return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
// Validate the response code. /**
if($response->code != 200) * List public repositories for the specified user.
{ *
// Decode the error response and throw an exception. * @param string $user The username to retrieve repositories for
$error = json_decode($response->body); *
* @return object
*
* @since 2.0
* @throws DomainException
*/
public function getPublicRepos($user)
{
$path = '/users/' . $user . '/repos';
throw new DomainException($error->message, $response->code); // Send the request.
} return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
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);
}
} }

View File

@ -1,36 +1,38 @@
COM_PATCHTESTER="Patch Tester" ; Joomla! Project
COM_PATCHTESTER_CONFIGURATION="Patch Tester Settings" ; Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 Open Source Matters, Inc. All rights reserved.
COM_PATCHTESTER_NOT_APPLIED="Not Applied" ; 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_APPLIED="Applied"
COM_PATCHTESTER_REVERT_PATCH="Revert Patch" COM_PATCHTESTER_APPLY_OK="Patch successfully applied"
COM_PATCHTESTER_APPLY_PATCH="Apply Patch" COM_PATCHTESTER_APPLY_PATCH="Apply Patch"
COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch" COM_PATCHTESTER_COMPONENT_DESC="Joomla! Patch Tester Configuration Values"
COM_PATCHTESTER_COMPONENT_LABEL="Patch Tester" COM_PATCHTESTER_COMPONENT_LABEL="Joomla! Patch Tester"
COM_PATCHTESTER_COMPONENT_DESC="Patch Tester Configuration Values" 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_LABEL="GitHub Username"
COM_PATCHTESTER_FIELD_ORG_DESC="Name of account on GitHub of which to monitor pull requests" 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_LABEL="GitHub Repository"
COM_PATCHTESTER_FIELD_REPO_DESC="Name of repository on GitHub of which to monitor pull requests" 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_FILE_DELETED_DOES_NOT_EXIST_S="The file marked for deletion does not exist: %s"
COM_PATCHTESTER_FIELD_GH_USER_DESC="Name of account on GitHub of which to authenticate to the API with" COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="The file marked for modification does not exist: %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_JOOMLACODE_ISSUE="Joomlacode Issue" COM_PATCHTESTER_JOOMLACODE_ISSUE="Joomlacode Issue"
COM_PATCHTESTER_PULL_ID="Pull ID" 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_PULL_ID="Pull ID"
COM_PATCHTESTER_SEARCH_IN_TITLE="Pull title" COM_PATCHTESTER_SEARCH_IN_TITLE="Pull title"
COM_PATCHTESTER_SORT="Sort:" COM_PATCHTESTER_SORT="Sort:"
COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch"
;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"

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" COM_PATCHTESTER_XML_DESCRIPTION="Component for pull request management testing"

View File

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

View File

@ -1,32 +1,34 @@
<?php <?php
/** /**
* @package PatchTester * @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved. *
* @license GNU General Public License version 2 or later; see LICENSE.txt * @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; 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 class PatchtesterModelPulls extends JModelList
{ {
/** /**
* Github object * Github object
* *
* @var PTGithub * @var PTGithub
* @since 2.0
*/ */
protected $github; protected $github;
/** /**
* Object containing the rate limit data * Object containing the rate limit data
* *
* @var object * @var object
* @since 2.0
*/ */
protected $rate; protected $rate;
@ -36,7 +38,7 @@ class PatchtesterModelPulls extends JModelList
* @param array $config An optional associative array of configuration settings. * @param array $config An optional associative array of configuration settings.
* *
* @see JController * @see JController
* @since 11.1 * @since 1.0
*/ */
public function __construct($config = array()) public function __construct($config = array())
{ {
@ -81,13 +83,16 @@ class PatchtesterModelPulls extends JModelList
} }
} }
/** /**
* Method to auto-populate the model state. * 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) protected function populateState($ordering = null, $direction = null)
{ {
@ -98,32 +103,58 @@ class PatchtesterModelPulls extends JModelList
$searchId = $this->getUserStateFromRequest($this->context . '.filter.searchid', 'filter_searchid'); $searchId = $this->getUserStateFromRequest($this->context . '.filter.searchid', 'filter_searchid');
$this->setState('filter.searchid', $searchId); $this->setState('filter.searchid', $searchId);
// Load the parameters. // Load the parameters.
$params = JComponentHelper::getParams('com_patchtester'); $params = JComponentHelper::getParams('com_patchtester');
$this->setState('params', $params); $this->setState('params', $params);
$this->setState('github_user', $params->get('org', 'joomla')); $this->setState('github_user', $params->get('org', 'joomla'));
$this->setState('github_repo', $params->get('repo', 'joomla-cms')); $this->setState('github_repo', $params->get('repo', 'joomla-cms'));
// List state information. // List state information.
parent::populateState('number', 'desc'); parent::populateState('number', 'desc');
// GitHub's default list limit is 30 // GitHub's default list limit is 30
$this->setState('list.limit', 30); $this->setState('list.limit', 30);
} }
/**
* Retrieves a list of applied patches
*
* @return mixed
*
* @since 1.0
*/
public function getAppliedPatches() public function getAppliedPatches()
{ {
$query = $this->_db->getQuery(true); $db = $this->getDbo();
$query->select('*'); $query = $db->getQuery(true)
$query->from('#__patchtester_tests'); ->select('*')
$query->where('applied = 1'); ->from('#__patchtester_tests')
->where('applied = 1');
$this->_db->setQuery($query); $db->setQuery($query);
$tests = $this->_db->loadObjectList('pull_id');
return $tests; 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() public function getItems()
{ {
if ($this->getState('github_user') == '' || $this->getState('github_repo') == '') 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->ordering = $this->getState('list.ordering', 'title');
$this->orderDir = $this->getState('list.direction', 'asc'); $this->orderDir = $this->getState('list.direction', 'asc');
$search = $this->getState('filter.search'); $search = $this->getState('filter.search');
$searchId = $this->getState('filter.searchid'); $searchId = $this->getState('filter.searchid');
$page = $this->getPagination()->pagesCurrent; $page = $this->getPagination()->pagesCurrent;
try try
{ {
@ -161,7 +192,7 @@ class PatchtesterModelPulls extends JModelList
continue; continue;
} }
// Try to find a joomlacode issue number // Try to find a Joomlacode issue number
$pulls[$i]->joomlacode_issue = 0; $pulls[$i]->joomlacode_issue = 0;
$matches = array(); $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) public function sortItems($a, $b)
{ {
switch ($this->ordering) switch ($this->ordering)
@ -216,15 +257,22 @@ class PatchtesterModelPulls extends JModelList
} }
} }
public function getTotal() /**
{ * Method to get the total number of items for the data set.
if ($this->rate->remaining > 0) *
{ * @return integer The total number of items available in the data set.
return $this->github->repos->get('joomla', 'joomla-cms')->open_issues_count; *
} * @since 2.0
else */
{ public function getTotal()
return 0; {
} 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 <?php
/** /**
* @package PatchTester * @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved. *
* @license GNU General Public License version 2 or later; see LICENSE.txt * @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; defined('_JEXEC') or die;
// Access check. // Access check.
@ -15,7 +14,7 @@ if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester'))
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
} }
JLoader::registerPrefix('PT', __DIR__.'/helpers'); JLoader::registerPrefix('PT', __DIR__ . '/helpers');
$controller = JControllerLegacy::getInstance('PatchTester'); $controller = JControllerLegacy::getInstance('PatchTester');
$controller->execute(JFactory::getApplication()->input->getCmd('task')); $controller->execute(JFactory::getApplication()->input->getCmd('task'));

View File

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

View File

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

View File

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

View File

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

View File

@ -1,47 +1,83 @@
<?php <?php
/** /**
* @package PatchTester * @package PatchTester
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved. *
* @license GNU General Public License version 2 or later; see LICENSE.txt * @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; defined('_JEXEC') or die;
jimport('joomla.application.component.view');
/** /**
* View class for a list of pull requests. * View class for a list of pull requests.
* *
* @package PatchTester * @package PatchTester
* @since 1.0
*/ */
class PatchtesterViewPulls extends JViewLegacy class PatchtesterViewPulls extends JViewLegacy
{ {
/**
* Array of open pull requests
*
* @var array
* @since 1.0
*/
protected $items; 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) public function display($tpl = null)
{ {
//@TODO: move the check // TODO: move the check
$checkErrs = array(); $checkErrs = array();
if(false == extension_loaded ('openssl')) if (!extension_loaded('openssl'))
{
$checkErrs[] = 'The OpenSSL extension must be installed and enabled in your php.ini'; $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'; $checkErrs[] = 'https wrappers must be enabled';
}
if (count($checkErrs)) if (count($checkErrs))
{ {
$application = JFactory::getApplication(); $application = JFactory::getApplication();
$application->enqueueMessage( $application->enqueueMessage('Your system does not meet the requirements to run the PullTester extension:', 'error');
'Your system does not meet the requirements to run the PullTester extension:'
, 'error');
foreach ($checkErrs as $error) foreach ($checkErrs as $error)
{ {
@ -51,33 +87,36 @@ class PatchtesterViewPulls extends JViewLegacy
return $this; return $this;
} }
$this->state = $this->get('State'); $this->state = $this->get('State');
$this->items = $this->get('Items'); $this->items = $this->get('Items');
$this->patches = $this->get('AppliedPatches'); $this->patches = $this->get('AppliedPatches');
$this->pagination = $this->get('Pagination'); $this->pagination = $this->get('Pagination');
// Check for errors. // Check for errors.
$errors = $this->get('Errors'); $errors = $this->get('Errors');
if (count($errors)) if (count($errors))
{ {
var_dump($errors); JError::raiseError(500, implode("\n", $errors));
var_dump($this->pagination);
// JError::raiseError(500, implode("\n", $errors)); return false;
// return false;
} }
$this->addToolbar(); $this->addToolbar();
parent::display($tpl); return parent::display($tpl);
} }
/** /**
* Add the page title and toolbar. * Add the page title and toolbar.
*
* @return void
*
* @since 1.0
*/ */
protected function addToolbar() protected function addToolbar()
{ {
JToolBarHelper::title('Joomla! Patch Tester', 'patchtester'); JToolBarHelper::title(JText::_('COM_PATCHTESTER'), 'patchtester');
JToolBarHelper::preferences('com_patchtester'); JToolBarHelper::preferences('com_patchtester');
JFactory::getDocument()->addStyleDeclaration( JFactory::getDocument()->addStyleDeclaration(