mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2024-12-22 10:58:58 +00:00
Formatting and fixes
This commit is contained in:
parent
d1a8e14e64
commit
edfce5445f
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<access component="com_patchtester">
|
<access component="com_patchtester">
|
||||||
<section name="component">
|
<section name="component">
|
||||||
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
|
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC"/>
|
||||||
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
|
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC"/>
|
||||||
</section>
|
</section>
|
||||||
</access>
|
</access>
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<config>
|
<config>
|
||||||
<fieldset name="component"
|
<fieldset name="component"
|
||||||
label="COM_PATCHTESTER_COMPONENT_LABEL"
|
label="COM_PATCHTESTER_COMPONENT_LABEL"
|
||||||
description="COM_PATCHTESTER_COMPONENT_DESC"
|
description="COM_PATCHTESTER_COMPONENT_DESC"
|
||||||
>
|
>
|
||||||
|
|
||||||
<field name="org" type="text"
|
<field name="org" type="text"
|
||||||
default="joomla"
|
default="joomla"
|
||||||
description="COM_PATCHTESTER_FIELD_ORG_DESC"
|
description="COM_PATCHTESTER_FIELD_ORG_DESC"
|
||||||
label="COM_PATCHTESTER_FIELD_ORG_LABEL"
|
label="COM_PATCHTESTER_FIELD_ORG_LABEL"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<field name="repo" type="text"
|
<field name="repo" type="text"
|
||||||
default="joomla-cms"
|
default="joomla-cms"
|
||||||
description="COM_PATCHTESTER_FIELD_REPO_DESC"
|
description="COM_PATCHTESTER_FIELD_REPO_DESC"
|
||||||
label="COM_PATCHTESTER_FIELD_REPO_LABEL"
|
label="COM_PATCHTESTER_FIELD_REPO_LABEL"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset name="permissions"
|
<fieldset name="permissions"
|
||||||
description="JCONFIG_PERMISSIONS_DESC"
|
description="JCONFIG_PERMISSIONS_DESC"
|
||||||
label="JCONFIG_PERMISSIONS_LABEL"
|
label="JCONFIG_PERMISSIONS_LABEL"
|
||||||
>
|
>
|
||||||
|
|
||||||
<field name="rules" type="rules"
|
<field name="rules" type="rules"
|
||||||
component="com_patchtester"
|
component="com_patchtester"
|
||||||
filter="rules"
|
filter="rules"
|
||||||
validate="rules"
|
validate="rules"
|
||||||
label="JCONFIG_PERMISSIONS_LABEL"
|
label="JCONFIG_PERMISSIONS_LABEL"
|
||||||
section="component" />
|
section="component"/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</config>
|
</config>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// No direct access
|
// No direct access
|
||||||
@ -11,7 +11,7 @@ defined('_JEXEC') or die;
|
|||||||
/**
|
/**
|
||||||
* PatchTester Controller
|
* PatchTester Controller
|
||||||
*
|
*
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
*/
|
*/
|
||||||
class PatchTesterController extends JController
|
class PatchTesterController extends JController
|
||||||
{
|
{
|
||||||
@ -20,11 +20,11 @@ class PatchTesterController extends JController
|
|||||||
/**
|
/**
|
||||||
* Method to display a view.
|
* Method to display a view.
|
||||||
*
|
*
|
||||||
* @param boolean $cachable If true, the view output will be cached
|
* @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()}.
|
* @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.
|
* @return JController This object to support chaining.
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public function display($cachable = false, $urlparams = false)
|
public function display($cachable = false, $urlparams = false)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// No direct access
|
// No direct access
|
||||||
@ -13,19 +13,22 @@ jimport('joomla.application.component.controllerform');
|
|||||||
/**
|
/**
|
||||||
* Pull controller class
|
* Pull controller class
|
||||||
*
|
*
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
*/
|
*/
|
||||||
class PatchtesterControllerPull extends JController
|
class PatchtesterControllerPull extends JController
|
||||||
{
|
{
|
||||||
public function apply()
|
public function apply()
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
$model = $this->getModel('pull')
|
{
|
||||||
->apply(JRequest::getVar('pull_id'));
|
$this->getModel('pull')
|
||||||
|
->apply(JRequest::getVar('pull_id'));
|
||||||
|
|
||||||
$msg = 'Patch successfully applied';
|
$msg = 'Patch successfully applied';
|
||||||
$type = 'message';
|
$type = 'message';
|
||||||
} catch (Exception $e) {
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
$msg = $e->getMessage();
|
$msg = $e->getMessage();
|
||||||
$type = 'error';
|
$type = 'error';
|
||||||
}
|
}
|
||||||
@ -35,14 +38,20 @@ class PatchtesterControllerPull extends JController
|
|||||||
|
|
||||||
public function revert()
|
public function revert()
|
||||||
{
|
{
|
||||||
$model = $this->getModel('pull');
|
try
|
||||||
if ($model->revert(JRequest::getVar('pull_id'))) {
|
{
|
||||||
|
$this->getModel('pull')
|
||||||
|
->revert(JRequest::getVar('pull_id'));
|
||||||
|
|
||||||
$msg = 'Patch successfully reverted';
|
$msg = 'Patch successfully reverted';
|
||||||
$type = 'message';
|
$type = 'message';
|
||||||
} else {
|
}
|
||||||
$msg = 'Patch did not revert';
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
$msg = $e->getMessage() ?: 'Patch did not revert';
|
||||||
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
@ -10,11 +10,10 @@ defined('_JEXEC') or die;
|
|||||||
/**
|
/**
|
||||||
* Methods supporting pull requests.
|
* Methods supporting pull requests.
|
||||||
*
|
*
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
*/
|
*/
|
||||||
class PatchtesterModelPull extends JModel
|
class PatchtesterModelPull extends JModel
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to auto-populate the model state.
|
* Method to auto-populate the model state.
|
||||||
*
|
*
|
||||||
@ -40,11 +39,13 @@ class PatchtesterModelPull extends JModel
|
|||||||
|
|
||||||
$lines = explode("\n", $patch);
|
$lines = explode("\n", $patch);
|
||||||
|
|
||||||
foreach ($lines AS $line) {
|
foreach ($lines AS $line)
|
||||||
|
{
|
||||||
switch ($state)
|
switch ($state)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (strpos($line, 'diff --git') === 0) {
|
if (strpos($line, 'diff --git') === 0)
|
||||||
|
{
|
||||||
$state = 1;
|
$state = 1;
|
||||||
}
|
}
|
||||||
$file = new stdClass;
|
$file = new stdClass;
|
||||||
@ -52,27 +53,33 @@ class PatchtesterModelPull extends JModel
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if (strpos($line, 'index') === 0) {
|
if (strpos($line, 'index') === 0)
|
||||||
|
{
|
||||||
$file->index = substr($line, 6);
|
$file->index = substr($line, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, '---') === 0) {
|
if (strpos($line, '---') === 0)
|
||||||
|
{
|
||||||
$file->old = substr($line, 6);
|
$file->old = substr($line, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, '+++') === 0) {
|
if (strpos($line, '+++') === 0)
|
||||||
|
{
|
||||||
$file->new = substr($line, 6);
|
$file->new = substr($line, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, 'new file mode') === 0) {
|
if (strpos($line, 'new file mode') === 0)
|
||||||
|
{
|
||||||
$file->action = 'added';
|
$file->action = 'added';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, 'deleted file mode') === 0) {
|
if (strpos($line, 'deleted file mode') === 0)
|
||||||
|
{
|
||||||
$file->action = 'deleted';
|
$file->action = 'deleted';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, '@@') === 0) {
|
if (strpos($line, '@@') === 0)
|
||||||
|
{
|
||||||
$state = 0;
|
$state = 0;
|
||||||
$files[] = $file;
|
$files[] = $file;
|
||||||
}
|
}
|
||||||
@ -84,54 +91,62 @@ class PatchtesterModelPull extends JModel
|
|||||||
|
|
||||||
public function apply($id)
|
public function apply($id)
|
||||||
{
|
{
|
||||||
jimport('joomla.client.github');
|
//@todo Use the JCurl class
|
||||||
jimport('joomla.client.curl');
|
require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/curl.php';
|
||||||
|
|
||||||
$table = JTable::getInstance('tests', 'PatchTesterTable');
|
$table = JTable::getInstance('tests', 'PatchTesterTable');
|
||||||
$github = new JGithub;
|
$github = new JGithub;
|
||||||
$pull = $github->pulls->get($this->getState('github_user'), $this->getState('github_repo'), $id);
|
$pull = $github->pulls->get($this->getState('github_user'), $this->getState('github_repo'), $id);
|
||||||
|
|
||||||
if (is_null($pull->head->repo)) {
|
if (is_null($pull->head->repo))
|
||||||
|
{
|
||||||
throw new Exception(JText::_('COM_PATCHTESTER_REPO_IS_GONE'));
|
throw new Exception(JText::_('COM_PATCHTESTER_REPO_IS_GONE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$patch = JCurl::getAdapter($pull->diff_url)
|
$patch = PTCurl::getAdapter($pull->diff_url)
|
||||||
->fetch()->body;
|
->fetch()->body;
|
||||||
|
|
||||||
$files = $this->parsePatch($patch);
|
$files = $this->parsePatch($patch);
|
||||||
|
|
||||||
foreach($files AS $file) {
|
foreach ($files as $file)
|
||||||
if ($file->action == 'deleted' && ! file_exists(JPATH_ROOT . '/' . $file->old)) {
|
{
|
||||||
|
if ($file->action == 'deleted' && !file_exists(JPATH_ROOT . '/' . $file->old))
|
||||||
|
{
|
||||||
throw new Exception(sprintf(JText::_('COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S'), $file->old));
|
throw new Exception(sprintf(JText::_('COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S'), $file->old));
|
||||||
}
|
}
|
||||||
if ($file->action == 'added' || $file->action == 'modified') {
|
if ($file->action == 'added' || $file->action == 'modified')
|
||||||
|
{
|
||||||
|
|
||||||
// if the backup file already exists, we can't apply the patch
|
// if the backup file already exists, we can't apply the patch
|
||||||
if (file_exists(JPATH_COMPONENT . '/backups/' . md5($file->new) . '.txt')) {
|
if (file_exists(JPATH_COMPONENT . '/backups/' . md5($file->new) . '.txt'))
|
||||||
|
{
|
||||||
throw new Exception(sprintf(JText::_('COM_PATCHTESTER_CONFLICT_S'), $file->new));
|
throw new Exception(sprintf(JText::_('COM_PATCHTESTER_CONFLICT_S'), $file->new));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file->action == 'modified' && ! file_exists(JPATH_ROOT . '/' . $file->old)) {
|
if ($file->action == 'modified' && !file_exists(JPATH_ROOT . '/' . $file->old))
|
||||||
|
{
|
||||||
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 = JCurl::getAdapter($url)
|
$file->body = PTCurl::getAdapter($url)
|
||||||
->fetch()->body;
|
->fetch()->body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// at this point, we have ensured that we have all the new files and there are no conflicts
|
// at this point, we have ensured that we have all the new files and there are no conflicts
|
||||||
|
|
||||||
foreach ($files AS $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
// we only create a backup if the file already exists
|
// we only create a backup if the file already exists
|
||||||
if ($file->action == 'deleted' || (file_exists(JPATH_ROOT . '/' . $file->new) && $file->action == 'modified')) {
|
if ($file->action == 'deleted' || (file_exists(JPATH_ROOT . '/' . $file->new) && $file->action == 'modified'))
|
||||||
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(sprintf('Can not copy file %s to %s'
|
||||||
, JPATH_ROOT . '/' . $file->old, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'));
|
, JPATH_ROOT . '/' . $file->old, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,13 +154,15 @@ class PatchtesterModelPull extends JModel
|
|||||||
{
|
{
|
||||||
case 'modified':
|
case 'modified':
|
||||||
case 'added':
|
case 'added':
|
||||||
if( ! JFile::write(JPath::clean(JPATH_ROOT . '/' . $file->new), $file->body)) {
|
if (!JFile::write(JPath::clean(JPATH_ROOT . '/' . $file->new), $file->body))
|
||||||
|
{
|
||||||
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':
|
||||||
if( ! JFile::delete(JPATH::clean(JPATH_ROOT . '/' . $file->old))) {
|
if (!JFile::delete(JPATH::clean(JPATH_ROOT . '/' . $file->old)))
|
||||||
|
{
|
||||||
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;
|
||||||
@ -159,7 +176,8 @@ class PatchtesterModelPull extends JModel
|
|||||||
$version = new JVersion;
|
$version = new JVersion;
|
||||||
$table->applied_version = $version->getShortVersion();
|
$table->applied_version = $version->getShortVersion();
|
||||||
|
|
||||||
if ( ! $table->store()) {
|
if (!$table->store())
|
||||||
|
{
|
||||||
throw new Exception($table->getError());
|
throw new Exception($table->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,41 +192,64 @@ class PatchtesterModelPull extends JModel
|
|||||||
|
|
||||||
// we don't want to restore files from an older version
|
// we don't want to restore files from an older version
|
||||||
$version = new JVersion;
|
$version = new JVersion;
|
||||||
if ($table->applied_version != $version->getShortVersion()) {
|
|
||||||
|
if ($table->applied_version != $version->getShortVersion())
|
||||||
|
{
|
||||||
|
/*
|
||||||
$table->applied = 0;
|
$table->applied = 0;
|
||||||
$table->applied_version = '';
|
$table->applied_version = '';
|
||||||
$table->store();
|
$table->store();
|
||||||
|
*/
|
||||||
|
$table->delete();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$files = json_decode($table->data);
|
$files = json_decode($table->data);
|
||||||
|
|
||||||
foreach ($files AS $file) {
|
if (!$files)
|
||||||
switch ($file->action) {
|
{
|
||||||
|
throw new Exception(sprintf('%s - Error retrieving table data (%s)'
|
||||||
|
, __METHOD__, htmlentities($table->data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
switch ($file->action)
|
||||||
|
{
|
||||||
case 'deleted':
|
case 'deleted':
|
||||||
case 'modified':
|
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('Can not copy file %s to %s'
|
throw new Exception(sprintf('Can not copy file %s to %s'
|
||||||
, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'
|
, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'
|
||||||
, JPATH_ROOT . '/' . $file->old));
|
, 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('Can not delete the file: %s'
|
throw new Exception(sprintf('Can not delete the file: %s'
|
||||||
, JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'));
|
, 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('Can not delete the file: %s', JPATH_ROOT . '/' . $file->new));
|
throw new Exception(sprintf('Can not delete the file: %s', JPATH_ROOT . '/' . $file->new));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
$table->applied_version = '';
|
$table->applied_version = '';
|
||||||
$table->applied = 0;
|
$table->applied = 0;
|
||||||
$table->store();
|
$table->store();
|
||||||
|
*/
|
||||||
|
$table->delete();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
@ -12,7 +12,7 @@ jimport('joomla.application.component.modellist');
|
|||||||
/**
|
/**
|
||||||
* Methods supporting a list of pull request.
|
* Methods supporting a list of pull request.
|
||||||
*
|
*
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
*/
|
*/
|
||||||
class PatchtesterModelPulls extends JModelList
|
class PatchtesterModelPulls extends JModelList
|
||||||
{
|
{
|
||||||
@ -20,13 +20,15 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param array An optional associative array of configuration settings.
|
* @param array $config An optional associative array of configuration settings.
|
||||||
* @see JController
|
*
|
||||||
* @since 1.6
|
* @see JController
|
||||||
|
* @since 11.1
|
||||||
*/
|
*/
|
||||||
public function __construct($config = array())
|
public function __construct($config = array())
|
||||||
{
|
{
|
||||||
if (empty($config['filter_fields'])) {
|
if (empty($config['filter_fields']))
|
||||||
|
{
|
||||||
$config['filter_fields'] = array(
|
$config['filter_fields'] = array(
|
||||||
'id', 'id',
|
'id', 'id',
|
||||||
'title', 'title',
|
'title', 'title',
|
||||||
@ -44,15 +46,15 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
*
|
*
|
||||||
* Note. Calling getState in this method will result in recursion.
|
* Note. Calling getState in this method will result in recursion.
|
||||||
*
|
*
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
protected function populateState($ordering = null, $direction = null)
|
protected function populateState($ordering = null, $direction = null)
|
||||||
{
|
{
|
||||||
// Load the filter state.
|
// Load the filter state.
|
||||||
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
|
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||||
$this->setState('filter.search', $search);
|
$this->setState('filter.search', $search);
|
||||||
|
|
||||||
$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.
|
||||||
@ -73,9 +75,10 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
* different modules that might need different sets of data or different
|
* different modules that might need different sets of data or different
|
||||||
* ordering requirements.
|
* ordering requirements.
|
||||||
*
|
*
|
||||||
* @param string $id A prefix for the store id.
|
* @param string $id A prefix for the store id.
|
||||||
* @return string A store id.
|
*
|
||||||
* @since 1.6
|
* @return string A store id.
|
||||||
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
protected function getStoreId($id = '')
|
protected function getStoreId($id = '')
|
||||||
{
|
{
|
||||||
@ -86,7 +89,7 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
{
|
{
|
||||||
$query = $this->_db->getQuery(true);
|
$query = $this->_db->getQuery(true);
|
||||||
$query->select('*');
|
$query->select('*');
|
||||||
$query->from('#__tests');
|
$query->from('#__patchtester_tests');
|
||||||
$query->where('applied = 1');
|
$query->where('applied = 1');
|
||||||
|
|
||||||
$this->_db->setQuery($query);
|
$this->_db->setQuery($query);
|
||||||
@ -98,7 +101,8 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
{
|
{
|
||||||
jimport('joomla.client.github');
|
jimport('joomla.client.github');
|
||||||
|
|
||||||
if ($this->getState('github_user') == '' || $this->getState('github_repo') == '') {
|
if ($this->getState('github_user') == '' || $this->getState('github_repo') == '')
|
||||||
|
{
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,28 +111,57 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
$search = $this->getState('filter.search');
|
$search = $this->getState('filter.search');
|
||||||
$searchId = $this->getState('filter.searchid');
|
$searchId = $this->getState('filter.searchid');
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
$github = new JGithub();
|
$github = new JGithub();
|
||||||
$pulls = $github->pulls->getAll($this->getState('github_user'), $this->getState('github_repo'));
|
$pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'));
|
||||||
usort($pulls, array($this, 'sortItems'));
|
usort($pulls, array($this, 'sortItems'));
|
||||||
|
|
||||||
foreach ($pulls AS $i => &$pull)
|
foreach ($pulls as $i => &$pull)
|
||||||
{
|
{
|
||||||
if($search && false === strpos($pull->title, $search)) {
|
if ($search && false === strpos($pull->title, $search))
|
||||||
|
{
|
||||||
unset($pulls[$i]);
|
unset($pulls[$i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($searchId && $pull->number != $searchId) {
|
|
||||||
|
if ($searchId && $pull->number != $searchId)
|
||||||
|
{
|
||||||
unset($pulls[$i]);
|
unset($pulls[$i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to find a joomlacode issue number
|
||||||
|
$pulls[$i]->joomlacode_issue = 0;
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
|
||||||
preg_match('#\[\#([0-9]+)\]#', $pull->title, $matches);
|
preg_match('#\[\#([0-9]+)\]#', $pull->title, $matches);
|
||||||
$pull->joomlacode_issue = isset($matches[1]) ? $matches[1] : 0;
|
|
||||||
|
if (isset($matches[1]))
|
||||||
|
{
|
||||||
|
$pulls[$i]->joomlacode_issue = (int) $matches[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
preg_match('#(http://joomlacode[-\w\./\?\S]+)#', $pull->body, $matches);
|
||||||
|
|
||||||
|
if (isset($matches[1]))
|
||||||
|
{
|
||||||
|
preg_match('#tracker_item_id=([0-9]+)#', $matches[1], $matches);
|
||||||
|
|
||||||
|
if (isset($matches[1]))
|
||||||
|
{
|
||||||
|
$pulls[$i]->joomlacode_issue = (int) $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pulls;
|
return $pulls;
|
||||||
} catch (Exception $e) {
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
@ -144,7 +177,7 @@ class PatchtesterModelPulls extends JModelList
|
|||||||
|
|
||||||
case 'number' :
|
case 'number' :
|
||||||
default :
|
default :
|
||||||
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
|
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -10,13 +10,14 @@
|
|||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
// Access check.
|
// Access check.
|
||||||
if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester')) {
|
if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester'))
|
||||||
|
{
|
||||||
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
|
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include dependencies
|
// Include dependencies
|
||||||
jimport('joomla.application.component.controller');
|
jimport('joomla.application.component.controller');
|
||||||
|
|
||||||
$controller = JController::getInstance('PatchTester');
|
$controller = JController::getInstance('PatchTester');
|
||||||
$controller->execute(JRequest::getCmd('task'));
|
$controller->execute(JRequest::getCmd('task'));
|
||||||
$controller->redirect();
|
$controller->redirect();
|
||||||
|
@ -1,51 +1,52 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<extension type="component" version="1.7" method="upgrade">
|
<extension type="component" version="1.7" method="upgrade">
|
||||||
<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>(C) 2011 Ian MacLennan. All rights reserved.
|
||||||
</copyright>
|
</copyright>
|
||||||
<license>GNU General Public License version 2 or later; see
|
<license>GNU General Public License version 2 or later; see
|
||||||
LICENSE.txt</license>
|
LICENSE.txt
|
||||||
<authorEmail>ianlenmac@gmail.com</authorEmail>
|
</license>
|
||||||
<authorUrl>http://github.com/ianmacl</authorUrl>
|
<authorEmail>ianlenmac@gmail.com</authorEmail>
|
||||||
<version>1.0alpha</version>
|
<authorUrl>http://github.com/ianmacl</authorUrl>
|
||||||
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
|
<version>1.0alpha</version>
|
||||||
|
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
|
||||||
|
|
||||||
<install> <!-- Runs on install -->
|
<install> <!-- Runs on install -->
|
||||||
<sql>
|
<sql>
|
||||||
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
|
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
|
||||||
</sql>
|
</sql>
|
||||||
</install>
|
</install>
|
||||||
<uninstall> <!-- Runs on uninstall -->
|
<uninstall> <!-- Runs on uninstall -->
|
||||||
<sql>
|
<sql>
|
||||||
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
|
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
|
||||||
</sql>
|
</sql>
|
||||||
</uninstall>
|
</uninstall>
|
||||||
|
|
||||||
<files folder="site">
|
<files folder="site">
|
||||||
<filename>patchtester.php</filename>
|
<filename>patchtester.php</filename>
|
||||||
</files>
|
</files>
|
||||||
<administration>
|
<administration>
|
||||||
<menu img="components/com_patchtester/assets/images/icon-16-patchtester.png">com_patchtester</menu>
|
<menu img="components/com_patchtester/assets/images/icon-16-patchtester.png">com_patchtester</menu>
|
||||||
<files folder="admin">
|
<files folder="admin">
|
||||||
<filename>access.xml</filename>
|
<filename>access.xml</filename>
|
||||||
<filename>config.xml</filename>
|
<filename>config.xml</filename>
|
||||||
<filename>controller.php</filename>
|
<filename>controller.php</filename>
|
||||||
<filename>patchtester.php</filename>
|
<filename>patchtester.php</filename>
|
||||||
<folder>assets</folder>
|
<folder>assets</folder>
|
||||||
<folder>controllers</folder>
|
<folder>controllers</folder>
|
||||||
<folder>models</folder>
|
<folder>models</folder>
|
||||||
<folder>sql</folder>
|
<folder>sql</folder>
|
||||||
<folder>tables</folder>
|
<folder>tables</folder>
|
||||||
<folder>views</folder>
|
<folder>views</folder>
|
||||||
<folder>language</folder>
|
<folder>language</folder>
|
||||||
</files>
|
</files>
|
||||||
</administration>
|
</administration>
|
||||||
|
|
||||||
<!-- Extension Update Specification -->
|
<!-- Extension Update Specification -->
|
||||||
<updateservers>
|
<updateservers>
|
||||||
<server type="extension">https://raw.github.com/ianmacl/patchtester/master/updates/patchtester.xml</server>
|
<server type="extension">https://raw.github.com/ianmacl/patchtester/master/updates/patchtester.xml</server>
|
||||||
</updateservers>
|
</updateservers>
|
||||||
|
|
||||||
</extension>
|
</extension>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
CREATE TABLE IF NOT EXISTS `#__tests` (
|
CREATE TABLE IF NOT EXISTS `#__patchtester_tests` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`pull_id` int(11) NOT NULL,
|
`pull_id` int(11) NOT NULL,
|
||||||
`data` text NOT NULL,
|
`data` longtext NOT NULL,
|
||||||
`patched_by` int(11) NOT NULL,
|
`patched_by` int(11) NOT NULL,
|
||||||
`applied` int(11) NOT NULL,
|
`applied` int(11) NOT NULL,
|
||||||
`applied_version` varchar(25) NOT NULL,
|
`applied_version` varchar(25) NOT NULL,
|
||||||
|
@ -1 +1 @@
|
|||||||
DROP TABLE IF EXISTS `#__tests`
|
DROP TABLE IF EXISTS `#__patchtester_tests`
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// No direct access
|
// No direct access
|
||||||
@ -11,17 +11,17 @@ defined('_JEXEC') or die;
|
|||||||
/**
|
/**
|
||||||
* Tests Table class
|
* Tests Table class
|
||||||
*
|
*
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
*/
|
*/
|
||||||
class PatchtesterTableTests extends JTable
|
class PatchtesterTableTests extends JTable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param JDatabase A database connector object
|
* @param JDatabase $db A database connector object
|
||||||
*/
|
*/
|
||||||
public function __construct(&$db)
|
public function __construct(&$db)
|
||||||
{
|
{
|
||||||
parent::__construct('#__tests', 'id', $db);
|
parent::__construct('#__patchtester_tests', 'id', $db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package PatchTester
|
* @package PatchTester
|
||||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// No direct access
|
// No direct access
|
||||||
@ -13,7 +13,7 @@ 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
|
||||||
*/
|
*/
|
||||||
class PatchtesterViewPulls extends JView
|
class PatchtesterViewPulls extends JView
|
||||||
{
|
{
|
||||||
@ -25,12 +25,13 @@ class PatchtesterViewPulls extends JView
|
|||||||
*/
|
*/
|
||||||
public function display($tpl = null)
|
public function display($tpl = null)
|
||||||
{
|
{
|
||||||
$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');
|
||||||
|
|
||||||
// Check for errors.
|
// Check for errors.
|
||||||
if (count($errors = $this->get('Errors'))) {
|
if (count($errors = $this->get('Errors')))
|
||||||
|
{
|
||||||
JError::raiseError(500, implode("\n", $errors));
|
JError::raiseError(500, implode("\n", $errors));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
rm -rf site
|
rm -rf site
|
||||||
rm -rf admin
|
rm -rf admin
|
||||||
rm -rf ../patchtester.tar.bz2
|
rm -rf ../patchtester.tar.bz2
|
||||||
@ -6,6 +7,7 @@ cp -r ../components/com_patchtester site
|
|||||||
rm -rf admin/backups/*.txt
|
rm -rf admin/backups/*.txt
|
||||||
mv admin/patchtester.xml patchtester.xml
|
mv admin/patchtester.xml patchtester.xml
|
||||||
tar jcf ../com_patchtester.tar.bz2 site admin patchtester.xml
|
tar jcf ../com_patchtester.tar.bz2 site admin patchtester.xml
|
||||||
|
tar zcf ../com_patchtester.tar.gz site admin patchtester.xml
|
||||||
|
|
||||||
rm -rf github
|
rm -rf github
|
||||||
mkdir github
|
mkdir github
|
||||||
@ -15,5 +17,7 @@ cp ../libraries/joomla/client/curl.php github
|
|||||||
cp -r ../libraries/joomla/client/github github
|
cp -r ../libraries/joomla/client/github github
|
||||||
cp github.xml github
|
cp github.xml github
|
||||||
tar jcf ../file_github.tar.bz2 github/*
|
tar jcf ../file_github.tar.bz2 github/*
|
||||||
|
tar zcf ../file_github.tar.gz github/*
|
||||||
|
|
||||||
tar jcf ../pkg_patchtester.tar.bz2 pkg_patchtester.xml ../com_patchtester.tar.bz2 ../file_github.tar.bz2
|
tar jcf ../pkg_patchtester.tar.bz2 pkg_patchtester.xml ../com_patchtester.tar.bz2 ../file_github.tar.bz2
|
||||||
|
tar zcf ../pkg_patchtester.tar.gz pkg_patchtester_gz.xml ../com_patchtester.tar.gz ../file_github.tar.gz
|
||||||
|
Loading…
Reference in New Issue
Block a user