getApplication()->setHeader('Pragma: no-cache'); $this->getApplication()->setHeader('Cache-Control: no-cache'); $this->getApplication()->setHeader('Expires: -1'); $this->getApplication()->setHeader('Content-Type', $this->getApplication()->mimeType . '; charset=' . $this->getApplication()->charSet); try { // Fetch our page from the session $page = \JFactory::getSession()->get('com_patchtester_fetcher_page', 1); // TODO - Decouple the model and context? $model = new PullsModel('com_patchtester.fetch', null, \JFactory::getDbo()); // Initialize the state for the model $model->setState($this->initializeState($model)); $status = $model->requestFromGithub($page); } catch (\Exception $e) { $response = new \JResponseJson($e); $this->getApplication()->sendHeaders(); 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); } $response = new \JResponseJson($status, $message, false, true); $this->getApplication()->sendHeaders(); echo json_encode($response); $this->getApplication()->close(); } }