31
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-06-03 22:20:48 +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
*/
class PatchTesterController extends JController
class PatchTesterController extends JControllerLegacy
{
protected $default_view = 'Pulls';

View File

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

View File

@ -37,7 +37,7 @@ class PTCurl extends JURI
*
* @throws Exception
*
* @return JCurl
* @return PTCurl
*/
public static function getAdapter($uri = null)
{
@ -72,7 +72,7 @@ class PTCurl extends JURI
*
* @param array $options The cURL options.
*
* @return JCurl
* @return PTCurl
*/
public function setOptions($options)
{
@ -94,7 +94,7 @@ class PTCurl extends JURI
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))
{

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
*/
class PatchtesterModelPull extends JModel
class PatchtesterModelPull extends JModelLegacy
{
/**
* Method to auto-populate the model state.
@ -92,7 +92,7 @@ class PatchtesterModelPull extends JModel
public function apply($id)
{
//@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');
$github = new JGithub;
@ -195,11 +195,6 @@ class PatchtesterModelPull extends JModel
if ($table->applied_version != $version->getShortVersion())
{
/*
$table->applied = 0;
$table->applied_version = '';
$table->store();
*/
$table->delete();
return $this;
@ -249,11 +244,6 @@ class PatchtesterModelPull extends JModel
}
}
/*
$table->applied_version = '';
$table->applied = 0;
$table->store();
*/
$table->delete();
return true;

View File

@ -57,15 +57,18 @@ class PatchtesterModelPulls extends JModelList
$searchId = $this->getUserStateFromRequest($this->context . '.filter.searchid', 'filter_searchid');
$this->setState('filter.searchid', $searchId);
// Load the parameters.
$params = JComponentHelper::getParams('com_patchtester');
// Load the parameters.
$params = JComponentHelper::getParams('com_patchtester');
$this->setState('params', $params);
$this->setState('github_user', $params->get('org', 'joomla'));
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
$this->setState('params', $params);
$this->setState('github_user', $params->get('org', 'joomla'));
$this->setState('github_repo', $params->get('repo', 'joomla-cms'));
// List state information.
parent::populateState('number', 'desc');
// List state information.
parent::populateState('number', 'desc');
//-- 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');
$searchId = $this->getState('filter.searchid');
$page = $this->getPagination()->pagesCurrent;
try
{
$github = new JGithub();
$pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'));
$github = new JGithub;
$pulls = $github->pulls->getList($this->getState('github_user'), $this->getState('github_repo'), 'open', $page);
usort($pulls, array($this, 'sortItems'));
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;
}
}
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
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->redirect();

View File

@ -8,7 +8,7 @@
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>ianlenmac@gmail.com</authorEmail>
<authorUrl>http://github.com/ianmacl</authorUrl>
<version>1.1</version>
<version>1.2</version>
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
<install>
<sql>
@ -26,22 +26,22 @@
<administration>
<menu img="components/com_patchtester/assets/images/icon-16-patchtester.png">com_patchtester</menu>
<files folder="admin">
<folder>assets</folder>
<folder>backups</folder>
<folder>controllers</folder>
<folder>helpers</folder>
<folder>install</folder>
<folder>language</folder>
<folder>models</folder>
<folder>tables</folder>
<folder>views</folder>
<filename>access.xml</filename>
<filename>config.xml</filename>
<filename>controller.php</filename>
<filename>patchtester.php</filename>
<folder>assets</folder>
<folder>backups</folder>
<folder>controllers</folder>
<folder>helpers</folder>
<folder>install</folder>
<folder>language</folder>
<folder>models</folder>
<folder>tables</folder>
<folder>views</folder>
<filename>access.xml</filename>
<filename>config.xml</filename>
<filename>controller.php</filename>
<filename>patchtester.php</filename>
</files>
</administration>
<updateservers>
<server type="extension">https://raw.github.com/ianmacl/patchtester/master/updates/patchtester.xml</server>
</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"
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>
<tr>
<th colspan="7" style="text-align: left;"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></th>
</tr>
<tr>
<td>
<button type="submit"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button"
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 width="8%">
<?php echo JHtml::_('grid.sort', 'COM_PATCHTESTER_PULL_ID', 'number', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_searchid" id="filter_searchid" class="span10"
value="<?php echo $this->escape($this->state->get('filter.searchid')); ?>" />
</th>
<th class="title">
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
</th>
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'title', $listDirn, $listOrder); ?>
<br />
<input type="text" name="filter_search" id="filter_search"
value="<?php echo $this->escape($this->state->get('filter.search')); ?>" />
</th>
<th>I</th>
<th class="title">
<?php echo JText::_('COM_PATCHTESTER_JOOMLACODE_ISSUE'); ?>
@ -82,17 +61,20 @@ $listDirn = $this->escape($this->state->get('list.direction'));
</tr>
</thead>
<tfoot>
<tr>
<td colspan="10">
</td>
</tr>
<tr>
<td colspan="6">
</td>
</tr>
</tfoot>
<tbody>
<?php echo $this->loadTemplate('items'); ?>
</tbody>
</table>
<div class="well">
<div>
<?php echo $this->pagination->getListFooter(); ?>
</div>
<div>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="pull_id" id="pull_id" value=""/>

View File

@ -8,82 +8,75 @@
// No direct access
defined('_JEXEC') or die;
foreach ($this->items as $i => $item) :
if (isset($this->patches[$item->number])) :
$patch = $this->patches[$item->number];
else :
$patch = false;
endif;
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td class="center">
<?php echo $item->number; ?>
</td>
<td>
<a class="icon icon16-github hasTip"
title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>"
href="<?php echo $item->html_url; ?>">
<?php echo $item->title; ?>
</a>
</td>
<td>
<?php
if ($item->body) :
echo JHtml::_('tooltip', htmlspecialchars($item->body), 'Info');
else :
echo '&nbsp;';
endif;
?>
</td>
<td>
<?php
if ($item->joomlacode_issue)
{
$title = ' title="Open link::'.JText::_('COM_PATCHTESTER_OPEN_IN_JOOMLACODE').'"';
foreach($this->items as $i => $item) :
$status = '';
if(isset($this->patches[$item->number])) :
$patch = $this->patches[$item->number];
$status = ($patch->applied) ? 'success' : '';
else :
$patch = false;
endif;
?>
<tr class="<?= $status ?>">
<td class="center">
<?php echo $item->number; ?>
</td>
<td>
<a class="icon icon16-github hasTip"
title="<?php echo JText::_('COM_PATCHTESTER_OPEN_IN_GITHUB'); ?>"
href="<?php echo $item->html_url; ?>">
<?php echo $item->title; ?>
</a>
</td>
<td>
<?php
if($item->body) :
echo JHtml::_('tooltip', htmlspecialchars($item->body), 'Info');
else :
echo '&nbsp;';
endif;
?>
</td>
<td>
<?php
if($item->joomlacode_issue)
{
$title = ' title="Open link::'.JText::_('COM_PATCHTESTER_OPEN_IN_JOOMLACODE').'"';
if(is_int($item->joomlacode_issue))
{
echo '<a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=';
echo $item->joomlacode_issue . '"'.$title.' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#' . $item->joomlacode_issue . ']</a>';
}
else
{
echo '<a href="' . $item->joomlacode_issue . '"'.$title;
echo ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#joomlacode]</a>';
}
}
?>
</td>
<td class="center">
<?php
if ($patch && $patch->applied)
{
echo '<div class="patchApplied" style="background-color: #adff2f;">';
echo JText::_('COM_PATCHTESTER_APPLIED');
echo '</div>';
}
else
{
echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
}
?>
</td>
<td class="center">
<?php
if ($patch && $patch->applied)
{
echo '<a href="javascript:submitpatch(\'pull.revert\', ' . (int) $patch->id . ');">' . JText::_('COM_PATCHTESTER_REVERT_PATCH') . '</a>';
}
else
{
echo '<a href="javascript:submitpatch(\'pull.apply\', ' . (int) $item->number . ');">' . JText::_('COM_PATCHTESTER_APPLY_PATCH') . '</a>';
}
?>
</td>
if(is_int($item->joomlacode_issue))
{
echo '<a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=';
echo $item->joomlacode_issue.'"'.$title.' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#'.$item->joomlacode_issue.']</a>';
}
else
{
echo '<a href="'.$item->joomlacode_issue.'"'.$title;
echo ' class="modal hasTip" rel="{handler: \'iframe\', size: {x: 900, y: 500}}">';
echo '[#joomlacode]</a>';
}
}
?>
</td>
<td class="center">
<?php
if($patch && $patch->applied) :
echo '<div class="patchApplied" style="background-color: #adff2f;">';
echo JText::_('COM_PATCHTESTER_APPLIED');
echo '</div>';
else :
echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
endif;
?>
</td>
<td class="center">
<?php
if($patch && $patch->applied) :
echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>';
else :
echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>';
endif;
?>
</td>
</tr>
<?php endforeach;

View File

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