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,26 +1,33 @@
<?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';
@ -34,12 +41,18 @@ class PatchtesterControllerPull extends JControllerLegacy
$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';
@ -52,5 +65,4 @@ class PatchtesterControllerPull extends JControllerLegacy
$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,18 +1,38 @@
<?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;
/**
* 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) public function __get($name)
{ {
if ($name == 'repos') if ($name == 'repos')

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
{ {
/**
* 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) public function get($user, $repo)
{ {
$path = '/repos/'.$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)
{
// 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);
} }
/** /**
* @param string $user * List public repositories for the specified 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 * @param string $user The username to retrieve repositories for
*
* @return object
*
* @since 2.0
* @throws DomainException * @throws DomainException
*/ */
public function getPublicRepos($user, $type = 'all', $sort = 'full_name', $direction = 'desc') public function getPublicRepos($user)
{ {
$path = '/users/'.$user.'/repos'; $path = '/users/' . $user . '/repos';
// 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)
{
// 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;
@ -11,11 +12,13 @@ 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;
@ -23,6 +26,7 @@ class PatchtesterModelPull extends JModelLegacy
* Github object * Github object
* *
* @var PTGithub * @var PTGithub
* @since 2.0
*/ */
protected $github; protected $github;
@ -30,6 +34,7 @@ class PatchtesterModelPull extends JModelLegacy
* 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:
@ -139,12 +155,24 @@ class PatchtesterModelPull extends JModelLegacy
$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,6 +247,7 @@ 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;
} }
} }
@ -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,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
*/ */
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
{ {
@ -20,6 +20,7 @@ class PatchtesterModelPulls extends JModelList
* Github object * Github object
* *
* @var PTGithub * @var PTGithub
* @since 2.0
*/ */
protected $github; protected $github;
@ -27,6 +28,7 @@ class PatchtesterModelPulls extends JModelList
* 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)
{ {
@ -112,18 +117,44 @@ class PatchtesterModelPulls extends JModelList
$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');
$db->setQuery($query);
try
{
$tests = $db->loadObjectList('pull_id');
$this->_db->setQuery($query);
$tests = $this->_db->loadObjectList('pull_id');
return $tests; 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') == '')
@ -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,6 +257,13 @@ class PatchtesterModelPulls extends JModelList
} }
} }
/**
* 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() public function getTotal()
{ {
if ($this->rate->remaining > 0) if ($this->rate->remaining > 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,11 +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;
JHtml::_('behavior.tooltip'); JHtml::_('behavior.tooltip');
@ -22,8 +22,7 @@ $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>
@ -39,14 +38,12 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<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">
@ -74,12 +71,11 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<?php echo $this->pagination->getListFooter(); ?> <?php echo $this->pagination->getListFooter(); ?>
</div> </div>
<div>
<input type="hidden" name="task" value=""/> <input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/> <input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="pull_id" id="pull_id" value=""/> <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" value="<?php echo $listOrder; ?>"/>
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/> <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
<?php echo JHtml::_('form.token'); ?> <?php echo JHtml::_('form.token'); ?>
</div>
</form> </form>

View File

@ -1,37 +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
*/ */
// 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])) :
if (isset($this->patches[$item->number])) :
$patch = $this->patches[$item->number]; $patch = $this->patches[$item->number];
$status = ($patch->applied) ? 'success' : ''; $status = ($patch->applied) ? 'success' : '';
else : else :
$patch = false; $patch = false;
endif; endif;
?> ?>
<tr class="<?= $status ?>"> <tr class="<?php echo $status ?>">
<td class="center"> <td class="center">
<?php echo $item->number; ?> <?php echo $item->number; ?>
</td> </td>
<td> <td>
<a class="icon icon16-github hasTip" <a class="icon icon16-github hasTip" title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>" href="<?php echo $item->html_url; ?>" target="_blank">
title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>"
href="<?php echo $item->html_url; ?>"
target="_blank">
<?php echo $item->title; ?> <?php echo $item->title; ?>
</a> </a>
</td> </td>
<td> <td>
<?php <?php if ($item->body) :
if($item->body) :
echo JHtml::_('tooltip', htmlspecialchars($item->body), 'Info'); echo JHtml::_('tooltip', htmlspecialchars($item->body), 'Info');
else : else :
echo '&nbsp;'; echo '&nbsp;';
@ -39,45 +36,35 @@ foreach($this->items as $i => $item) :
?> ?>
</td> </td>
<td> <td>
<?php <?php if ($item->joomlacode_issue) :
if($item->joomlacode_issue) $title = ' title="Open link::' . JText::_('COM_PATCHTESTER_OPEN_IN_JOOMLACODE') . '"';
{
$title = ' title="Open link::'.JText::_('COM_PATCHTESTER_OPEN_IN_JOOMLACODE').'"';
if(is_int($item->joomlacode_issue)) if (is_int($item->joomlacode_issue)) :
{
echo '<a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id='; 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 . '"' . $title . ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#'.$item->joomlacode_issue.']</a>'; echo '[#' . $item->joomlacode_issue . ']</a>';
} else :
else echo '<a href="' . $item->joomlacode_issue . '"' . $title;
{
echo '<a href="'.$item->joomlacode_issue.'"'.$title;
echo ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">'; echo ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#joomlacode]</a>'; echo '[#joomlacode]</a>';
} endif;
} endif; ?>
?>
</td> </td>
<td class="center"> <td class="center">
<?php <?php if ($patch && $patch->applied) :
if($patch && $patch->applied) :
echo '<div class="patchApplied" style="background-color: #adff2f;">'; echo '<div class="patchApplied" style="background-color: #adff2f;">';
echo JText::_('COM_PATCHTESTER_APPLIED'); echo JText::_('COM_PATCHTESTER_APPLIED');
echo '</div>'; echo '</div>';
else : else :
echo JText::_('COM_PATCHTESTER_NOT_APPLIED'); echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
endif; endif; ?>
?>
</td> </td>
<td class="center"> <td class="center">
<?php <?php if ($patch && $patch->applied) :
if($patch && $patch->applied) : echo '<a href="javascript:submitpatch(\'pull.revert\', ' . (int) $patch->id . ');">' . JText::_('COM_PATCHTESTER_REVERT_PATCH') . '</a>';
echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>';
else : else :
echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>'; echo '<a href="javascript:submitpatch(\'pull.apply\', ' . (int) $item->number . ');">' . JText::_('COM_PATCHTESTER_APPLY_PATCH') . '</a>';
endif; endif; ?>
?>
</td> </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;
/**
* Object containing data about applied patches
*
* @var object
* @since 1.0
*/
protected $patches;
/**
* State object
*
* @var JRegistry
* @since 1.0
*/
protected $state; protected $state;
/**
* Pagination object
*
* @var JPagination
* @since 2.0
*/
protected $pagination; protected $pagination;
/** /**
* Display the view * 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)
{ {
@ -61,23 +97,26 @@ class PatchtesterViewPulls extends JViewLegacy
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(