diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index 0f5c72d..4a2858a 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -79,9 +79,10 @@ abstract class Helper // Set name of the zip archive $options->set('zip.name', 'build.zip'); + $options->set('zip.deleted_log', 'deleted_files.log'); // Set temp archive for extracting and downloading files - $options->set('folder.temp', JPATH_COMPONENT . '/temp'); + $options->set('folder.temp', Factory::getConfig()->get('tmp_path')); $options->set('folder.backups', JPATH_COMPONENT . '/backups'); // Set full url for addressing the file diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 75a8a1e..3f1d300 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -8,12 +8,14 @@ namespace PatchTester\Model; +use Joomla\Archive\Zip; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\Path; use Joomla\CMS\Language\Text; use Joomla\CMS\Version; use Joomla\Filesystem\File; +use Joomla\Filesystem\Folder; use PatchTester\GitHub\Exception\UnexpectedResponse; use PatchTester\Helper; @@ -182,13 +184,14 @@ class PullModel extends AbstractModel // Create tmp folder if it does not exist if (!file_exists($ciSettings->get('folder.temp'))) { - mkdir($ciSettings->get('folder.temp')); + Folder::create($ciSettings->get('folder.temp')); } - $tempPath = $ciSettings->get('folder.temp') . "/$id"; - $backupsPath = $ciSettings->get('folder.backups') . "/$id"; - $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); - $serverPath = sprintf($ciSettings->get('zip.url'), $id); + $tempPath = $ciSettings->get('folder.temp') . "/$id"; + $backupsPath = $ciSettings->get('folder.backups') . "/$id"; + $deletedFilesPath = $tempPath . '/' . $ciSettings->get('zip.deleted_log'); + $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); + $serverPath = sprintf($ciSettings->get('zip.url'), $id); // Patch has already been applied if (file_exists($backupsPath)) @@ -201,69 +204,68 @@ class PullModel extends AbstractModel if (!$serverHeaders || $serverHeaders[0] != 'HTTP/1.1 200 OK') { - throw new \RuntimeException(Text::_('File does not exist on Server')); + throw new \RuntimeException(Text::_('COM_PATCHTESTER_SERVER_RESPONDED_NOT_200')); } - mkdir($tempPath); + Folder::create($tempPath); file_put_contents($zipPath, fopen($serverPath, "r")); // Check if zip folder could have been downloaded if (!file_exists($zipPath)) { - $this->rmDir($tempPath); - throw new \RuntimeException(Text::_('Zip has not been created')); + Folder::delete($tempPath); + throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_DOES_NOT_EXIST')); } - $zip = new \ZipArchive; - $zip->open($zipPath); + $zip = new Zip; - // Check if zip contains files - if ($zip->numFiles === 0) + if (!$zip->extract($zipPath, $tempPath)) { - $zip->close(); - $this->rmDir($tempPath); - throw new \RuntimeException(Text::_('Zip is empty')); + Folder::delete($tempPath); + throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_EXTRACT_FAILED')); } - $zip->extractTo($tempPath); - $zip->close(); - unlink($zipPath); - // Get a list of files from folder and deleted.log - $files = $this->getListOfFiles($tempPath); + File::delete($zipPath); + $files = Folder::files($tempPath, null, true, true); + $files = str_replace(Path::clean("$tempPath\\"), '', $files); - // ToDo add deleted files loop + $deletedFiles = file($deletedFilesPath); - mkdir($backupsPath); + Folder::create($backupsPath); // Moves existent files to backup and replace them or creates new one if they don't exist foreach ($files as $file) { - $filePath = explode("/", $file); + $filePath = explode("\\", $file); array_pop($filePath); - $filePath = implode("/", $filePath); + $filePath = implode("\\", $filePath); if (file_exists(JPATH_ROOT . "/$file")) { // Create directories if they don't exist until file if (!file_exists("$backupsPath/$filePath")) { - mkdir("$backupsPath/$filePath",null, true); + Folder::create("$backupsPath/$filePath"); } - rename(JPATH_ROOT . "/$file", "$backupsPath/$file"); + File::move(JPATH_ROOT . "/$file", "$backupsPath/$file"); } + // Create directories if they don't exist until file if (!file_exists(JPATH_ROOT . "/$filePath")) { - mkdir(JPATH_ROOT . "/$filePath",null, true); + Folder::create(JPATH_ROOT . "/$filePath"); } - copy("$tempPath/$file", JPATH_ROOT . "/$file"); + if (file_exists("$tempPath/$file")) + { + File::copy("$tempPath/$file", JPATH_ROOT . "/$file"); + } } // Clear temp folder and store applied patch in database - $this->rmDir($tempPath); + Folder::delete($tempPath); $this->saveAppliedPatch($id, $files); @@ -274,83 +276,6 @@ class PullModel extends AbstractModel return true; } - /** - * Returns an array containing fileNames as string for a given $dir - * - * @param string $dir directory to scan - * @param array $files array with fileNames - * @param string $parent parent directory - * - * @return array fileNames - * - * @since 3.0 - */ - private function getListOfFiles($dir, $files = [], $parent = null) - { - if (is_dir($dir)) - { - // Remove dot files/folders - $temp = preg_grep("/^([^.])/", scandir($dir)); - - foreach ($temp as $key => $file) - { - if (is_dir($dir . '/' . $file)) - { - unset($temp[$key]); - $files = $this->getListOfFiles($dir . '/' . $file, $files, - (is_null($parent) ? $file : $parent . '/' . $file)); - } - - if (!is_null($parent) && !is_dir($dir . '/' . $file)) - { - $temp[$key] = $parent . '/' . $file; - } - } - - $files = array_merge($files, $temp); - - return $files; - } - else - { - return []; - } - } - - /** - * Removes directory and its content recursively - * - * @param string $dir directory to delete - * - * @return void - * - * @since 3.0 - */ - private function rmDir($dir) - { - if (is_dir($dir)) - { - $files = scandir($dir); - - foreach ($files as $file) - { - if ($file != "." && $file != "..") - { - if (is_dir($dir . "/" . $file)) - { - $this->rmDir($dir . "/" . $file); - } - else - { - unlink($dir . "/" . $file); - } - } - } - - rmdir($dir); - } - } - /** * Patches the code with the supplied pull request * @@ -636,32 +561,32 @@ class PullModel extends AbstractModel // Delete file from root of it exists if (file_Exists(JPATH_ROOT . "/$file")) { - $filePath = explode("/", $file); + $filePath = explode("\\", $file); array_pop($filePath); - $filePath = implode("/", $filePath); + $filePath = implode("\\", $filePath); - unlink(JPATH_ROOT . "/$file"); + File::delete(JPATH_ROOT . "/$file"); // If folder is empty, remove it as well if (count(glob(JPATH_ROOT . "/$filePath/*")) === 0) { - rmdir(JPATH_ROOT . "/$filePath"); + Folder::delete(JPATH_ROOT . "/$filePath"); } // Move from backup, if it exists there if (file_exists("$backupsPath/$file")) { - rename("$backupsPath/$file", JPATH_ROOT . "/$file"); + File::move("$backupsPath/$file", JPATH_ROOT . "/$file"); } } // Move from backup, if file exists there - got deleted by patch elseif (file_exists("$backupsPath/$file")) { - rename("$backupsPath/$file", JPATH_ROOT . "/$file"); + File::move("$backupsPath/$file", JPATH_ROOT . "/$file"); } } - $this->rmDir($backupsPath); + Folder::delete($backupsPath); // Change the media version $version = new Version; diff --git a/administrator/components/com_patchtester/PatchTester/View/Fetch/tmpl/default.php b/administrator/components/com_patchtester/PatchTester/View/Fetch/tmpl/default.php index 97146d0..b2a2b8f 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Fetch/tmpl/default.php +++ b/administrator/components/com_patchtester/PatchTester/View/Fetch/tmpl/default.php @@ -21,8 +21,8 @@ HTMLHelper::_('script', 'com_patchtester/fetcher.js', array('version' => 'auto',

-
-
+
+
diff --git a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php index e4af427..6467150 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php +++ b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php @@ -6,117 +6,158 @@ * @license GNU General Public License version 2 or later */ +use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; /** @var \PatchTester\View\Pulls\PullsHtmlView $this */ +$searchToolsOptions = array( + 'filtersHidden' => true, + 'filterButton' => true, + 'defaultLimit' => Factory::getApplication()->get('list_limit', 20), + 'searchFieldSelector' => '#filter_search', + 'selectorFieldName' => 'client_id', + 'showSelector' => false, + 'orderFieldSelector' => '#list_fullordering', + 'showNoResults' => false, + 'noResultsText' => '', + 'formSelector' => '#adminForm', +); + HTMLHelper::_('behavior.core'); -HTMLHelper::_('bootstrap.tooltip'); -HTMLHelper::_('formbehavior.chosen', 'select'); +HTMLHelper::_('searchtools.form', '#adminForm', $searchToolsOptions); HTMLHelper::_('stylesheet', 'com_patchtester/octicons.css', array('version' => '3.5.0', 'relative' => true)); HTMLHelper::_('script', 'com_patchtester/patchtester.js', array('version' => 'auto', 'relative' => true)); $listOrder = $this->escape($this->state->get('list.fullordering', 'a.pull_id DESC')); +$listLimit = (int) ($this->state->get('list.limit')); $filterApplied = $this->escape($this->state->get('filter.applied')); $filterBranch = $this->escape($this->state->get('filter.branch')); $filterRtc = $this->escape($this->state->get('filter.rtc')); ?> -
-
-
- -
- - -
-
- - pagination->getLimitBox(); ?> -
-
- - -
-
- - -
-
- - -
-
- - + +
+
+
+ +
+ items)) : ?> +
+ + +
+ + + + + + + + + + + + + + + loadTemplate('items'); ?> + +
+ , +
+ + + + + + + + + + + +
+ + + pagination->getListFooter(); ?> + + + + + +
- - items)) : ?> -
- -
- - - - - - - - - - trackerAlias !== false) : ?> - - - - - - - - loadTemplate('items'); ?> - -
- - - - - - - - - - - - - - - -
- - - pagination->getListFooter(); ?> - - - - -
diff --git a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php index 1eaa19f..3d6345b 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php +++ b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php @@ -14,59 +14,58 @@ foreach ($this->items as $i => $item) : $status = ''; if ($item->applied) : - $status = ' class="success"'; + $status = ' class="table-active"'; endif; ?> > - + pull_id; ?> - + - escape($item->title); ?> - applied) : ?> -
- sha, 0, 10)); ?> + escape($item->title); ?> + +
+ - +
+ + + +
+ applied) : ?> +
+ sha, 0, 10)); ?> +
+ +
- + escape($item->branch); ?> - + is_rtc) : ?> - + - + - - - - - - trackerAlias !== false) : ?> - - - - - - - + applied) : ?> -
- -
+ - - - + - + applied) : ?> -
+ - + diff --git a/administrator/templates/atum/html/com_patchtester/fetch/default.php b/administrator/templates/atum/html/com_patchtester/fetch/default.php deleted file mode 100644 index b2a2b8f..0000000 --- a/administrator/templates/atum/html/com_patchtester/fetch/default.php +++ /dev/null @@ -1,28 +0,0 @@ - 'auto', 'relative' => true)); - -?> - -
-

-

-
-
-
- -
diff --git a/administrator/templates/atum/html/com_patchtester/pulls/default.php b/administrator/templates/atum/html/com_patchtester/pulls/default.php deleted file mode 100644 index 6467150..0000000 --- a/administrator/templates/atum/html/com_patchtester/pulls/default.php +++ /dev/null @@ -1,163 +0,0 @@ - true, - 'filterButton' => true, - 'defaultLimit' => Factory::getApplication()->get('list_limit', 20), - 'searchFieldSelector' => '#filter_search', - 'selectorFieldName' => 'client_id', - 'showSelector' => false, - 'orderFieldSelector' => '#list_fullordering', - 'showNoResults' => false, - 'noResultsText' => '', - 'formSelector' => '#adminForm', -); - -HTMLHelper::_('behavior.core'); -HTMLHelper::_('searchtools.form', '#adminForm', $searchToolsOptions); -HTMLHelper::_('stylesheet', 'com_patchtester/octicons.css', array('version' => '3.5.0', 'relative' => true)); -HTMLHelper::_('script', 'com_patchtester/patchtester.js', array('version' => 'auto', 'relative' => true)); - -$listOrder = $this->escape($this->state->get('list.fullordering', 'a.pull_id DESC')); -$listLimit = (int) ($this->state->get('list.limit')); -$filterApplied = $this->escape($this->state->get('filter.applied')); -$filterBranch = $this->escape($this->state->get('filter.branch')); -$filterRtc = $this->escape($this->state->get('filter.rtc')); -?> -
-
-
-
- -
- items)) : ?> -
- - -
- - - - - - - - - - - - - - - loadTemplate('items'); ?> - -
- , -
- - - - - - - - - - - -
- - - pagination->getListFooter(); ?> - - - - - -
-
-
-
-
diff --git a/administrator/templates/atum/html/com_patchtester/pulls/default_items.php b/administrator/templates/atum/html/com_patchtester/pulls/default_items.php deleted file mode 100644 index f9810ee..0000000 --- a/administrator/templates/atum/html/com_patchtester/pulls/default_items.php +++ /dev/null @@ -1,72 +0,0 @@ -items as $i => $item) : - $status = ''; - - if ($item->applied) : - $status = ' class="table-active"'; - endif; -?> -> - - pull_id; ?> - - - escape($item->title); ?> - -
-
- - - -
-
- - - -
- applied) : ?> -
- sha, 0, 10)); ?> -
- -
- - - escape($item->branch); ?> - - - is_rtc) : ?> - - - - - - - applied) : ?> - - - - - - - applied) : ?> - - - - - - -