33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-12-22 19:09:00 +00:00

Add J! 3.0 compat and pagination

This commit is contained in:
Nikolai Plath 2012-09-08 20:53:44 -05:00
parent b44df81fd3
commit 227109ed4b
12 changed files with 258 additions and 174 deletions

View File

@ -13,7 +13,7 @@ defined('_JEXEC') or die;
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchTesterController extends JController class PatchTesterController extends JControllerLegacy
{ {
protected $default_view = 'Pulls'; protected $default_view = 'Pulls';

View File

@ -15,17 +15,17 @@ jimport('joomla.application.component.controllerform');
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchtesterControllerPull extends JController class PatchtesterControllerPull extends JControllerLegacy
{ {
public function apply() public function apply()
{ {
try try
{ {
$this->getModel('pull') $this->getModel('pull')
->apply(JRequest::getVar('pull_id')); ->apply(JFactory::getApplication()->input->getInt('pull_id'));
$msg = JText::_('COM_PATCHTESTER_APPLY_OK'); $msg = JText::_('COM_PATCHTESTER_APPLY_OK');
$type = 'message'; $type = 'success';
} }
catch (Exception $e) catch (Exception $e)
{ {
@ -41,10 +41,10 @@ class PatchtesterControllerPull extends JController
try try
{ {
$this->getModel('pull') $this->getModel('pull')
->revert(JRequest::getVar('pull_id')); ->revert(JFactory::getApplication()->input->getInt('pull_id'));
$msg = JText::_('COM_PATCHTESTER_REVERT_OK'); $msg = JText::_('COM_PATCHTESTER_REVERT_OK');
$type = 'message'; $type = 'success';
} }
catch (Exception $e) catch (Exception $e)
{ {

View File

@ -37,7 +37,7 @@ class PTCurl extends JURI
* *
* @throws Exception * @throws Exception
* *
* @return JCurl * @return PTCurl
*/ */
public static function getAdapter($uri = null) public static function getAdapter($uri = null)
{ {
@ -72,7 +72,7 @@ class PTCurl extends JURI
* *
* @param array $options The cURL options. * @param array $options The cURL options.
* *
* @return JCurl * @return PTCurl
*/ */
public function setOptions($options) public function setOptions($options)
{ {
@ -94,7 +94,7 @@ class PTCurl extends JURI
curl_setopt_array($ch, $this->curlOptions); curl_setopt_array($ch, $this->curlOptions);
curl_setopt($ch, CURLOPT_URL, $this->_uri); curl_setopt($ch, CURLOPT_URL, $this->uri);
if ( ! array_key_exists(CURLOPT_SSL_VERIFYHOST, $this->curlOptions)) if ( ! array_key_exists(CURLOPT_SSL_VERIFYHOST, $this->curlOptions))
{ {

View File

@ -0,0 +1,35 @@
<?php
/**
* User: elkuku
* Date: 08.09.12
* Time: 19:08
*
* @property-read PtGithubRepos $repos GitHub API object for repos.
*/
class PtGithub extends JGithub
{
/**
* @var PtGithubRepos
*/
protected $repos;
public static function getInstance(JRegistry $options = null, JGithubHttp $client = null)
{
return new PtGithub($options, $client);
}
public function __get($name)
{
if ($name == 'repos')
{
if ($this->repos == null)
{
$this->repos = new PtGithubRepos($this->options, $this->client);
}
return $this->repos;
}
return parent::__get($name);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* User: elkuku
* Date: 08.09.12
* Time: 18:54
*/
/**
* A.
*/
class PtGithubRepos extends JGithubObject
{
public function get($user, $repo)
{
$path = '/repos/'.$user.'/'.$repo;
// 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);
}
/**
* @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

@ -12,7 +12,7 @@ defined('_JEXEC') or die;
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchtesterModelPull extends JModel class PatchtesterModelPull extends JModelLegacy
{ {
/** /**
* Method to auto-populate the model state. * Method to auto-populate the model state.
@ -92,7 +92,7 @@ class PatchtesterModelPull extends JModel
public function apply($id) public function apply($id)
{ {
//@todo Use the JCurl class //@todo Use the JCurl class
require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/curl.php'; // require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/curl.php';
$table = JTable::getInstance('tests', 'PatchTesterTable'); $table = JTable::getInstance('tests', 'PatchTesterTable');
$github = new JGithub; $github = new JGithub;
@ -195,11 +195,6 @@ class PatchtesterModelPull extends JModel
if ($table->applied_version != $version->getShortVersion()) if ($table->applied_version != $version->getShortVersion())
{ {
/*
$table->applied = 0;
$table->applied_version = '';
$table->store();
*/
$table->delete(); $table->delete();
return $this; return $this;
@ -249,11 +244,6 @@ class PatchtesterModelPull extends JModel
} }
} }
/*
$table->applied_version = '';
$table->applied = 0;
$table->store();
*/
$table->delete(); $table->delete();
return true; return true;

View File

@ -57,15 +57,18 @@ 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');
//-- GitHubs default list limit is 30
$this->state->set('list.limit', 30);
} }
/** /**
@ -111,10 +114,12 @@ class PatchtesterModelPulls extends JModelList
$search = $this->getState('filter.search'); $search = $this->getState('filter.search');
$searchId = $this->getState('filter.searchid'); $searchId = $this->getState('filter.searchid');
$page = $this->getPagination()->pagesCurrent;
try try
{ {
$github = new JGithub(); $github = new JGithub;
$pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo')); $pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'), 'open', $page);
usort($pulls, array($this, 'sortItems')); usort($pulls, array($this, 'sortItems'));
foreach ($pulls as $i => &$pull) foreach ($pulls as $i => &$pull)
@ -180,4 +185,17 @@ class PatchtesterModelPulls extends JModelList
return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number; return ($this->orderDir == 'asc') ? $b->number < $a->number : $b->number > $a->number;
} }
} }
public function getTotal()
{
// $g = new PtGithub;
//$repo = $g->repos->get('joomla', 'joomla-cms');
return PtGithub::getInstance()
->repos->get('joomla', 'joomla-cms')
->open_issues_count;
//return $repo->open_issues_count;
}
} }

View File

@ -16,8 +16,10 @@ if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester'))
} }
// Include dependencies // Include dependencies
jimport('joomla.application.component.controller'); //jimport('joomla.application.component.controller');
$controller = JController::getInstance('PatchTester'); JLoader::registerPrefix('Pt', __DIR__.'/helpers');
$controller = JControllerLegacy::getInstance('PatchTester');
$controller->execute(JRequest::getCmd('task')); $controller->execute(JRequest::getCmd('task'));
$controller->redirect(); $controller->redirect();

View File

@ -8,7 +8,7 @@
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> <license>GNU General Public License version 2 or later; see LICENSE.txt</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.1</version> <version>1.2</version>
<description>COM_PATCHTESTER_XML_DESCRIPTION</description> <description>COM_PATCHTESTER_XML_DESCRIPTION</description>
<install> <install>
<sql> <sql>
@ -26,22 +26,22 @@
<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">
<folder>assets</folder> <folder>assets</folder>
<folder>backups</folder> <folder>backups</folder>
<folder>controllers</folder> <folder>controllers</folder>
<folder>helpers</folder> <folder>helpers</folder>
<folder>install</folder> <folder>install</folder>
<folder>language</folder> <folder>language</folder>
<folder>models</folder> <folder>models</folder>
<folder>tables</folder> <folder>tables</folder>
<folder>views</folder> <folder>views</folder>
<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>
</files> </files>
</administration> </administration>
<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>

View File

@ -24,51 +24,30 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<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">
<table class="adminlist">
<div>
<button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button" class="btn"
onclick="document.id('filter_search').value='';document.id('filter_searchid').value='';this.form.submit();">
<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
</button>
</div>
<table class="table table-striped table-hover table-condensed">
<thead> <thead>
<tr> <tr>
<th colspan="7" style="text-align: left;"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></th> <th width="8%">
</tr> <?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
<tr> <br />
<td> <input type="text" name="filter_searchid" id="filter_searchid" class="span10"
<button type="submit"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button> value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>" />
<button type="button" </th>
onclick="document.id('filter_search').value='';document.id('filter_searchid').value='';this.form.submit();">
<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
</button>
</td>
<td>
<label class="filter-search-lbl"
for="filter_searchid"><?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_PULL_ID'); ?></label>
<input type="text" name="filter_searchid" id="filter_searchid" size="5"
value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>"
title="<?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_PULL_ID'); ?>"/>
</td>
<td>
<label class="filter-search-lbl"
for="filter_search"><?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_TITLE'); ?></label>
<br/>
<input type="text" name="filter_search" id="filter_search"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>"
title="<?php echo JText::_('COM_PATCHTESTER_SEARCH_IN_TITLE'); ?>"/>
</td>
<td colspan="4">
</td>
</tr>
<tr>
<th colspan="7" style="text-align: left;"><?php echo JText::_('COM_PATCHTESTER_SORT'); ?></th>
</tr>
<tr>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value=""
title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)"/>
</th>
<th width="5%">
<?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
</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); ?>
</th> <br />
<input type="text" name="filter_search" id="filter_search"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>" />
</th>
<th>I</th> <th>I</th>
<th class="title"> <th class="title">
<?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?> <?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?>
@ -82,17 +61,20 @@ $listDirn = $this->escape($this->state->get('list.direction'));
</tr> </tr>
</thead> </thead>
<tfoot> <tfoot>
<tr> <tr>
<td colspan="10"> <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> <?php echo $this->pagination->getListFooter(); ?>
</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=""/>

View File

@ -8,82 +8,75 @@
// No direct access // No direct access
defined('_JEXEC') or die; defined('_JEXEC') or die;
foreach ($this->items as $i => $item) : foreach($this->items as $i => $item) :
if (isset($this->patches[$item->number])) : $status = '';
$patch = $this->patches[$item->number]; if(isset($this->patches[$item->number])) :
else : $patch = $this->patches[$item->number];
$patch = false; $status = ($patch->applied) ? 'success' : '';
endif; else :
?> $patch = false;
<tr class="row<?php echo $i % 2; ?>"> endif;
<td class="center"> ?>
<?php echo JHtml::_('grid.id', $i, $item->id); ?> <tr class="<?= $status ?>">
</td> <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'); ?>"
title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>" href="<?php echo $item->html_url; ?>">
href="<?php echo $item->html_url; ?>"> <?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;'; endif;
endif; ?>
?> </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>';
} }
} }
?> ?>
</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 :
} echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
else endif;
{ ?>
echo JText::_('COM_PATCHTESTER_NOT_APPLIED'); </td>
} <td class="center">
?> <?php
</td> if($patch && $patch->applied) :
<td class="center"> echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>';
<?php else :
if ($patch && $patch->applied) echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>';
{ endif;
echo '<a href="javascript:submitpatch(\'pull.revert\', ' . (int) $patch->id . ');">' . JText::_('COM_PATCHTESTER_REVERT_PATCH') . '</a>'; ?>
} </td>
else
{
echo '<a href="javascript:submitpatch(\'pull.apply\', ' . (int) $item->number . ');">' . JText::_('COM_PATCHTESTER_APPLY_PATCH') . '</a>';
}
?>
</td>
</tr> </tr>
<?php endforeach; <?php endforeach;

View File

@ -15,10 +15,11 @@ jimport('joomla.application.component.view');
* *
* @package PatchTester * @package PatchTester
*/ */
class PatchtesterViewPulls extends JView class PatchtesterViewPulls extends JViewLegacy
{ {
protected $items; protected $items;
protected $state; protected $state;
protected $pagination;
/** /**
* Display the view * Display the view
@ -53,12 +54,17 @@ class PatchtesterViewPulls extends JView
$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');
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) $errors = $this->get('Errors');
if (count($errors))
{ {
JError::raiseError(500, implode("\n", $errors)); var_dump($errors);
return false; var_dump($this->pagination);
// JError::raiseError(500, implode("\n", $errors));
// return false;
} }
$this->addToolbar(); $this->addToolbar();