2014-05-03 23:48:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Patch testing component for the Joomla! CMS
|
|
|
|
*
|
2015-02-22 21:29:43 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2015 Open Source Matters, Inc. All rights reserved.
|
2014-05-03 23:48:08 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PatchTester\Controller;
|
|
|
|
|
|
|
|
use PatchTester\Model\PullsModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller class to fetch remote data
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2014-10-17 11:32:48 +00:00
|
|
|
class FetchController extends DisplayController
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Execute the controller.
|
|
|
|
*
|
|
|
|
* @return void Redirects the application
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
// We don't want this request to be cached.
|
|
|
|
header('Pragma: no-cache');
|
|
|
|
header('Cache-Control: no-cache');
|
|
|
|
header('Expires: -1');
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
try
|
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
// Fetch our page from the session
|
|
|
|
$page = \JFactory::getSession()->get('com_patchtester_fetcher_page', 1);
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
// TODO - Decouple the model and context?
|
2015-02-16 21:35:49 +00:00
|
|
|
$model = new PullsModel('com_patchtester.fetch', null, \JFactory::getDbo());
|
2014-10-17 11:32:48 +00:00
|
|
|
|
|
|
|
// Initialize the state for the model
|
|
|
|
$model->setState($this->initializeState($model));
|
|
|
|
|
2015-02-23 01:49:59 +00:00
|
|
|
$status = $model->requestFromGithub($page);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
catch (\Exception $e)
|
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
$response = new \JResponseJson($e);
|
|
|
|
|
|
|
|
echo json_encode($response);
|
|
|
|
|
|
|
|
$this->getApplication()->close(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the UI and session now
|
|
|
|
if (isset($status['page']))
|
|
|
|
{
|
|
|
|
\JFactory::getSession()->set('com_patchtester_fetcher_page', $status['page']);
|
|
|
|
$message = \JText::sprintf('COM_PATCHTESTER_FETCH_PAGE_NUMBER', $status['page']);
|
|
|
|
unset($status['page']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$status['header'] = \JText::_('COM_PATCHTESTER_FETCH_SUCCESSFUL', true);
|
|
|
|
$message = \JText::_('COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW', true);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 01:49:59 +00:00
|
|
|
$response = new \JResponseJson($status, $message, false, true);
|
|
|
|
|
|
|
|
echo json_encode($response);
|
|
|
|
|
|
|
|
$this->getApplication()->close();
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
}
|