31
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-06-03 14:10:47 +00:00

Added a validation in revert method to check if a directory is empty and remove it after reverting patch.

This commit is contained in:
Sebastian Enns 2019-09-09 21:38:23 +02:00
parent 690a3c7cd0
commit 82befbe554

View File

@ -174,7 +174,7 @@ class PullModel extends AbstractModel
*
* @throws \RuntimeException
*/
public function applyWithCIServer($id)
private function applyWithCIServer($id)
{
// Get the CIServer Registry
$ciSettings = Helper::initializeCISettings();
@ -232,7 +232,7 @@ class PullModel extends AbstractModel
// Get a list of files from folder and deleted.log
$files = $this->getListOfFiles($tempPath);
// ToDo add deleted files to fileList
// ToDo add deleted files loop
mkdir($backupsPath);
@ -362,7 +362,7 @@ class PullModel extends AbstractModel
*
* @throws \RuntimeException
*/
public function applyWithGitHub($id)
private function applyWithGitHub($id)
{
// Get the Github object
$github = Helper::initializeGithub();
@ -546,7 +546,7 @@ class PullModel extends AbstractModel
*
* @since 3.0
*/
public function saveAppliedPatch($id, $fileList, $sha = null)
private function saveAppliedPatch($id, $fileList, $sha = null)
{
$record = (object) array(
'pull_id' => $id,
@ -609,7 +609,7 @@ class PullModel extends AbstractModel
* @since 3.0
* @throws \RuntimeException
*/
public function revertWithCIServer($id)
private function revertWithCIServer($id)
{
// Get the CIServer Registry
$ciSettings = Helper::initializeCISettings();
@ -636,8 +636,18 @@ class PullModel extends AbstractModel
// Delete file from root of it exists
if (file_Exists(JPATH_ROOT . "/$file"))
{
$filePath = explode("/", $file);
array_pop($filePath);
$filePath = implode("/", $filePath);
unlink(JPATH_ROOT . "/$file");
// If folder is empty, remove it as well
if (count(glob(JPATH_ROOT . "/$filePath/*")) === 0)
{
rmdir(JPATH_ROOT . "/$filePath");
}
// Move from backup, if it exists there
if (file_exists("$backupsPath/$file"))
{
@ -670,7 +680,7 @@ class PullModel extends AbstractModel
* @since 2.0
* @throws \RuntimeException
*/
public function revertWithGitHub($id)
private function revertWithGitHub($id)
{
$testRecord = $this->getTestRecord($id);