2011-10-11 13:02:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-03 23:48:08 +00:00
|
|
|
* Patch testing component for the Joomla! CMS
|
2013-07-13 02:26:21 +00:00
|
|
|
*
|
2016-02-20 16:35:10 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2016 Open Source Matters, Inc. All rights reserved.
|
2013-07-13 02:26:21 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
namespace PatchTester\Model;
|
2011-10-11 13:02:57 +00:00
|
|
|
|
2014-05-03 02:02:38 +00:00
|
|
|
use Joomla\Registry\Registry;
|
|
|
|
|
2016-06-25 16:34:48 +00:00
|
|
|
use PatchTester\GitHub\Exception\UnexpectedResponse;
|
2014-05-03 23:48:08 +00:00
|
|
|
use PatchTester\Helper;
|
|
|
|
|
2011-10-11 13:02:57 +00:00
|
|
|
/**
|
|
|
|
* Methods supporting pull requests.
|
|
|
|
*
|
2014-05-03 23:48:08 +00:00
|
|
|
* @since 2.0
|
2011-10-11 13:02:57 +00:00
|
|
|
*/
|
2016-02-20 16:54:55 +00:00
|
|
|
class PullModel extends \JModelDatabase
|
2011-10-11 13:02:57 +00:00
|
|
|
{
|
2013-07-28 17:44:05 +00:00
|
|
|
/**
|
|
|
|
* Array containing top level non-production folders
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2016-07-30 20:09:04 +00:00
|
|
|
protected $nonProductionFolders = array(
|
|
|
|
'build',
|
|
|
|
'docs',
|
|
|
|
'installation',
|
|
|
|
'tests',
|
|
|
|
'.github',
|
|
|
|
);
|
2016-03-27 09:59:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array containing non-production files
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected $nonProductionFiles = array(
|
|
|
|
'.gitignore',
|
|
|
|
'.travis.yml',
|
|
|
|
'README.md',
|
|
|
|
'build.xml',
|
|
|
|
'composer.json',
|
|
|
|
'composer.lock',
|
|
|
|
'phpunit.xml.dist',
|
|
|
|
'robots.txt.dist',
|
|
|
|
'travisci-phpunit.xml',
|
2016-07-30 20:09:04 +00:00
|
|
|
'LICENSE',
|
|
|
|
'RoboFile.dist.ini',
|
|
|
|
'RoboFile.php',
|
|
|
|
'codeception.yml',
|
|
|
|
'jorobo.dist.ini',
|
|
|
|
'manifest.xml',
|
|
|
|
'crowdin.yaml',
|
|
|
|
'travis-lang-update.sh',
|
2016-03-27 09:59:48 +00:00
|
|
|
);
|
2013-07-28 17:44:05 +00:00
|
|
|
|
2013-07-13 02:26:21 +00:00
|
|
|
/**
|
2016-06-25 17:28:29 +00:00
|
|
|
* Parse the list of modified files from a pull request
|
2013-07-13 02:26:21 +00:00
|
|
|
*
|
2016-06-25 17:28:29 +00:00
|
|
|
* @param object $files The modified files to parse
|
2013-07-13 02:26:21 +00:00
|
|
|
*
|
2016-06-25 17:28:29 +00:00
|
|
|
* @return array
|
2013-07-13 02:26:21 +00:00
|
|
|
*
|
2016-06-25 17:46:15 +00:00
|
|
|
* @since 3.0.0
|
2013-07-13 02:26:21 +00:00
|
|
|
*/
|
2016-06-25 17:28:29 +00:00
|
|
|
protected function parseFileList($files)
|
2011-10-11 20:51:12 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
$parsedFiles = array();
|
2011-10-11 20:51:12 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
foreach ($files as $file)
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
/*
|
|
|
|
* Check if the patch tester is running in a production environment
|
|
|
|
* If so, do not patch certain files as errors will be thrown
|
|
|
|
*/
|
|
|
|
if (!file_exists(JPATH_ROOT . '/installation/index.php'))
|
2011-10-11 20:51:12 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
$filePath = explode('/', $file->filename);
|
2013-07-28 17:44:05 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
if (in_array($filePath[0], $this->nonProductionFiles))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-07-13 02:26:21 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
if (in_array($filePath[0], $this->nonProductionFolders))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2011-10-11 20:51:12 +00:00
|
|
|
}
|
2016-06-25 17:28:29 +00:00
|
|
|
|
2016-07-30 20:12:36 +00:00
|
|
|
// Sometimes the repo filename is not the production file name
|
2016-07-31 08:45:42 +00:00
|
|
|
$prodFileName = $file->filename;
|
|
|
|
$filePath = explode('/', $prodFileName);
|
2016-07-30 20:09:04 +00:00
|
|
|
|
2016-07-30 20:12:36 +00:00
|
|
|
// Remove the `src` here to match the CMS paths if needed
|
2016-07-30 20:09:04 +00:00
|
|
|
if ($filePath[0] === 'src')
|
|
|
|
{
|
2016-07-31 08:45:42 +00:00
|
|
|
$prodFileName = str_replace('src/', '', $prodFileName);
|
2016-07-30 20:09:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
$parsedFiles[] = (object) array(
|
2016-07-30 20:09:04 +00:00
|
|
|
'action' => $file->status,
|
2016-07-31 08:45:42 +00:00
|
|
|
'filename' => $prodFileName,
|
2016-07-30 20:12:36 +00:00
|
|
|
'repofilename' => $file->filename,
|
2016-07-30 20:09:04 +00:00
|
|
|
'fileurl' => $file->contents_url,
|
2016-06-25 17:28:29 +00:00
|
|
|
);
|
2011-10-11 20:51:12 +00:00
|
|
|
}
|
2013-07-13 02:26:21 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
return $parsedFiles;
|
2011-10-11 20:51:12 +00:00
|
|
|
}
|
|
|
|
|
2013-07-13 02:26:21 +00:00
|
|
|
/**
|
|
|
|
* Patches the code with the supplied pull request
|
|
|
|
*
|
|
|
|
* @param integer $id ID of the pull request to apply
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*
|
2014-05-03 23:48:08 +00:00
|
|
|
* @since 2.0
|
|
|
|
* @throws \RuntimeException
|
2013-07-13 02:26:21 +00:00
|
|
|
*/
|
2011-10-11 13:02:57 +00:00
|
|
|
public function apply($id)
|
|
|
|
{
|
2014-05-03 01:56:15 +00:00
|
|
|
// Get the Github object
|
2014-05-03 23:48:08 +00:00
|
|
|
$github = Helper::initializeGithub();
|
2015-05-09 17:00:55 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2016-06-25 16:34:48 +00:00
|
|
|
$rateResponse = $github->getRateLimit();
|
|
|
|
$rate = json_decode($rateResponse->body);
|
2015-05-09 17:00:55 +00:00
|
|
|
}
|
2016-06-25 16:34:48 +00:00
|
|
|
catch (UnexpectedResponse $e)
|
2015-05-09 17:00:55 +00:00
|
|
|
{
|
2015-06-16 19:14:41 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e);
|
2015-05-09 17:00:55 +00:00
|
|
|
}
|
2014-05-03 01:56:15 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
// If over the API limit, we can't build this list
|
|
|
|
if ($rate->resources->core->remaining == 0)
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2015-02-23 00:04:22 +00:00
|
|
|
throw new \RuntimeException(
|
|
|
|
\JText::sprintf('COM_PATCHTESTER_API_LIMIT_LIST', \JFactory::getDate($rate->resources->core->reset))
|
|
|
|
);
|
|
|
|
}
|
2011-10-11 20:51:12 +00:00
|
|
|
|
2015-05-09 16:35:36 +00:00
|
|
|
try
|
|
|
|
{
|
2016-06-25 16:34:48 +00:00
|
|
|
$pullResponse = $github->getPullRequest($this->getState()->get('github_user'), $this->getState()->get('github_repo'), $id);
|
|
|
|
$pull = json_decode($pullResponse->body);
|
2015-05-09 16:35:36 +00:00
|
|
|
}
|
2016-06-25 16:34:48 +00:00
|
|
|
catch (UnexpectedResponse $e)
|
2015-05-09 16:35:36 +00:00
|
|
|
{
|
2015-06-16 19:14:41 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e);
|
2015-05-09 16:35:36 +00:00
|
|
|
}
|
2011-10-11 13:02:57 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
if (is_null($pull->head->repo))
|
|
|
|
{
|
|
|
|
throw new \RuntimeException(\JText::_('COM_PATCHTESTER_REPO_IS_GONE'));
|
|
|
|
}
|
2014-05-03 01:56:15 +00:00
|
|
|
|
2015-05-09 16:35:36 +00:00
|
|
|
try
|
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
$filesResponse = $github->getFilesForPullRequest($this->getState()->get('github_user'), $this->getState()->get('github_repo'), $id);
|
|
|
|
$files = json_decode($filesResponse->body);
|
2015-05-09 16:35:36 +00:00
|
|
|
}
|
2016-06-25 16:34:48 +00:00
|
|
|
catch (UnexpectedResponse $e)
|
2015-05-09 16:35:36 +00:00
|
|
|
{
|
2015-06-16 19:14:41 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e);
|
2015-05-09 16:35:36 +00:00
|
|
|
}
|
2011-10-11 20:51:12 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
if (!count($files))
|
2015-02-23 00:04:22 +00:00
|
|
|
{
|
2015-02-23 13:50:13 +00:00
|
|
|
return false;
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2013-07-28 17:44:05 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
$parsedFiles = $this->parseFileList($files);
|
|
|
|
|
|
|
|
foreach ($parsedFiles as $file)
|
2015-02-23 00:04:22 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
if ($file->action == 'deleted' && !file_exists(JPATH_ROOT . '/' . $file->filename))
|
2015-02-23 00:04:22 +00:00
|
|
|
{
|
2015-05-09 16:35:36 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S', $file->old));
|
2013-07-28 17:44:05 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
if ($file->action == 'added' || $file->action == 'modified')
|
2013-07-13 00:31:00 +00:00
|
|
|
{
|
2015-02-23 00:04:22 +00:00
|
|
|
// If the backup file already exists, we can't apply the patch
|
2016-06-25 17:28:29 +00:00
|
|
|
if (file_exists(JPATH_COMPONENT . '/backups/' . md5($file->filename) . '.txt'))
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_CONFLICT_S', $file->filename));
|
2011-10-11 20:51:12 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
if ($file->action == 'modified' && !file_exists(JPATH_ROOT . '/' . $file->filename))
|
2013-07-13 00:31:00 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S', $file->filename));
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2011-10-11 20:51:12 +00:00
|
|
|
|
2015-05-09 16:35:36 +00:00
|
|
|
try
|
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
$contentsResponse = $github->getFileContents(
|
2016-07-30 20:09:04 +00:00
|
|
|
$pull->head->user->login, $this->getState()->get('github_repo'), $file->repofilename, urlencode($pull->head->ref)
|
2016-06-25 17:28:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$contents = json_decode($contentsResponse->body);
|
|
|
|
|
|
|
|
// In case encoding type ever changes
|
|
|
|
switch ($contents->encoding)
|
|
|
|
{
|
|
|
|
case 'base64':
|
|
|
|
$file->body = base64_decode($contents->content);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \RuntimeException(\JText::_('COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING'));
|
|
|
|
}
|
2015-05-09 16:35:36 +00:00
|
|
|
}
|
2016-06-25 17:28:29 +00:00
|
|
|
catch (UnexpectedResponse $e)
|
2015-05-09 16:35:36 +00:00
|
|
|
{
|
2015-06-16 19:14:41 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e);
|
2015-05-09 16:35:36 +00:00
|
|
|
}
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2011-10-11 13:02:57 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
jimport('joomla.filesystem.file');
|
2016-06-25 16:34:48 +00:00
|
|
|
jimport('joomla.filesystem.path');
|
2013-07-13 00:31:00 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
// At this point, we have ensured that we have all the new files and there are no conflicts
|
2016-06-25 17:28:29 +00:00
|
|
|
foreach ($parsedFiles as $file)
|
2015-02-23 00:04:22 +00:00
|
|
|
{
|
|
|
|
// We only create a backup if the file already exists
|
2016-06-25 17:28:29 +00:00
|
|
|
if ($file->action == 'deleted' || (file_exists(JPATH_ROOT . '/' . $file->filename) && $file->action == 'modified'))
|
2011-10-11 20:51:12 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
$src = JPATH_ROOT . '/' . $file->filename;
|
|
|
|
$dest = JPATH_COMPONENT . '/backups/' . md5($file->filename) . '.txt';
|
|
|
|
|
|
|
|
if (!\JFile::copy(\JPath::clean($src), $dest))
|
2013-07-13 00:31:00 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE', $src, $dest));
|
2013-07-13 00:31:00 +00:00
|
|
|
}
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2011-10-11 20:51:12 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
switch ($file->action)
|
|
|
|
{
|
|
|
|
case 'modified':
|
|
|
|
case 'added':
|
2016-06-25 17:28:29 +00:00
|
|
|
if (!\JFile::write(\JPath::clean(JPATH_ROOT . '/' . $file->filename), $file->body))
|
2015-02-23 00:04:22 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_WRITE_FILE', JPATH_ROOT . '/' . $file->filename));
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2013-07-13 02:26:21 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
break;
|
2013-07-13 00:31:00 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
case 'deleted':
|
2016-06-25 17:28:29 +00:00
|
|
|
if (!\JFile::delete(\JPath::clean(JPATH_ROOT . '/' . $file->filename)))
|
2015-02-23 00:04:22 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', JPATH_ROOT . '/' . $file->filename));
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2013-07-13 02:26:21 +00:00
|
|
|
|
2015-02-23 00:04:22 +00:00
|
|
|
break;
|
2011-10-11 16:04:33 +00:00
|
|
|
}
|
2016-06-25 17:39:35 +00:00
|
|
|
|
|
|
|
// We don't need the file's body any longer (and it causes issues with binary data when json_encode() is run), so remove it
|
|
|
|
unset($file->body);
|
2015-02-23 00:04:22 +00:00
|
|
|
}
|
2011-10-15 01:13:59 +00:00
|
|
|
|
2016-06-19 15:06:59 +00:00
|
|
|
$record = (object) array(
|
|
|
|
'pull_id' => $pull->number,
|
2016-06-25 17:28:29 +00:00
|
|
|
'data' => json_encode($parsedFiles),
|
2016-06-19 15:06:59 +00:00
|
|
|
'patched_by' => \JFactory::getUser()->id,
|
|
|
|
'applied' => 1,
|
|
|
|
'applied_version' => JVERSION,
|
|
|
|
);
|
2011-10-15 01:13:59 +00:00
|
|
|
|
2016-03-27 18:01:31 +00:00
|
|
|
$db = $this->getDb();
|
2016-06-19 15:06:59 +00:00
|
|
|
|
|
|
|
$db->insertObject('#__patchtester_tests', $record);
|
|
|
|
|
|
|
|
// Insert the retrieved commit SHA into the pulls table for this item
|
2016-03-27 18:01:31 +00:00
|
|
|
$db->setQuery(
|
|
|
|
$db->getQuery(true)
|
|
|
|
->update('#__patchtester_pulls')
|
|
|
|
->set('sha = ' . $db->quote($pull->head->sha))
|
|
|
|
->where($db->quoteName('pull_id') . ' = ' . (int) $id)
|
|
|
|
)->execute();
|
|
|
|
|
2011-10-15 01:13:59 +00:00
|
|
|
return true;
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
|
|
|
|
2013-07-13 02:26:21 +00:00
|
|
|
/**
|
|
|
|
* Reverts the specified pull request
|
|
|
|
*
|
2016-03-11 16:36:53 +00:00
|
|
|
* @param integer $id ID of the pull request to revert
|
2013-07-13 02:26:21 +00:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*
|
2014-05-03 23:48:08 +00:00
|
|
|
* @since 2.0
|
|
|
|
* @throws \RuntimeException
|
2013-07-13 02:26:21 +00:00
|
|
|
*/
|
2011-10-11 13:02:57 +00:00
|
|
|
public function revert($id)
|
|
|
|
{
|
2016-06-19 15:06:59 +00:00
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
|
|
$testRecord = $db->setQuery(
|
|
|
|
$db->getQuery(true)
|
|
|
|
->select('*')
|
|
|
|
->from('#__patchtester_tests')
|
|
|
|
->where('id = ' . (int) $id)
|
|
|
|
)->loadObject();
|
2011-10-11 13:02:57 +00:00
|
|
|
|
2013-07-13 00:31:00 +00:00
|
|
|
// We don't want to restore files from an older version
|
2016-06-19 15:06:59 +00:00
|
|
|
if ($testRecord->applied_version != JVERSION)
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2016-06-19 15:06:59 +00:00
|
|
|
return $this->removeTest($testRecord);
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 15:06:59 +00:00
|
|
|
$files = json_decode($testRecord->data);
|
2011-10-11 13:02:57 +00:00
|
|
|
|
2012-06-12 18:42:45 +00:00
|
|
|
if (!$files)
|
|
|
|
{
|
2016-06-19 15:06:59 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_READING_DATABASE_TABLE', __METHOD__, htmlentities($testRecord->data)));
|
2012-06-12 18:42:45 +00:00
|
|
|
}
|
|
|
|
|
2013-07-13 00:31:00 +00:00
|
|
|
jimport('joomla.filesystem.file');
|
|
|
|
|
2012-06-12 18:42:45 +00:00
|
|
|
foreach ($files as $file)
|
|
|
|
{
|
|
|
|
switch ($file->action)
|
|
|
|
{
|
2011-10-11 20:51:12 +00:00
|
|
|
case 'deleted':
|
|
|
|
case 'modified':
|
2016-06-25 17:28:29 +00:00
|
|
|
$src = JPATH_COMPONENT . '/backups/' . md5($file->filename) . '.txt';
|
|
|
|
$dest = JPATH_ROOT . '/' . $file->filename;
|
|
|
|
|
|
|
|
if (!\JFile::copy($src, $dest))
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE', $src, $dest));
|
2011-10-15 01:13:59 +00:00
|
|
|
}
|
2012-06-12 18:42:45 +00:00
|
|
|
|
2016-06-25 17:28:29 +00:00
|
|
|
if (file_exists($src))
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
if (!\JFile::delete($src))
|
2015-05-09 17:24:57 +00:00
|
|
|
{
|
|
|
|
throw new \RuntimeException(
|
2016-06-25 17:28:29 +00:00
|
|
|
\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', $src)
|
2015-05-09 17:24:57 +00:00
|
|
|
);
|
|
|
|
}
|
2011-10-15 01:13:59 +00:00
|
|
|
}
|
2013-07-13 02:26:21 +00:00
|
|
|
|
2011-10-11 20:51:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'added':
|
2016-06-25 17:28:29 +00:00
|
|
|
$src = JPATH_ROOT . '/' . $file->filename;
|
|
|
|
|
|
|
|
if (file_exists($src))
|
2012-06-12 18:42:45 +00:00
|
|
|
{
|
2016-06-25 17:28:29 +00:00
|
|
|
if (!\JFile::delete($src))
|
2015-05-09 17:24:57 +00:00
|
|
|
{
|
|
|
|
throw new \RuntimeException(
|
2016-06-25 17:28:29 +00:00
|
|
|
\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', $src)
|
2015-05-09 17:24:57 +00:00
|
|
|
);
|
|
|
|
}
|
2011-10-15 01:13:59 +00:00
|
|
|
}
|
2013-07-13 02:26:21 +00:00
|
|
|
|
2011-10-11 20:51:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-11 13:02:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 15:06:59 +00:00
|
|
|
return $this->removeTest($testRecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the database record for a test
|
|
|
|
*
|
2016-06-19 16:07:53 +00:00
|
|
|
* @param stdClass $testRecord The record being deleted
|
2016-06-19 15:06:59 +00:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*
|
2016-06-25 17:46:15 +00:00
|
|
|
* @since 3.0.0
|
2016-06-19 15:06:59 +00:00
|
|
|
*/
|
|
|
|
private function removeTest($testRecord)
|
|
|
|
{
|
2016-03-27 18:01:31 +00:00
|
|
|
$db = $this->getDb();
|
2016-06-19 15:06:59 +00:00
|
|
|
|
|
|
|
// Remove the retrieved commit SHA from the pulls table for this item
|
2016-03-27 18:01:31 +00:00
|
|
|
$db->setQuery(
|
|
|
|
$db->getQuery(true)
|
|
|
|
->update('#__patchtester_pulls')
|
|
|
|
->set('sha = ' . $db->quote(''))
|
2016-06-19 15:06:59 +00:00
|
|
|
->where($db->quoteName('pull_id') . ' = ' . (int) $testRecord->pull_id)
|
2016-03-27 18:01:31 +00:00
|
|
|
)->execute();
|
|
|
|
|
|
|
|
// And delete the record from the tests table
|
2016-06-19 15:06:59 +00:00
|
|
|
$db->setQuery(
|
|
|
|
$db->getQuery(true)
|
|
|
|
->delete('#__patchtester_tests')
|
|
|
|
->where('id = ' . (int) $testRecord->id)
|
|
|
|
)->execute();
|
2011-10-11 13:02:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|