From 5e3c94d5c2daeaabc27428794e2132c053a19431 Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Sun, 8 Sep 2019 18:02:14 +0200 Subject: [PATCH 01/27] First Attempt to add an "apply method via CI Server". --- .../com_patchtester/PatchTester/Helper.php | 27 +++ .../PatchTester/Model/PullModel.php | 198 ++++++++++++++++++ 2 files changed, 225 insertions(+) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index ddf2312..511cd28 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -62,4 +62,31 @@ abstract class Helper return new GitHub($options); } + + /** + * Initializes the CI Settings + * + * @return Registry + * + * @since 3.0 + */ + public static function initializeCISettings() + { + $options = new Registry; + + // Set CI server address for the request + $options->set('server.url', 'https://stuff.gramma.name'); + + // Set name of the zip archive + $options->set('zip.name', 'build.zip'); + + // Set temp archive for extracting and downloading files + $options->set('folder.temp', JPATH_COMPONENT . '/temp'); + $options->set('folder.backups', JPATH_COMPONENT . '/backups'); + + // Set full url for addressing the file + $options->set('zip.url', $options->get('server.url') . '/%s/' . $options->get('zip.name')); + + return $options; + } } diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index f537e69..3d10adf 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -8,6 +8,7 @@ namespace PatchTester\Model; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\Path; use Joomla\CMS\Language\Text; @@ -136,15 +137,212 @@ class PullModel extends AbstractModel /** * Patches the code with the supplied pull request + * However uses different destinations for different repositories. * * @param integer $id ID of the pull request to apply * * @return boolean * * @since 2.0 + * * @throws \RuntimeException */ public function apply($id) + { + $params = ComponentHelper::getParams('com_patchtester'); + + // Decide based on repository settings whether patch will be applied through Github or CIServer + if ($params->get('repo', 'joomla-cms') === 'joomla-cms' + && $params->get('org', 'joomla') === 'joomla') + { + return $this->applyWithCIServer($id); + } + else + { + return $this->applyWithGitHub($id); + } + } + + /** + * Patches the code with the supplied pull request + * + * @param integer $id ID of the pull request to apply + * + * @return boolean + * + * @since 3.0 + * + * @throws \RuntimeException + */ + public function applyWithCIServer($id) + { + // Get the CIServer Registry + $ciSettings = Helper::initializeCISettings(); + + $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); + + // Check if zip folder exists on server + $serverHeaders = @get_headers($serverPath); + + if (!$serverHeaders || $serverHeaders[0] != 'HTTP/1.1 200 OK') + { + throw new \RuntimeException(Text::_('File does not exist on Server')); + } + + mkdir($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')); + } + + $zip = new \ZipArchive; + $res = $zip->open($zipPath); + + // Check if zip contains files + if ($zip->numFiles === 0) + { + $zip->close(); + $this->rmDir($tempPath); + throw new \RuntimeException(Text::_('Zip is empty')); + } + + $zip->extractTo($tempPath); + $zip->close(); + + unlink($zipPath); + $files = $this->getListOfFiles($tempPath); + + mkdir($backupsPath); + + foreach ($files as $file) + { + if (file_exists(JPATH_ROOT . "/$file")) + { + copy(JPATH_ROOT . "/$file", "$backupsPath/$file"); + } + + copy("$tempPath/$file", JPATH_ROOT . "/$file"); + } + + $this->rmDir($tempPath); + + // ToDo refactor with githubCode to avoid duplicate code + + $record = (object) array( + 'pull_id' => $id, + 'data' => json_encode($files), + 'patched_by' => Factory::getUser()->id, + 'applied' => 1, + 'applied_version' => JVERSION, + ); + + $db = $this->getDb(); + + $db->insertObject('#__patchtester_tests', $record); + + // Change the media version + $version = new Version; + $version->refreshMediaVersion(); + + 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]); + $temp = $this->getListOfFiles($dir . '/' . $file, $temp, (is_null($parent) ? $file : $parent . '/' . $file)); + } + + if (!is_null($parent)) + { + $temp[$file] = $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 + * + * @param integer $id ID of the pull request to apply + * + * @return boolean + * + * @since 2.0 + * + * @throws \RuntimeException + */ + public function applyWithGitHub($id) { // Get the Github object $github = Helper::initializeGithub(); From 723deb1c8828f4aad003d5cb910254a3b355beb1 Mon Sep 17 00:00:00 2001 From: datsepp Date: Mon, 9 Sep 2019 17:32:50 +0200 Subject: [PATCH 02/27] Added method for reverting applied patches, added methods to reduce duplicate code and edited build.sh --- .../com_patchtester/PatchTester/Helper.php | 2 +- .../PatchTester/Model/PullModel.php | 253 ++++++++++++++---- .../components/com_patchtester/temp/readme.md | 1 + build/patchtester/build.sh | 1 - 4 files changed, 198 insertions(+), 59 deletions(-) create mode 100644 administrator/components/com_patchtester/temp/readme.md diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index 511cd28..0f5c72d 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -75,7 +75,7 @@ abstract class Helper $options = new Registry; // Set CI server address for the request - $options->set('server.url', 'https://stuff.gramma.name'); + $options->set('server.url', 'https://joomla-dev.lukaskimpel.com'); // Set name of the zip archive $options->set('zip.name', 'build.zip'); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 3d10adf..6962b16 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -137,7 +137,7 @@ class PullModel extends AbstractModel /** * Patches the code with the supplied pull request - * However uses different destinations for different repositories. + * However uses different methods for different repositories. * * @param integer $id ID of the pull request to apply * @@ -179,10 +179,16 @@ class PullModel extends AbstractModel // Get the CIServer Registry $ciSettings = Helper::initializeCISettings(); - $tempPath = $ciSettings->get('folder.temp') . "/$id"; + // Create tmp folder if it does not exist + if (!file_exists($ciSettings->get('folder.temp'))) + { + mkdir($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); + $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); + $serverPath = sprintf($ciSettings->get('zip.url'), $id); // Check if zip folder exists on server $serverHeaders = @get_headers($serverPath); @@ -203,7 +209,7 @@ class PullModel extends AbstractModel } $zip = new \ZipArchive; - $res = $zip->open($zipPath); + $zip->open($zipPath); // Check if zip contains files if ($zip->numFiles === 0) @@ -215,37 +221,49 @@ class PullModel extends AbstractModel $zip->extractTo($tempPath); $zip->close(); - unlink($zipPath); + + // Get a list of files from folder and deleted.log $files = $this->getListOfFiles($tempPath); + // ToDo add deleted files to fileList + + if (file_exists($backupsPath)) + { + $this->rmDir($backupsPath); + } mkdir($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); + array_pop($filePath); + $filePath = implode("/", $filePath); + if (file_exists(JPATH_ROOT . "/$file")) { - copy(JPATH_ROOT . "/$file", "$backupsPath/$file"); + // Create directories if they don't exist until file + if (!file_exists("$backupsPath/$filePath")) + { + mkdir("$backupsPath/$filePath",null, true); + } + + rename(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); } copy("$tempPath/$file", JPATH_ROOT . "/$file"); } + // Clear temp folder and store applied patch in database $this->rmDir($tempPath); - // ToDo refactor with githubCode to avoid duplicate code - - $record = (object) array( - 'pull_id' => $id, - 'data' => json_encode($files), - 'patched_by' => Factory::getUser()->id, - 'applied' => 1, - 'applied_version' => JVERSION, - ); - - $db = $this->getDb(); - - $db->insertObject('#__patchtester_tests', $record); + $this->saveAppliedPatch($id, $files); // Change the media version $version = new Version; @@ -257,11 +275,11 @@ class PullModel extends AbstractModel /** * 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 + * @param string $dir directory to scan + * @param array $files array with fileNames + * @param string $parent parent directory * - * @return array fileNames + * @return array fileNames * * @since 3.0 */ @@ -277,12 +295,13 @@ class PullModel extends AbstractModel if (is_dir($dir . '/' . $file)) { unset($temp[$key]); - $temp = $this->getListOfFiles($dir . '/' . $file, $temp, (is_null($parent) ? $file : $parent . '/' . $file)); + $files = $this->getListOfFiles($dir . '/' . $file, $files, + (is_null($parent) ? $file : $parent . '/' . $file)); } - if (!is_null($parent)) + if (!is_null($parent) && !is_dir($dir . '/' . $file)) { - $temp[$file] = $parent . '/' . $file; + $temp[$key] = $parent . '/' . $file; } } @@ -299,7 +318,7 @@ class PullModel extends AbstractModel /** * Removes directory and its content recursively * - * @param string $dir directory to delete + * @param string $dir directory to delete * * @return void * @@ -330,7 +349,6 @@ class PullModel extends AbstractModel } } - /** * Patches the code with the supplied pull request * @@ -506,25 +524,7 @@ class PullModel extends AbstractModel unset($file->body); } - $record = (object) array( - 'pull_id' => $pull->number, - 'data' => json_encode($parsedFiles), - 'patched_by' => Factory::getUser()->id, - 'applied' => 1, - 'applied_version' => JVERSION, - ); - - $db = $this->getDb(); - - $db->insertObject('#__patchtester_tests', $record); - - // Insert the retrieved commit SHA into the pulls table for this item - $db->setQuery( - $db->getQuery(true) - ->update('#__patchtester_pulls') - ->set('sha = ' . $db->quote($pull->head->sha)) - ->where($db->quoteName('pull_id') . ' = ' . (int) $id) - )->execute(); + $this->saveAppliedPatch($pull->number, $parsedFiles, $pull->head->sha); // Change the media version $version = new Version; @@ -533,8 +533,133 @@ class PullModel extends AbstractModel return true; } + /** + * Saves the applied patch into database + * + * @param integer $id ID of the applied pull request + * @param array $fileList List of files + * @param string $sha sha-key from pull request + * + * @return void + * + * @since 3.0 + */ + public function saveAppliedPatch($id, $fileList, $sha = null) + { + $record = (object) array( + 'pull_id' => $id, + 'data' => json_encode($fileList), + 'patched_by' => Factory::getUser()->id, + 'applied' => 1, + 'applied_version' => JVERSION, + ); + + $db = $this->getDb(); + + $db->insertObject('#__patchtester_tests', $record); + + if (!is_null($sha)) + { + // Insert the retrieved commit SHA into the pulls table for this item + $db->setQuery( + $db->getQuery(true) + ->update('#__patchtester_pulls') + ->set('sha = ' . $db->quote($sha)) + ->where($db->quoteName('pull_id') . ' = ' . (int) $id) + )->execute(); + } + } + /** * Reverts the specified pull request + * However uses different methods for different repositories. + * + * @param integer $id ID of the pull request to revert + * + * @return boolean + * + * @since 3.0 + * @throws \RuntimeException + */ + public function revert($id) + { + $params = ComponentHelper::getParams('com_patchtester'); + + // Decide based on repository settings whether patch will be applied through Github or CIServer + if ($params->get('repo', 'joomla-cms') === 'joomla-cms' + && $params->get('org', 'joomla') === 'joomla') + { + return $this->revertWithCIServer($id); + } + else + { + return $this->revertWithGitHub($id); + } + } + + /** + * Reverts the specified pull request with CIServer options + * + * @param integer $id ID of the pull request to revert + * + * @return boolean + * + * @since 3.0 + * @throws \RuntimeException + */ + public function revertWithCIServer($id) + { + // Get the CIServer Registry + $ciSettings = Helper::initializeCISettings(); + + $testRecord = $this->getTestRecord($id); + + // We don't want to restore files from an older version + if ($testRecord->applied_version != JVERSION) + { + return $this->removeTest($testRecord); + } + + $files = json_decode($testRecord->data); + + if (!$files) + { + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_ERROR_READING_DATABASE_TABLE', __METHOD__, htmlentities($testRecord->data))); + } + + $backupsPath = $ciSettings->get('folder.backups') . "/$testRecord->pull_id"; + + foreach ($files as $file) + { + // Delete file from root of it exists + if (file_Exists(JPATH_ROOT . "/$file")) + { + unlink(JPATH_ROOT . "/$file"); + + // Move from backup, if it exists there + if (file_exists("$backupsPath/$file")) + { + rename("$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"); + } + } + + $this->rmDir($backupsPath); + + // Change the media version + $version = new Version; + $version->refreshMediaVersion(); + + return $this->removeTest($testRecord); + } + + /** + * Reverts the specified pull request with Github Requests * * @param integer $id ID of the pull request to revert * @@ -543,16 +668,9 @@ class PullModel extends AbstractModel * @since 2.0 * @throws \RuntimeException */ - public function revert($id) + public function revertWithGitHub($id) { - $db = $this->getDb(); - - $testRecord = $db->setQuery( - $db->getQuery(true) - ->select('*') - ->from('#__patchtester_tests') - ->where('id = ' . (int) $id) - )->loadObject(); + $testRecord = $this->getTestRecord($id); // We don't want to restore files from an older version if ($testRecord->applied_version != JVERSION) @@ -679,4 +797,25 @@ class PullModel extends AbstractModel return true; } + + /** + * Retrieves test data from database by specific id + * + * @param integer $id ID of the record + * + * @return stdClass $testRecord The record looking for + * + * @since 3.0.0 + */ + private function getTestRecord($id) + { + $db = $this->getDb(); + + return $db->setQuery( + $db->getQuery(true) + ->select('*') + ->from('#__patchtester_tests') + ->where('id = ' . (int) $id) + )->loadObject(); + } } diff --git a/administrator/components/com_patchtester/temp/readme.md b/administrator/components/com_patchtester/temp/readme.md new file mode 100644 index 0000000..c535448 --- /dev/null +++ b/administrator/components/com_patchtester/temp/readme.md @@ -0,0 +1 @@ +This folder contains the temp files and must be writable by PHP. diff --git a/build/patchtester/build.sh b/build/patchtester/build.sh index c2e201e..451fc35 100755 --- a/build/patchtester/build.sh +++ b/build/patchtester/build.sh @@ -5,7 +5,6 @@ rm -rf build/packages && mkdir build/packages composer install --no-dev -o cp -r administrator/components/com_patchtester build/packaging/admin cp -r administrator/templates/atum/html/com_patchtester build/packaging/atum -cp -r administrator/templates/hathor/html/com_patchtester build/packaging/hathor cp -r media/com_patchtester build/packaging/media rm -rf build/packaging/admin/backups/*.txt mv build/packaging/admin/patchtester.xml build/packaging/patchtester.xml From 690a3c7cd0f43a94bbca68656245d3665c538124 Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Mon, 9 Sep 2019 18:38:25 +0200 Subject: [PATCH 03/27] Small fix to avoid calling apply method multiple times. --- .../com_patchtester/PatchTester/Model/PullModel.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 6962b16..a718737 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -143,7 +143,7 @@ class PullModel extends AbstractModel * * @return boolean * - * @since 2.0 + * @since 3.0 * * @throws \RuntimeException */ @@ -190,6 +190,12 @@ class PullModel extends AbstractModel $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); $serverPath = sprintf($ciSettings->get('zip.url'), $id); + // Patch has already been applied + if (file_exists($backupsPath)) + { + return false; + } + // Check if zip folder exists on server $serverHeaders = @get_headers($serverPath); @@ -228,10 +234,6 @@ class PullModel extends AbstractModel // ToDo add deleted files to fileList - if (file_exists($backupsPath)) - { - $this->rmDir($backupsPath); - } mkdir($backupsPath); // Moves existent files to backup and replace them or creates new one if they don't exist From 82befbe55461e8dccfb2ac1ed6140ae0230733d4 Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Mon, 9 Sep 2019 21:38:23 +0200 Subject: [PATCH 04/27] Added a validation in revert method to check if a directory is empty and remove it after reverting patch. --- .../PatchTester/Model/PullModel.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index a718737..75a8a1e 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -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); From aaeccd34024ffbbbe23d88181149613fbf9bc8a6 Mon Sep 17 00:00:00 2001 From: datsepp Date: Tue, 10 Sep 2019 13:53:40 +0200 Subject: [PATCH 05/27] Added method for reverting applied patches, added methods to reduce duplicate code and edited build.sh --- .../com_patchtester/PatchTester/Helper.php | 3 +- .../PatchTester/Model/PullModel.php | 153 +++--------- .../PatchTester/View/Fetch/tmpl/default.php | 4 +- .../PatchTester/View/Pulls/tmpl/default.php | 231 +++++++++++------- .../View/Pulls/tmpl/default_items.php | 67 +++-- .../html/com_patchtester/fetch/default.php | 28 --- .../html/com_patchtester/pulls/default.php | 163 ------------ .../com_patchtester/pulls/default_items.php | 72 ------ build/patchtester/build.sh | 1 - media/com_patchtester/js/fetcher.js | 2 +- 10 files changed, 213 insertions(+), 511 deletions(-) delete mode 100644 administrator/templates/atum/html/com_patchtester/fetch/default.php delete mode 100644 administrator/templates/atum/html/com_patchtester/pulls/default.php delete mode 100644 administrator/templates/atum/html/com_patchtester/pulls/default_items.php 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) : ?> - - - - - - - Date: Tue, 10 Sep 2019 15:22:19 +0200 Subject: [PATCH 06/27] Refactored JSCode for button-click events. --- .../View/Pulls/tmpl/default_items.php | 104 +++++++++--------- media/com_patchtester/js/patchtester.js | 39 +++---- 2 files changed, 70 insertions(+), 73 deletions(-) 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 3d6345b..f829d66 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 @@ -16,57 +16,57 @@ foreach ($this->items as $i => $item) : if ($item->applied) : $status = ' class="table-active"'; endif; -?> -> - - pull_id; ?> - - - escape($item->title); ?> - -
-
- - - -
-
- - - -
- applied) : ?> -
- sha, 0, 10)); ?> -
+ ?> + > + + pull_id; ?> + + + escape($item->title); ?> + +
+
+ + + +
+
+ + + +
+ applied) : ?> +
+ sha, 0, 10)); ?> +
+ +
+ + + escape($item->branch); ?> + + + is_rtc) : ?> + + + -
- - - escape($item->branch); ?> - - - is_rtc) : ?> - - - - - - - applied) : ?> - - - - - - - applied) : ?> - - - - - - + + + applied) : ?> + + + + + + + applied) : ?> + + + + + + { - window.PatchTester = { - /** - * Process the patch action - * - * @param {String} task The task to perform - * @param {Number} id The item ID - */ - submitpatch: function (task, id) { - var idField = document.getElementById('pull_id'); - idField.value = id; + let submitPatch = document.querySelectorAll(".submitPatch"); + let pullIdForm = document.querySelector("#pull_id"); - Joomla.submitform(task); - } - }; + /** + * EventListener which listens on submitPatch Button, + * checks if it is an apply or revert method and + * processes the patch action + * + * @param {Event} event + */ + submitPatch.forEach((element) => element.addEventListener("click", (event) => { + let currentTarget = event.currentTarget, + data = currentTarget.dataset.task.split("-"), + task = data[0]; - Joomla.submitbutton = function (task) { - if (task != 'reset' || confirm(Joomla.JText._('COM_PATCHTESTER_CONFIRM_RESET', 'Resetting will attempt to revert all applied patches and removes all backed up files. This may result in a corrupted environment. Are you sure you want to continue?'))) { - Joomla.submitform(task); - } - }; -}(Joomla, window, document); + pullIdForm.value = data[1]; + Joomla.submitform(task); + })); +}); From 16c415872ce03427d44c4dd2b5a7f8eb3b85c735 Mon Sep 17 00:00:00 2001 From: datsepp Date: Tue, 10 Sep 2019 15:39:57 +0200 Subject: [PATCH 07/27] Added Git-Request to retrieve sha in applyWithCiServer method. --- .../PatchTester/Model/PullModel.php | 84 ++++++++++++------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 3f1d300..39237ad 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -12,11 +12,13 @@ use Joomla\Archive\Zip; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\Path; +use Joomla\CMS\Http\Response; use Joomla\CMS\Language\Text; use Joomla\CMS\Version; use Joomla\Filesystem\File; use Joomla\Filesystem\Folder; use PatchTester\GitHub\Exception\UnexpectedResponse; +use PatchTester\GitHub\GitHub; use PatchTester\Helper; /** @@ -181,6 +183,13 @@ class PullModel extends AbstractModel // Get the CIServer Registry $ciSettings = Helper::initializeCISettings(); + // Get the Github object + $github = Helper::initializeGithub(); + + // retrieve pullData for sha later on. + $pull = $this->retrieveGitHubData($github, $id); + $sha = $pull->head->sha; + // Create tmp folder if it does not exist if (!file_exists($ciSettings->get('folder.temp'))) { @@ -267,7 +276,7 @@ class PullModel extends AbstractModel // Clear temp folder and store applied patch in database Folder::delete($tempPath); - $this->saveAppliedPatch($id, $files); + $this->saveAppliedPatch($id, $files, $sha); // Change the media version $version = new Version; @@ -292,33 +301,7 @@ class PullModel extends AbstractModel // Get the Github object $github = Helper::initializeGithub(); - try - { - $rateResponse = $github->getRateLimit(); - $rate = json_decode($rateResponse->body); - } - catch (UnexpectedResponse $e) - { - throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e); - } - - // If over the API limit, we can't build this list - if ($rate->resources->core->remaining == 0) - { - throw new \RuntimeException( - Text::sprintf('COM_PATCHTESTER_API_LIMIT_LIST', Factory::getDate($rate->resources->core->reset)) - ); - } - - try - { - $pullResponse = $github->getPullRequest($this->getState()->get('github_user'), $this->getState()->get('github_repo'), $id); - $pull = json_decode($pullResponse->body); - } - catch (UnexpectedResponse $e) - { - throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e); - } + $pull = $this->retrieveGitHubData($github, $id); if (is_null($pull->head->repo)) { @@ -460,6 +443,51 @@ class PullModel extends AbstractModel return true; } + /** + * Patches the code with the supplied pull request + * + * @param GitHub $github github object + * @param integer $id Id of the pull request + * + * @return Response + * + * @since 2.0 + * + * @throws \RuntimeException + */ + private function retrieveGitHubData($github, $id) + { + try + { + $rateResponse = $github->getRateLimit(); + $rate = json_decode($rateResponse->body); + } + catch (UnexpectedResponse $e) + { + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e); + } + + // If over the API limit, we can't build this list + if ($rate->resources->core->remaining == 0) + { + throw new \RuntimeException( + Text::sprintf('COM_PATCHTESTER_API_LIMIT_LIST', Factory::getDate($rate->resources->core->reset)) + ); + } + + try + { + $pullResponse = $github->getPullRequest($this->getState()->get('github_user'), $this->getState()->get('github_repo'), $id); + $pull = json_decode($pullResponse->body); + } + catch (UnexpectedResponse $e) + { + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e); + } + + return $pull; + } + /** * Saves the applied patch into database * From 84cb1b369be38f69d890489b08b967b8f7a4e884 Mon Sep 17 00:00:00 2001 From: datsepp Date: Wed, 11 Sep 2019 11:41:01 +0200 Subject: [PATCH 08/27] Fixed revert/applying patch methods and added language constants. --- .../com_patchtester/PatchTester/Helper.php | 4 +- .../PatchTester/Model/PullModel.php | 122 ++++++++---- .../language/de-DE/de-DE.com_patchtester.ini | 183 +++++++++--------- .../language/en-GB/en-GB.com_patchtester.ini | 6 + .../language/en-US/en-US.com_patchtester.ini | 5 + 5 files changed, 188 insertions(+), 132 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index 4a2858a..c7b3a6c 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -75,11 +75,11 @@ abstract class Helper $options = new Registry; // Set CI server address for the request - $options->set('server.url', 'https://joomla-dev.lukaskimpel.com'); + $options->set('server.url', 'https://stuff.gramma.name'); // Set name of the zip archive $options->set('zip.name', 'build.zip'); - $options->set('zip.deleted_log', 'deleted_files.log'); + $options->set('zip.log.name', 'deleted_files.log'); // Set temp archive for extracting and downloading files $options->set('folder.temp', Factory::getConfig()->get('tmp_path')); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 39237ad..9145892 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -196,11 +196,13 @@ class PullModel extends AbstractModel Folder::create($ciSettings->get('folder.temp')); } - $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); + $tempPath = $ciSettings->get('folder.temp') . "/$id"; + $backupsPath = $ciSettings->get('folder.backups') . "/$id"; + + $delLogPath = $tempPath . '/' . $ciSettings->get('zip.log.name'); + $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); + + $serverZipPath = sprintf($ciSettings->get('zip.url'), $id); // Patch has already been applied if (file_exists($backupsPath)) @@ -209,7 +211,7 @@ class PullModel extends AbstractModel } // Check if zip folder exists on server - $serverHeaders = @get_headers($serverPath); + $serverHeaders = @get_headers($serverZipPath); if (!$serverHeaders || $serverHeaders[0] != 'HTTP/1.1 200 OK') { @@ -217,7 +219,7 @@ class PullModel extends AbstractModel } Folder::create($tempPath); - file_put_contents($zipPath, fopen($serverPath, "r")); + file_put_contents($zipPath, fopen($serverZipPath, "r")); // Check if zip folder could have been downloaded if (!file_exists($zipPath)) @@ -234,49 +236,72 @@ class PullModel extends AbstractModel throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_EXTRACT_FAILED')); } - // Get a list of files from folder and deleted.log + // remove zip to avoid get listing afterwards File::delete($zipPath); + + // get files from deleted_logs + $deletedFiles = file($delLogPath); + + // remove deleted_logs to avoid get listing afterwards + File::delete($delLogPath); + + // retrieve all files and merge them into one array $files = Folder::files($tempPath, null, true, true); $files = str_replace(Path::clean("$tempPath\\"), '', $files); - - $deletedFiles = file($deletedFilesPath); + $files = array_merge($files, $deletedFiles); Folder::create($backupsPath); // Moves existent files to backup and replace them or creates new one if they don't exist - foreach ($files as $file) + foreach ($files as $key => $file) { - $filePath = explode("\\", $file); - array_pop($filePath); - $filePath = implode("\\", $filePath); - - if (file_exists(JPATH_ROOT . "/$file")) + try { - // Create directories if they don't exist until file - if (!file_exists("$backupsPath/$filePath")) + $filePath = explode("\\", $file); + array_pop($filePath); + $filePath = implode("\\", $filePath); + + // deleted_logs returns files as well as folder, if value is folder, unset and skip + if (is_dir(JPATH_ROOT . "/$file")) { - Folder::create("$backupsPath/$filePath"); + unset($files[$key]); + continue; } - File::move(JPATH_ROOT . "/$file", "$backupsPath/$file"); - } + if (file_exists(JPATH_ROOT . "/$file")) + { + // Create directories if they don't exist until file + if (!file_exists("$backupsPath/$filePath")) + { + Folder::create("$backupsPath/$filePath"); + } - // Create directories if they don't exist until file - if (!file_exists(JPATH_ROOT . "/$filePath")) - { - Folder::create(JPATH_ROOT . "/$filePath"); - } + File::move(JPATH_ROOT . "/$file", "$backupsPath/$file"); + } - if (file_exists("$tempPath/$file")) + // Create directories if they don't exist until file + if (!file_exists(JPATH_ROOT . "/$filePath") || !is_dir(JPATH_ROOT . "/$filePath")) + { + Folder::create(JPATH_ROOT . "/$filePath"); + } + + if (file_exists("$tempPath/$file")) + { + File::copy("$tempPath/$file", JPATH_ROOT . "/$file"); + } + } + catch(\RuntimeException $e) { - File::copy("$tempPath/$file", JPATH_ROOT . "/$file"); + Folder::delete($tempPath); + Folder::move($backupsPath, $backupsPath . "_failed"); + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_FAILED_APPLYING_PATCH', $file, $e->getMessage())); } } // Clear temp folder and store applied patch in database Folder::delete($tempPath); - $this->saveAppliedPatch($id, $files, $sha); + $this->saveAppliedPatch($id, $files); // Change the media version $version = new Version; @@ -586,31 +611,44 @@ class PullModel extends AbstractModel foreach ($files as $file) { - // Delete file from root of it exists - if (file_Exists(JPATH_ROOT . "/$file")) + try { $filePath = explode("\\", $file); array_pop($filePath); $filePath = implode("\\", $filePath); - File::delete(JPATH_ROOT . "/$file"); - - // If folder is empty, remove it as well - if (count(glob(JPATH_ROOT . "/$filePath/*")) === 0) + // Delete file from root of it exists + if (file_Exists(JPATH_ROOT . "/$file")) { - Folder::delete(JPATH_ROOT . "/$filePath"); + + File::delete(JPATH_ROOT . "/$file"); + + // Move from backup, if it exists there + if (file_exists("$backupsPath/$file")) + { + File::move("$backupsPath/$file", JPATH_ROOT . "/$file"); + } + + // If folder is empty, remove it as well + if (count(glob(JPATH_ROOT . "/$filePath/*")) === 0) + { + Folder::delete(JPATH_ROOT . "/$filePath"); + } } - - // Move from backup, if it exists there - if (file_exists("$backupsPath/$file")) + // Move from backup, if file exists there - got deleted by patch + elseif (file_exists("$backupsPath/$file")) { + if (!file_exists(JPATH_ROOT . "/$filePath")) + { + Folder::create(JPATH_ROOT . "/$filePath"); + } + File::move("$backupsPath/$file", JPATH_ROOT . "/$file"); } } - // Move from backup, if file exists there - got deleted by patch - elseif (file_exists("$backupsPath/$file")) + catch(\RuntimeException $e) { - File::move("$backupsPath/$file", JPATH_ROOT . "/$file"); + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_FAILED_REVERT_PATCH', $file, $e->getMessage())); } } diff --git a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini index b2bbd60..1ab18e7 100644 --- a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini @@ -3,92 +3,99 @@ ; License GNU General Public License version 2 or later ; Note : All ini files need to be saved as UTF-8 -COM_PATCHTESTER="Joomla! Patch Tester" -COM_PATCHTESTER_40_WARNING="Solange Joomla! 4.0 in der Entwicklung ist, muss der Patch-Tester als experimentell angesehen werden, da Änderungen in Joomla, einschließlich des in einem Patch enthaltenen Codes, möglicherweise nicht rückwärts-kompatibel sind." -COM_PATCHTESTER_API_LIMIT_ACTION="Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die angeforderte Aktion anzuführen. Das Limit wird um %s zurückgesetzt" -COM_PATCHTESTER_API_LIMIT_LIST="Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die Daten zu aktualisieren. Das Limit wird um %s zurückgesetzt" -COM_PATCHTESTER_APPLIED="Angewendet" -COM_PATCHTESTER_APPLIED_COMMIT_SHA="Angewandter Commit SHA: %s" -COM_PATCHTESTER_APPLY_OK="Patch erfolgreich angewendet" -COM_PATCHTESTER_APPLY_PATCH="Patch installieren" -COM_PATCHTESTER_BRANCH="Versionszweig" -COM_PATCHTESTER_CONFIGURATION="Joomla! Patch-Tester Einstellungen" -COM_PATCHTESTER_CONFIRM_RESET="Das Zurücksetzen versucht, alle installierten Patches rückgängig zu machen. Dabei werden alle Backup-Dateien entfernt. Dies könnte dazu führen, dass die Umgebung nicht mehr stabil ist. Sind Sie sicher, dass Sie fortfahren möchten?" -COM_PATCHTESTER_CONFLICT_S="Der Patch konnte nicht installiert werden, weil es einen Konflikt mit einem anderen Patch gibt: %s" -COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB="Keine Verbindung zu GitHub: %s" -COM_PATCHTESTER_ERROR_APPLIED_PATCHES="Daten von GitHub können nicht abgerufen werden, solange Patches installiert sind. Entfernen Sie bitte die Patches, bevor Sie fortfahren." -COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE="Die Datei %1$s konnte nicht nach %2$s kopiert werden." -COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE="Die Datei %s kann nicht gelöscht werden." -COM_PATCHTESTER_ERROR_CANNOT_WRITE_FILE="Die Datei %s kann nicht geschrieben werden." -COM_PATCHTESTER_ERROR_GITHUB_FETCH="Fehler beim Abrufen der Patches von GitHub: %s" -COM_PATCHTESTER_ERROR_INSERT_DATABASE="Fehler beim Eintragen der Patches in die Datenbank: %s" -COM_PATCHTESTER_ERROR_MODEL_NOT_FOUND="Model-Klasse %s nicht gefunden." -COM_PATCHTESTER_ERROR_READING_DATABASE_TABLE="%1$s - Fehler beim Abrufen von Tabellendaten (%2$s)" -COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE="Fehler beim Leeren der Pulls-Tabelle: %s" -COM_PATCHTESTER_ERROR_TRUNCATING_TESTS_TABLE="Fehler beim Leeren der Tests-Tabelle %s" -COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING="Die Patch-Dateien sind in mit einem nicht unterstützten Format codiert." -COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND="Ansicht nicht gefunden [Name, Format]: %1$s, %2$s" -COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED="Fehler beim Abrufen der Daten von GitHub." -COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW="Alle Daten wurden abgerufen. Schließen Sie bitte dieses Popup um die Seite neu zu laden." -COM_PATCHTESTER_FETCH_INITIALIZING="Vorbereitungen für das Abrufen der Daten von GitHub" -COM_PATCHTESTER_FETCH_INITIALIZING_DESCRIPTION="Überprüfe die Vorbereitungen für den Datenabruf. Bitte haben Sie etwas Geduld." -COM_PATCHTESTER_FETCH_PAGE_NUMBER="Verarbeite Seite %s der GitHub-Daten" -COM_PATCHTESTER_FETCH_PAGE_NUMBER_OF_TOTAL="Verarbeite Seite %1$s von %2$s der GitHub-Daten" -COM_PATCHTESTER_FETCH_PROCESSING="Verarbeite Daten von GitHub" -COM_PATCHTESTER_FETCH_SUCCESSFUL="Patches wurden erfolgreich abgerufen" -COM_PATCHTESTER_FIELD_GH_AUTH_DESC="Wähle die 'Anmeldeinformationen' für die Authentifizierung durch Deinen GitHub Usernamen und Passwort oder 'Token' für die Verwendung eines GitHub API Token" -COM_PATCHTESTER_FIELD_GH_AUTH_LABEL="GitHub Authentifizierungs-Methode" -COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_CREDENTIALS="Anmeldeinformationen" -COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_TOKEN="Token" -COM_PATCHTESTER_FIELD_GH_PASSWORD_LABEL="GitHub-Passwort" -COM_PATCHTESTER_FIELD_GH_PASSWORD_DESC="Passwort für das im 'GitHub Konto' eingetragene Benutzerkonto. Beachte, dass für Konten mit Zwei-Faktor-Authentifizierung auch ein Token generiert werden muss." -COM_PATCHTESTER_FIELD_GH_TOKEN_DESC="Verwenden Sie dieses Feld, um ein GitHub API-Token anstelle von Benutzernamen und Passwort anzugeben. Beachten Sie, dass dies erforderlich ist, wenn Ihr Konto Zwei-Faktor-Authentifizierung aktiviert hat." -COM_PATCHTESTER_FIELD_GH_TOKEN_LABEL="GitHub-Token" -COM_PATCHTESTER_FIELD_GH_USER_LABEL="GitHub Benutzername" -COM_PATCHTESTER_FIELD_GH_USER_DESC="Name des GitHub Kontos, das für die Authentifizierung des API genutzt wird." -COM_PATCHTESTER_FIELD_ORG_LABEL="Projektinhaber" -COM_PATCHTESTER_FIELD_ORG_DESC="Benutzername oder Organisation auf Github, welcher die Pull Requests überwachen soll." -COM_PATCHTESTER_FIELD_REPO_LABEL="Individuelle Projekt-Repository" -COM_PATCHTESTER_FIELD_REPO_DESC="Name des GitHub Repositorys, dessen Pull Requests überwacht werden." -COM_PATCHTESTER_FIELD_REPOSITORY_DESC="Verfügbare Joomla! Repositories. Wähle um die Organisation und die Repository Feldwerte automatisch zu füllen." -COM_PATCHTESTER_FIELD_REPOSITORY_LABEL="GitHub Repository" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_JOOMLA_CMS="Joomla! CMS" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER="Joomla! Patch-Tester Komponente" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB="Joomla! Webkataloginstallations-Plugin" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS="Joomla! Weblinks-Paket" -COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM="Benutzerdefiniert" -COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC="Konfigurationswerte für GitHub Repository" -COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL="GitHub Repository" -COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC="Konfigurationswerte für GitHub Authentifizierung" -COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL="GitHub Authentifizierung" -COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S="Die zu löschende Datei existiert nicht: %s" -COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="Die zu ändernde Datei existiert nicht: %s" -COM_PATCHTESTER_FILTER_APPLIED_PATCHES="Angewendete Patches filtern" -COM_PATCHTESTER_FILTER_BRANCH="Versionszweig filtern" -COM_PATCHTESTER_FILTER_RTC_PATCHES="RTC Patches filtern" -COM_PATCHTESTER_FILTER_SEARCH_DESCRIPTION="Die Liste nach Titel oder mit 'id:' nach Pull Request ID durchsuchen." -COM_PATCHTESTER_GITHUB="GitHub" -COM_PATCHTESTER_HEADING_FETCH_DATA="Rufe GitHub Daten ab" -COM_PATCHTESTER_JISSUE="J! Issue" -COM_PATCHTESTER_JISSUES="Issue-Tracker" -COM_PATCHTESTER_PULL_ID="Pull-ID" -COM_PATCHTESTER_NO_CREDENTIALS="In den Optionen wurden noch keine Benutzerdaten eingetragen. Deshalb können höchstens 60 Anfragen pro Stunde an das Github API gestellt werden. Mit Benutzerdaten sind bis zu 5.000 Anfragen pro Stunde möglich." -COM_PATCHTESTER_NO_FILES_TO_PATCH="Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind." -COM_PATCHTESTER_NO_ITEMS="Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen." -COM_PATCHTESTER_NOT_APPLIED="Nicht angewendet" -COM_PATCHTESTER_NOT_RTC="Nicht RTC" -COM_PATCHTESTER_READY_TO_COMMIT="Ready to Commit" -COM_PATCHTESTER_REPO_IS_GONE="Der Patch konnte nicht angewendet werden, weil das Repository fehlt" -COM_PATCHTESTER_REQUIREMENT_HTTPS="HTTPS Wrapper müssen aktiviert sein" -COM_PATCHTESTER_REQUIREMENT_OPENSSL="Die OpenSSL-Erweiterung muss installiert und in der php.ini aktivert sein" -COM_PATCHTESTER_REQUIREMENTS_HEADING="Die Vorraussetzungen sind nicht erfüllt" -COM_PATCHTESTER_REQUIREMENTS_NOT_MET="Ihr System erfüllt nicht die Vorraussetzungen um den Patch-Tester auszuführen:" -COM_PATCHTESTER_RESET_HAS_ERRORS="Die Daten wurden zurück gesetzt. Leider sind dabei Fehler aufgetreten. Bitte entferne alle .txt Dateien im Verzeichnis '%1$s' und leere die Datenbanktabelle '%2$s'." -COM_PATCHTESTER_RESET_OK="Die Daten wurden erfolgreich zurück gesetzt." -COM_PATCHTESTER_REVERT_OK="Der Patch wurde erfolgreich entfernt" -COM_PATCHTESTER_REVERT_PATCH="Patch entfernen" -COM_PATCHTESTER_RTC="RTC" -COM_PATCHTESTER_TEST_THIS_PATCH="Diesen Patch testen" -COM_PATCHTESTER_TOOLBAR_FETCH_DATA="Daten abrufen" -COM_PATCHTESTER_TOOLBAR_RESET="Zurücksetzen" +COM_PATCHTESTER = "Joomla! Patch Tester" +COM_PATCHTESTER_40_WARNING = "Solange Joomla! 4.0 in der Entwicklung ist, muss der Patch-Tester als experimentell angesehen werden, da Änderungen in Joomla, einschließlich des in einem Patch enthaltenen Codes, möglicherweise nicht rückwärts-kompatibel sind." +COM_PATCHTESTER_API_LIMIT_ACTION = "Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die angeforderte Aktion anzuführen. Das Limit wird um %s zurückgesetzt" +COM_PATCHTESTER_API_LIMIT_LIST = "Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die Daten zu aktualisieren. Das Limit wird um %s zurückgesetzt" +COM_PATCHTESTER_APPLIED = "Angewendet" +COM_PATCHTESTER_APPLIED_COMMIT_SHA = "Angewandter Commit SHA: %s" +COM_PATCHTESTER_APPLY_OK = "Patch erfolgreich angewendet" +COM_PATCHTESTER_APPLY_PATCH = "Patch installieren" +COM_PATCHTESTER_BRANCH = "Versionszweig" +COM_PATCHTESTER_CONFIGURATION = "Joomla! Patch-Tester Einstellungen" +COM_PATCHTESTER_CONFIRM_RESET = "Das Zurücksetzen versucht, alle installierten Patches rückgängig zu machen. Dabei werden alle Backup-Dateien entfernt. Dies könnte dazu führen, dass die Umgebung nicht mehr stabil ist. Sind Sie sicher, dass Sie fortfahren möchten?" +COM_PATCHTESTER_CONFLICT_S = "Der Patch konnte nicht installiert werden, weil es einen Konflikt mit einem anderen Patch gibt: %s" +COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB = "Keine Verbindung zu GitHub: %s" +COM_PATCHTESTER_ERROR_APPLIED_PATCHES = "Daten von GitHub können nicht abgerufen werden, solange Patches installiert sind. Entfernen Sie bitte die Patches, bevor Sie fortfahren." +COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE = "Die Datei %1$s konnte nicht nach %2$s kopiert werden." +COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE = "Die Datei %s kann nicht gelöscht werden." +COM_PATCHTESTER_ERROR_CANNOT_WRITE_FILE = "Die Datei %s kann nicht geschrieben werden." +COM_PATCHTESTER_ERROR_GITHUB_FETCH = "Fehler beim Abrufen der Patches von GitHub: %s" +COM_PATCHTESTER_ERROR_INSERT_DATABASE = "Fehler beim Eintragen der Patches in die Datenbank: %s" +COM_PATCHTESTER_ERROR_MODEL_NOT_FOUND = "Model-Klasse %s nicht gefunden." +COM_PATCHTESTER_ERROR_READING_DATABASE_TABLE = "%1$s - Fehler beim Abrufen von Tabellendaten (%2$s)" +COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE = "Fehler beim Leeren der Pulls-Tabelle: %s" +COM_PATCHTESTER_ERROR_TRUNCATING_TESTS_TABLE = "Fehler beim Leeren der Tests-Tabelle %s" +COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING = "Die Patch-Dateien sind in mit einem nicht unterstützten Format codiert." +COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND = "Ansicht nicht gefunden [Name, Format]: %1$s, %2$s" +COM_PATCHTESTER_FAILED_APPLYING_PATCH="Der Patch konnte nicht angewendet werden aufgrund eines Problems mit %1$s. %2$s" +COM_PATCHTESTER_FAILED_REVERT_PATCH="Der Patch konnte nicht zurückgesetzt werden aufgrund eines Problems mit %1$s. %2$s" +COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED = "Fehler beim Abrufen der Daten von GitHub." +COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW = "Alle Daten wurden abgerufen. Schließen Sie bitte dieses Popup um die Seite neu zu laden." +COM_PATCHTESTER_FETCH_INITIALIZING = "Vorbereitungen für das Abrufen der Daten von GitHub" +COM_PATCHTESTER_FETCH_INITIALIZING_DESCRIPTION = "Überprüfe die Vorbereitungen für den Datenabruf. Bitte haben Sie etwas Geduld." +COM_PATCHTESTER_FETCH_PAGE_NUMBER = "Verarbeite Seite %s der GitHub-Daten" +COM_PATCHTESTER_FETCH_PAGE_NUMBER_OF_TOTAL = "Verarbeite Seite %1$s von %2$s der GitHub-Daten" +COM_PATCHTESTER_FETCH_PROCESSING = "Verarbeite Daten von GitHub" +COM_PATCHTESTER_FETCH_SUCCESSFUL = "Patches wurden erfolgreich abgerufen" +COM_PATCHTESTER_FIELD_GH_AUTH_DESC = "Wähle die 'Anmeldeinformationen' für die Authentifizierung durch Deinen GitHub Usernamen und Passwort oder 'Token' für die Verwendung eines GitHub API Token" +COM_PATCHTESTER_FIELD_GH_AUTH_LABEL = "GitHub Authentifizierungs-Methode" +COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_CREDENTIALS = "Anmeldeinformationen" +COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_TOKEN = "Token" +COM_PATCHTESTER_FIELD_GH_PASSWORD_LABEL = "GitHub-Passwort" +COM_PATCHTESTER_FIELD_GH_PASSWORD_DESC = "Passwort für das im 'GitHub Konto' eingetragene Benutzerkonto. Beachte, dass für Konten mit Zwei-Faktor-Authentifizierung auch ein Token generiert werden muss." +COM_PATCHTESTER_FIELD_GH_TOKEN_DESC = "Verwenden Sie dieses Feld, um ein GitHub API-Token anstelle von Benutzernamen und Passwort anzugeben. Beachten Sie, dass dies erforderlich ist, wenn Ihr Konto Zwei-Faktor-Authentifizierung aktiviert hat." +COM_PATCHTESTER_FIELD_GH_TOKEN_LABEL = "GitHub-Token" +COM_PATCHTESTER_FIELD_GH_USER_LABEL = "GitHub Benutzername" +COM_PATCHTESTER_FIELD_GH_USER_DESC = "Name des GitHub Kontos, das für die Authentifizierung des API genutzt wird." +COM_PATCHTESTER_FIELD_ORG_LABEL = "Projektinhaber" +COM_PATCHTESTER_FIELD_ORG_DESC = "Benutzername oder Organisation auf Github, welcher die Pull Requests überwachen soll." +COM_PATCHTESTER_FIELD_REPO_LABEL = "Individuelle Projekt-Repository" +COM_PATCHTESTER_FIELD_REPO_DESC = "Name des GitHub Repositorys, dessen Pull Requests überwacht werden." +COM_PATCHTESTER_FIELD_REPOSITORY_DESC = "Verfügbare Joomla! Repositories. Wähle um die Organisation und die Repository Feldwerte automatisch zu füllen." +COM_PATCHTESTER_FIELD_REPOSITORY_LABEL = "GitHub Repository" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_JOOMLA_CMS = "Joomla! CMS" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER = "Joomla! Patch-Tester Komponente" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB = "Joomla! Webkataloginstallations-Plugin" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS = "Joomla! Weblinks-Paket" +COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM = "Benutzerdefiniert" +COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC = "Konfigurationswerte für GitHub Repository" +COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL = "GitHub Repository" +COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC = "Konfigurationswerte für GitHub Authentifizierung" +COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL = "GitHub Authentifizierung" +COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S = "Die zu löschende Datei existiert nicht: %s" +COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S = "Die zu ändernde Datei existiert nicht: %s" +COM_PATCHTESTER_FILTER_APPLIED_PATCHES = "Angewendete Patches filtern" +COM_PATCHTESTER_FILTER_BRANCH = "Versionszweig filtern" +COM_PATCHTESTER_FILTER_RTC_PATCHES = "RTC Patches filtern" +COM_PATCHTESTER_FILTER_SEARCH_DESCRIPTION = "Die Liste nach Titel oder mit 'id:' nach Pull Request ID durchsuchen." +COM_PATCHTESTER_GITHUB = "GitHub" +COM_PATCHTESTER_HEADING_FETCH_DATA = "Rufe GitHub Daten ab" +COM_PATCHTESTER_JISSUE = "J! Issue" +COM_PATCHTESTER_JISSUES = "Issue-Tracker" +COM_PATCHTESTER_PULL_ID = "Pull-ID" +COM_PATCHTESTER_NO_CREDENTIALS = "In den Optionen wurden noch keine Benutzerdaten eingetragen. Deshalb können höchstens 60 Anfragen pro Stunde an das Github API gestellt werden. Mit Benutzerdaten sind bis zu 5.000 Anfragen pro Stunde möglich." +COM_PATCHTESTER_NO_FILES_TO_PATCH = "Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind." +COM_PATCHTESTER_NO_ITEMS = "Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen." +COM_PATCHTESTER_NOT_APPLIED = "Nicht angewendet" +COM_PATCHTESTER_NOT_RTC = "Nicht RTC" +COM_PATCHTESTER_READY_TO_COMMIT = "Ready to Commit" +COM_PATCHTESTER_REPO_IS_GONE = "Der Patch konnte nicht angewendet werden, weil das Repository fehlt" +COM_PATCHTESTER_REQUIREMENT_HTTPS = "HTTPS Wrapper müssen aktiviert sein" +COM_PATCHTESTER_REQUIREMENT_OPENSSL = "Die OpenSSL-Erweiterung muss installiert und in der php.ini aktivert sein" +COM_PATCHTESTER_REQUIREMENTS_HEADING = "Die Vorraussetzungen sind nicht erfüllt" +COM_PATCHTESTER_REQUIREMENTS_NOT_MET = "Ihr System erfüllt nicht die Vorraussetzungen um den Patch-Tester auszuführen:" +COM_PATCHTESTER_RESET_HAS_ERRORS = "Die Daten wurden zurück gesetzt. Leider sind dabei Fehler aufgetreten. Bitte entferne alle .txt Dateien im Verzeichnis '%1$s' und leere die Datenbanktabelle '%2$s'." +COM_PATCHTESTER_RESET_OK = "Die Daten wurden erfolgreich zurück gesetzt." +COM_PATCHTESTER_REVERT_OK = "Der Patch wurde erfolgreich entfernt" +COM_PATCHTESTER_REVERT_PATCH = "Patch entfernen" +COM_PATCHTESTER_RTC = "RTC" +COM_PATCHTESTER_SERVER_RESPONDED_NOT_200 = "Es konnte entweder keine Verbindung zum Server aufgebaut werden oder der angegebene Pull Request existiert nicht auf dem Server." +COM_PATCHTESTER_TEST_THIS_PATCH = "Diesen Patch testen" +COM_PATCHTESTER_TOOLBAR_FETCH_DATA = "Daten abrufen" +COM_PATCHTESTER_TOOLBAR_RESET = "Zurücksetzen" +COM_PATCHTESTER_ZIP_DOES_NOT_EXIST="Der Patch konnte nicht angewendet werden, weil er nicht vom Server heruntergeladen werden konnte." +COM_PATCHTESTER_ZIP_EXTRACT_FAILED="Der Patch konnte nicht angewendet werden, weil nicht entpackt werden konnte." + + diff --git a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini index 609779c..629461d 100644 --- a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini @@ -28,6 +28,8 @@ COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE="Error truncating the pulls table: COM_PATCHTESTER_ERROR_TRUNCATING_TESTS_TABLE="Error truncating the tests table: %s" COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING="The patch's files are encoded in an unsupported format." COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND="View not found [name, format]: %1$s, %2$s" +COM_PATCHTESTER_FAILED_APPLYING_PATCH="Patch could not be applied due to exception with %1$s. %2$s" +COM_PATCHTESTER_FAILED_REVERT_PATCH="Patch could not be reverted due to exception with %1$s. %2$s" COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED="An error has occurred while fetching the data from GitHub." COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW="All data has been retrieved. Please close this modal window to refresh the page." COM_PATCHTESTER_FETCH_INITIALIZING="Preparing to fetch GitHub data" @@ -91,8 +93,12 @@ COM_PATCHTESTER_RESET_OK="The reset process has completed successfully." COM_PATCHTESTER_REVERT_OK="Patch successfully reverted" COM_PATCHTESTER_REVERT_PATCH="Revert Patch" COM_PATCHTESTER_RTC="RTC" +COM_PATCHTESTER_SERVER_RESPONDED_NOT_200 ="The patch could not be applied either due to missing connection to the server or missing patch on the server." COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch" COM_PATCHTESTER_TOOLBAR_FETCH_DATA="Fetch Data" COM_PATCHTESTER_TOOLBAR_RESET="Reset" COM_PATCHTESTER_VIEW_ON_GITHUB="View on GitHub" COM_PATCHTESTER_VIEW_ON_JOOMLA_ISSUE_TRACKER="View on Joomla! Issue Tracker" +COM_PATCHTESTER_ZIP_DOES_NOT_EXIST="The patch could not be applied, because it couldn't be retrieved from server." +COM_PATCHTESTER_ZIP_EXTRACT_FAILED="The patch could not be applied, because it couldn't be extracted." + diff --git a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini index 3be4ff4..b36225b 100644 --- a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini @@ -28,6 +28,8 @@ COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE="Error truncating the pulls table: COM_PATCHTESTER_ERROR_TRUNCATING_TESTS_TABLE="Error truncating the tests table: %s" COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING="The patch's files are encoded in an unsupported format." COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND="View not found [name, format]: %1$s, %2$s" +COM_PATCHTESTER_FAILED_APPLYING_PATCH="Patch could not be applied due to exception with %1$s. %2$s" +COM_PATCHTESTER_FAILED_REVERT_PATCH="Patch could not be reverted due to exception with %1$s. %2$s" COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED="An error has occurred while fetching the data from GitHub." COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW="All data has been retrieved. Please close this modal window to refresh the page." COM_PATCHTESTER_FETCH_INITIALIZING="Preparing to fetch GitHub data" @@ -88,7 +90,10 @@ COM_PATCHTESTER_RESET_OK="The reset process has completed successfully." COM_PATCHTESTER_REVERT_OK="Patch successfully reverted" COM_PATCHTESTER_REVERT_PATCH="Revert Patch" COM_PATCHTESTER_RTC="RTC" +COM_PATCHTESTER_SERVER_RESPONDED_NOT_200 ="The patch could not be applied either due to missing connection to the server or missing patch on the server." COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch" COM_PATCHTESTER_TOOLBAR_FETCH_DATA="Fetch Data" COM_PATCHTESTER_TOOLBAR_RESET="Reset" +COM_PATCHTESTER_ZIP_DOES_NOT_EXIST="The patch could not be applied, because it couldn't be retrieved from server." +COM_PATCHTESTER_ZIP_EXTRACT_FAILED="The patch could not be applied, because it couldn't be extracted." From b5bd81143e71ea9c25eb05f527f2800db241a761 Mon Sep 17 00:00:00 2001 From: datsepp Date: Wed, 11 Sep 2019 13:57:14 +0200 Subject: [PATCH 09/27] Fixed deleting files from master. --- .../com_patchtester/PatchTester/Helper.php | 2 +- .../PatchTester/Model/PullModel.php | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index c7b3a6c..ae6eae3 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -75,7 +75,7 @@ abstract class Helper $options = new Registry; // Set CI server address for the request - $options->set('server.url', 'https://stuff.gramma.name'); + $options->set('server.url', 'https://joomla-dev.lukaskimpel.com'); // Set name of the zip archive $options->set('zip.name', 'build.zip'); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 9145892..a022773 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -187,8 +187,17 @@ class PullModel extends AbstractModel $github = Helper::initializeGithub(); // retrieve pullData for sha later on. - $pull = $this->retrieveGitHubData($github, $id); - $sha = $pull->head->sha; + try + { + $pull = $this->retrieveGitHubData($github, $id); + $sha = $pull->head->sha; + } + catch (\RuntimeException $e) + { + // Catch the Exception and continue, because the hash is not that + // necessary for applying patches + $sha = "Error:429"; + } // Create tmp folder if it does not exist if (!file_exists($ciSettings->get('folder.temp'))) @@ -241,6 +250,7 @@ class PullModel extends AbstractModel // get files from deleted_logs $deletedFiles = file($delLogPath); + $deletedFiles = array_map('trim', $deletedFiles); // remove deleted_logs to avoid get listing afterwards File::delete($delLogPath); @@ -257,7 +267,7 @@ class PullModel extends AbstractModel { try { - $filePath = explode("\\", $file); + $filePath = explode("\\", Path::clean($file)); array_pop($filePath); $filePath = implode("\\", $filePath); @@ -301,7 +311,7 @@ class PullModel extends AbstractModel // Clear temp folder and store applied patch in database Folder::delete($tempPath); - $this->saveAppliedPatch($id, $files); + $this->saveAppliedPatch($id, $files, $sha); // Change the media version $version = new Version; From 13bc747b71ab3e0f59e6e51d7e9f8ce18ba8e57d Mon Sep 17 00:00:00 2001 From: datsepp Date: Wed, 11 Sep 2019 14:57:35 +0200 Subject: [PATCH 10/27] Added configuration support for CI-Server. Now it is possible to switch between methods of applying patches. --- .../com_patchtester/PatchTester/Helper.php | 4 +- .../PatchTester/Model/PullModel.php | 26 +-- .../components/com_patchtester/config.xml | 162 +++++++++++------- .../language/de-DE/de-DE.com_patchtester.ini | 8 + .../language/en-GB/en-GB.com_patchtester.ini | 8 + .../language/en-US/en-US.com_patchtester.ini | 8 + 6 files changed, 138 insertions(+), 78 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index ae6eae3..bfdd39e 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -72,10 +72,12 @@ abstract class Helper */ public static function initializeCISettings() { + $params = ComponentHelper::getParams('com_patchtester'); + $options = new Registry; // Set CI server address for the request - $options->set('server.url', 'https://joomla-dev.lukaskimpel.com'); + $options->set('server.url', $params->get('ci_server', 'https://ci.joomla.org')); // Set name of the zip archive $options->set('zip.name', 'build.zip'); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index a022773..e1ed6af 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -156,7 +156,7 @@ class PullModel extends AbstractModel $params = ComponentHelper::getParams('com_patchtester'); // Decide based on repository settings whether patch will be applied through Github or CIServer - if ($params->get('repo', 'joomla-cms') === 'joomla-cms' + if ((bool) $params->get('ci_switch', 1) && $params->get('repo', 'joomla-cms') === 'joomla-cms' && $params->get('org', 'joomla') === 'joomla') { return $this->applyWithCIServer($id); @@ -249,11 +249,14 @@ class PullModel extends AbstractModel File::delete($zipPath); // get files from deleted_logs - $deletedFiles = file($delLogPath); + $deletedFiles = (file($delLogPath) ? file($delLogPath) : []); $deletedFiles = array_map('trim', $deletedFiles); - // remove deleted_logs to avoid get listing afterwards - File::delete($delLogPath); + if(file_exists($delLogPath)) + { + // remove deleted_logs to avoid get listing afterwards + File::delete($delLogPath); + } // retrieve all files and merge them into one array $files = Folder::files($tempPath, null, true, true); @@ -289,20 +292,21 @@ class PullModel extends AbstractModel File::move(JPATH_ROOT . "/$file", "$backupsPath/$file"); } - // Create directories if they don't exist until file - if (!file_exists(JPATH_ROOT . "/$filePath") || !is_dir(JPATH_ROOT . "/$filePath")) - { - Folder::create(JPATH_ROOT . "/$filePath"); - } - if (file_exists("$tempPath/$file")) { + // Create directories if they don't exist until file + if (!file_exists(JPATH_ROOT . "/$filePath") || !is_dir(JPATH_ROOT . "/$filePath")) + { + Folder::create(JPATH_ROOT . "/$filePath"); + } + File::copy("$tempPath/$file", JPATH_ROOT . "/$file"); } } catch(\RuntimeException $e) { Folder::delete($tempPath); + Folder::move($backupsPath, $backupsPath . "_failed"); throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_FAILED_APPLYING_PATCH', $file, $e->getMessage())); } @@ -576,7 +580,7 @@ class PullModel extends AbstractModel $params = ComponentHelper::getParams('com_patchtester'); // Decide based on repository settings whether patch will be applied through Github or CIServer - if ($params->get('repo', 'joomla-cms') === 'joomla-cms' + if ((bool) $params->get('ci_switch', 1) && $params->get('repo', 'joomla-cms') === 'joomla-cms' && $params->get('org', 'joomla') === 'joomla') { return $this->revertWithCIServer($id); diff --git a/administrator/components/com_patchtester/config.xml b/administrator/components/com_patchtester/config.xml index d45b607..6aec092 100644 --- a/administrator/components/com_patchtester/config.xml +++ b/administrator/components/com_patchtester/config.xml @@ -2,63 +2,65 @@
+ name="repositories" + label="COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL" + description="COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC" + > + name="repository" + type="list" + label="COM_PATCHTESTER_FIELD_REPOSITORY_LABEL" + description="COM_PATCHTESTER_FIELD_REPOSITORY_DESC" + default="joomla:joomla-cms" + onchange="if (jQuery(this).val() != 'custom') { var parts = jQuery(this).val().split(':'); } else { var parts = ['', '']; } document.getElementById('jform_org').value = parts[0]; document.getElementById('jform_repo').value = parts[1];" + > - +
+ name="authentication" + label="COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL" + description="COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC" + > + > @@ -66,49 +68,77 @@
+ name="ci_settings" + label="COM_PATCHTESTER_FIELDSET_CI_SETTINGS" + description="COM_PATCHTESTER_FIELDSET_CI_SETTINGS_DESC" + > + + + + + + +
+ +
+ +
diff --git a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini index 1ab18e7..6060e24 100644 --- a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini @@ -59,10 +59,18 @@ COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER = "Joomla! Patch-Tester Komp COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB = "Joomla! Webkataloginstallations-Plugin" COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS = "Joomla! Weblinks-Paket" COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM = "Benutzerdefiniert" +COM_PATCHTESTER_FIELD_CI_SERVER_NAME="CI Server Adresse" +COM_PATCHTESTER_FIELD_CI_SERVER_NAME_DESC="Server Adresse für das Herunterladen kompilierter Patches." +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH="Switch CI Integration" +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_DESC="Schaltet die CI Integration an oder aus." +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_ON="An" +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_OFF="Aus" COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC = "Konfigurationswerte für GitHub Repository" COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL = "GitHub Repository" COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC = "Konfigurationswerte für GitHub Authentifizierung" COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL = "GitHub Authentifizierung" +COM_PATCHTESTER_FIELDSET_CI_SETTINGS="CI Server Einstellungen" +COM_PATCHTESTER_FIELDSET_CI_SETTINGS_DESC="Konfigurationswerte für CI Server Patching" COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S = "Die zu löschende Datei existiert nicht: %s" COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S = "Die zu ändernde Datei existiert nicht: %s" COM_PATCHTESTER_FILTER_APPLIED_PATCHES = "Angewendete Patches filtern" diff --git a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini index 629461d..911ad15 100644 --- a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini @@ -59,10 +59,18 @@ COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER="Joomla! Patch Tester Compon COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB="Joomla! Install From Web Plugin" COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS="Joomla! Weblinks Package" COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM="Custom" +COM_PATCHTESTER_FIELD_CI_SERVER_NAME="CI Server Address" +COM_PATCHTESTER_FIELD_CI_SERVER_NAME_DESC="Server address for obtaining compiled patches." +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH="Switch CI Integration" +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_DESC="Turn CI integration on or off." +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_ON="On" +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_OFF="Off" COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC="Configuration Values for GitHub Repository" COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL="GitHub Repository" COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC="Configuration Values for GitHub Authentication" COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL="GitHub Authentication" +COM_PATCHTESTER_FIELDSET_CI_SETTINGS="CI Server Settings" +COM_PATCHTESTER_FIELDSET_CI_SETTINGS_DESC="Configuration Values for CI Server Patching" COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S="The file marked for deletion does not exist: %s" COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="The file marked for modification does not exist: %s" COM_PATCHTESTER_FILTER_APPLIED_PATCHES="Filter Applied Patches" diff --git a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini index b36225b..131e127 100644 --- a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini @@ -59,10 +59,18 @@ COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER="Joomla! Patch Tester Compon COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB="Joomla! Install From Web Plugin" COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS="Joomla! Weblinks Package" COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM="Custom" +COM_PATCHTESTER_FIELD_CI_SERVER_NAME="CI Server Address" +COM_PATCHTESTER_FIELD_CI_SERVER_NAME_DESC="Server address for obtaining compiled patches." +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH="Switch CI Integration" +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_DESC="Turn CI integration on or off." +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_ON="On" +COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_OFF="Off" COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC="Configuration Values for GitHub Repository" COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL="GitHub Repository" COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC="Configuration Values for GitHub Authentication" COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL="GitHub Authentication" +COM_PATCHTESTER_FIELDSET_CI_SETTINGS="CI Server Settings" +COM_PATCHTESTER_FIELDSET_CI_SETTINGS_DESC="Configuration Values for CI Server Patching" COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S="The file marked for deletion does not exist: %s" COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="The file marked for modification does not exist: %s" COM_PATCHTESTER_FILTER_APPLIED_PATCHES="Filter Applied Patches" From 7360369c5b57bd9c9e756d72af34d615db3b6f89 Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Wed, 11 Sep 2019 22:51:03 +0200 Subject: [PATCH 11/27] Added patch chain to lock order of reverting - avoid demolishing own installation by accident. --- .../com_patchtester/PatchTester/Helper.php | 1 + .../PatchTester/Model/PullModel.php | 29 +++++++++++++++++++ .../language/de-DE/de-DE.com_patchtester.ini | 1 + .../language/en-GB/en-GB.com_patchtester.ini | 1 + .../language/en-US/en-US.com_patchtester.ini | 1 + composer.json | 3 +- 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index bfdd39e..b408f8b 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -82,6 +82,7 @@ abstract class Helper // Set name of the zip archive $options->set('zip.name', 'build.zip'); $options->set('zip.log.name', 'deleted_files.log'); + $options->set('zip.chain.name', 'patch_chain.log'); // Set temp archive for extracting and downloading files $options->set('folder.temp', Factory::getConfig()->get('tmp_path')); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index e1ed6af..37bf7f3 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -208,6 +208,7 @@ class PullModel extends AbstractModel $tempPath = $ciSettings->get('folder.temp') . "/$id"; $backupsPath = $ciSettings->get('folder.backups') . "/$id"; + $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); $delLogPath = $tempPath . '/' . $ciSettings->get('zip.log.name'); $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); @@ -317,6 +318,19 @@ class PullModel extends AbstractModel $this->saveAppliedPatch($id, $files, $sha); + // Write or create patch chain for correct order of patching + if (!file_exists($patchChainPath) || filesize($patchChainPath) === 0) + { + File::write($patchChainPath, $id); + } + else + { + // Remove any from php set EOL in log file, add id and rewrite file + $patchChain = explode(PHP_EOL, file_get_contents($patchChainPath)); + $patchChain[] = $id; + File::write($patchChainPath, implode(PHP_EOL, $patchChain)); + } + // Change the media version $version = new Version; $version->refreshMediaVersion(); @@ -608,6 +622,21 @@ class PullModel extends AbstractModel $testRecord = $this->getTestRecord($id); + // Get PatchChain as array, remove any EOL set by php + $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); + $patchChain = array_reverse(explode(PHP_EOL, file_get_contents($patchChainPath))); + + // Allow only reverts in order of the patch chain + if ($patchChain[0] != $testRecord->pull_id) + { + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain[sizeof($patchChain)-1])); + } + else + { + array_shift($patchChain); + File::write($patchChainPath, implode(PHP_EOL, $patchChain)); + } + // We don't want to restore files from an older version if ($testRecord->applied_version != JVERSION) { diff --git a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini index 6060e24..3b9191b 100644 --- a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini @@ -86,6 +86,7 @@ COM_PATCHTESTER_NO_CREDENTIALS = "In den Optionen wurden noch keine Benutzerdate COM_PATCHTESTER_NO_FILES_TO_PATCH = "Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind." COM_PATCHTESTER_NO_ITEMS = "Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen." COM_PATCHTESTER_NOT_APPLIED = "Nicht angewendet" +COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="Der Patch kann nicht zurückgesetzt werden, es muss zunächst erstmal der Patch mit der Pull ID %s zurückgesetzt werden." COM_PATCHTESTER_NOT_RTC = "Nicht RTC" COM_PATCHTESTER_READY_TO_COMMIT = "Ready to Commit" COM_PATCHTESTER_REPO_IS_GONE = "Der Patch konnte nicht angewendet werden, weil das Repository fehlt" diff --git a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini index 911ad15..86071a3 100644 --- a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini @@ -85,6 +85,7 @@ COM_PATCHTESTER_NO_CREDENTIALS="You have not entered your user credentials in th COM_PATCHTESTER_NO_FILES_TO_PATCH="There are no files to patch from this pull request. This may mean that the files in the pull request are not present in your installation." COM_PATCHTESTER_NO_ITEMS="No data has been retrieved from GitHub, please click the 'Fetch Data' button in the toolbar to retrieve the open pull requests." COM_PATCHTESTER_NOT_APPLIED="Not Applied" +COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="You can't revert this patch, you need to revert the patch with the pull id %s first." COM_PATCHTESTER_NOT_RTC="Not RTC" COM_PATCHTESTER_PULL_ID="Pull ID" COM_PATCHTESTER_PULL_ID_ASC="Pull ID ascending" diff --git a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini index 131e127..711789b 100644 --- a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini @@ -86,6 +86,7 @@ COM_PATCHTESTER_NO_CREDENTIALS="You have not entered your user credentials in th COM_PATCHTESTER_NO_FILES_TO_PATCH="There are no files to patch from this pull request. This may mean that the files in the pull request are not present in your installation." COM_PATCHTESTER_NO_ITEMS="No data has been retrieved from GitHub, please click the 'Fetch Data' button in the toolbar to retrieve the open pull requests." COM_PATCHTESTER_NOT_APPLIED="Not Applied" +COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="You can't revert this patch, you need to revert the patch with the pull id %s first." COM_PATCHTESTER_NOT_RTC="Not RTC" COM_PATCHTESTER_READY_TO_COMMIT="Ready to Commit" COM_PATCHTESTER_REPO_IS_GONE="The patch could not be applied because the repository is missing" diff --git a/composer.json b/composer.json index 3e1206a..28b6db4 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "vendor-dir": "administrator/components/com_patchtester/vendor" }, "require": { - "php": "^5.3.10|^7.0" + "php": "^7.0", + "ext-json": "*" }, "require-dev": { "php": "^5.6|^7.0", From 1006702eb85c485bad6dbc666c9bda1e132f7301 Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Wed, 11 Sep 2019 22:51:03 +0200 Subject: [PATCH 12/27] Added patch chain to lock order of reverting - avoid demolishing own installation by accident. Fix of some mistakes in Patch Chain. --- .../com_patchtester/PatchTester/Helper.php | 1 + .../PatchTester/Model/PullModel.php | 29 +++++++++++++++++++ .../language/de-DE/de-DE.com_patchtester.ini | 1 + .../language/en-GB/en-GB.com_patchtester.ini | 1 + .../language/en-US/en-US.com_patchtester.ini | 1 + composer.json | 3 +- 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index bfdd39e..b408f8b 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -82,6 +82,7 @@ abstract class Helper // Set name of the zip archive $options->set('zip.name', 'build.zip'); $options->set('zip.log.name', 'deleted_files.log'); + $options->set('zip.chain.name', 'patch_chain.log'); // Set temp archive for extracting and downloading files $options->set('folder.temp', Factory::getConfig()->get('tmp_path')); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index e1ed6af..bab5052 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -208,6 +208,7 @@ class PullModel extends AbstractModel $tempPath = $ciSettings->get('folder.temp') . "/$id"; $backupsPath = $ciSettings->get('folder.backups') . "/$id"; + $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); $delLogPath = $tempPath . '/' . $ciSettings->get('zip.log.name'); $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); @@ -317,6 +318,19 @@ class PullModel extends AbstractModel $this->saveAppliedPatch($id, $files, $sha); + // Write or create patch chain for correct order of patching + if (!file_exists($patchChainPath) || filesize($patchChainPath) === 0) + { + File::write($patchChainPath, $id); + } + else + { + // Remove any from php set EOL in log file, add id and rewrite file + $patchChain = explode(PHP_EOL, file_get_contents($patchChainPath)); + $patchChain[] = $id; + File::write($patchChainPath, implode(PHP_EOL, $patchChain)); + } + // Change the media version $version = new Version; $version->refreshMediaVersion(); @@ -608,6 +622,21 @@ class PullModel extends AbstractModel $testRecord = $this->getTestRecord($id); + // Get PatchChain as array, remove any EOL set by php + $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); + $patchChain = array_reverse(explode(PHP_EOL, file_get_contents($patchChainPath))); + + // Allow only reverts in order of the patch chain + if ($patchChain[0] != $testRecord->pull_id) + { + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain[0])); + } + else + { + array_shift($patchChain); + File::write($patchChainPath, implode(PHP_EOL, array_reverse($patchChain))); + } + // We don't want to restore files from an older version if ($testRecord->applied_version != JVERSION) { diff --git a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini index 6060e24..3b9191b 100644 --- a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini @@ -86,6 +86,7 @@ COM_PATCHTESTER_NO_CREDENTIALS = "In den Optionen wurden noch keine Benutzerdate COM_PATCHTESTER_NO_FILES_TO_PATCH = "Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind." COM_PATCHTESTER_NO_ITEMS = "Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen." COM_PATCHTESTER_NOT_APPLIED = "Nicht angewendet" +COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="Der Patch kann nicht zurückgesetzt werden, es muss zunächst erstmal der Patch mit der Pull ID %s zurückgesetzt werden." COM_PATCHTESTER_NOT_RTC = "Nicht RTC" COM_PATCHTESTER_READY_TO_COMMIT = "Ready to Commit" COM_PATCHTESTER_REPO_IS_GONE = "Der Patch konnte nicht angewendet werden, weil das Repository fehlt" diff --git a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini index 911ad15..86071a3 100644 --- a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini @@ -85,6 +85,7 @@ COM_PATCHTESTER_NO_CREDENTIALS="You have not entered your user credentials in th COM_PATCHTESTER_NO_FILES_TO_PATCH="There are no files to patch from this pull request. This may mean that the files in the pull request are not present in your installation." COM_PATCHTESTER_NO_ITEMS="No data has been retrieved from GitHub, please click the 'Fetch Data' button in the toolbar to retrieve the open pull requests." COM_PATCHTESTER_NOT_APPLIED="Not Applied" +COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="You can't revert this patch, you need to revert the patch with the pull id %s first." COM_PATCHTESTER_NOT_RTC="Not RTC" COM_PATCHTESTER_PULL_ID="Pull ID" COM_PATCHTESTER_PULL_ID_ASC="Pull ID ascending" diff --git a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini index 131e127..711789b 100644 --- a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini @@ -86,6 +86,7 @@ COM_PATCHTESTER_NO_CREDENTIALS="You have not entered your user credentials in th COM_PATCHTESTER_NO_FILES_TO_PATCH="There are no files to patch from this pull request. This may mean that the files in the pull request are not present in your installation." COM_PATCHTESTER_NO_ITEMS="No data has been retrieved from GitHub, please click the 'Fetch Data' button in the toolbar to retrieve the open pull requests." COM_PATCHTESTER_NOT_APPLIED="Not Applied" +COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="You can't revert this patch, you need to revert the patch with the pull id %s first." COM_PATCHTESTER_NOT_RTC="Not RTC" COM_PATCHTESTER_READY_TO_COMMIT="Ready to Commit" COM_PATCHTESTER_REPO_IS_GONE="The patch could not be applied because the repository is missing" diff --git a/composer.json b/composer.json index 3e1206a..28b6db4 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "vendor-dir": "administrator/components/com_patchtester/vendor" }, "require": { - "php": "^5.3.10|^7.0" + "php": "^7.0", + "ext-json": "*" }, "require-dev": { "php": "^5.6|^7.0", From a321ad0d2f5f54b2b57f55e34f3e7fcaf1185d55 Mon Sep 17 00:00:00 2001 From: datsepp Date: Thu, 12 Sep 2019 09:04:05 +0200 Subject: [PATCH 13/27] Changed parameter of revert from db_id to pull_id. Configured resetController to remove first all git patches and then revert all ci patches in order of patchChain. --- .../Controller/ResetController.php | 51 +++++++++++++++---- .../PatchTester/Model/PullModel.php | 6 +-- .../View/Pulls/tmpl/default_items.php | 2 +- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php index 7bb551f..c345768 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php @@ -13,6 +13,7 @@ use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\Filesystem\File; +use PatchTester\Helper; use PatchTester\Model\PullModel; use PatchTester\Model\PullsModel; use PatchTester\Model\TestsModel; @@ -41,9 +42,23 @@ class ResetController extends AbstractController $pullsModel = new PullsModel($this->context, null, Factory::getDbo()); $testsModel = new TestsModel(null, Factory::getDbo()); + // Get the CIServer Registry + $ciSettings = Helper::initializeCISettings(); + + // Get PatchChain as array, remove any EOL set by php + $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); + $patchChain = array_reverse(explode(PHP_EOL, file_get_contents($patchChainPath))); + // Check the applied patches in the database first $appliedPatches = $testsModel->getAppliedPatches(); + if (count($patchChain) && count($appliedPatches)) + { + // Get only the pull_id and remove all occurrences with patchChain + $appliedPatches = array_map(function($patch) { return $patch->pull_id; }, $appliedPatches); + $appliedPatches = array_diff($appliedPatches, $patchChain); + } + if (count($appliedPatches)) { $revertErrored = false; @@ -53,32 +68,50 @@ class ResetController extends AbstractController { try { - $pullModel->revert($patch->id); + $pullModel->revertWithGitHub($patch); } catch (\RuntimeException $e) { $revertErrored = true; } } + } - // If we errored out reverting patches, we'll need to truncate the table - if ($revertErrored) + if (count($patchChain)) + { + $revertErrored = false; + + // Let's try to cleanly revert all applied patches with ci + foreach ($patchChain as $patch) { try { - $testsModel->truncateTable(); + $pullModel->revertWithCIServer($patch); } catch (\RuntimeException $e) { - $hasErrors = true; - - $this->getApplication()->enqueueMessage( - Text::sprintf('COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE', $e->getMessage()), 'error' - ); + $revertErrored = true; } } } + // If we errored out reverting patches, we'll need to truncate the table + if ($revertErrored) + { + try + { + $testsModel->truncateTable(); + } + catch (\RuntimeException $e) + { + $hasErrors = true; + + $this->getApplication()->enqueueMessage( + Text::sprintf('COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE', $e->getMessage()), 'error' + ); + } + } + // Now truncate the pulls table try { diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index bab5052..c30d782 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -615,7 +615,7 @@ class PullModel extends AbstractModel * @since 3.0 * @throws \RuntimeException */ - private function revertWithCIServer($id) + public function revertWithCIServer($id) { // Get the CIServer Registry $ciSettings = Helper::initializeCISettings(); @@ -714,7 +714,7 @@ class PullModel extends AbstractModel * @since 2.0 * @throws \RuntimeException */ - private function revertWithGitHub($id) + public function revertWithGitHub($id) { $testRecord = $this->getTestRecord($id); @@ -861,7 +861,7 @@ class PullModel extends AbstractModel $db->getQuery(true) ->select('*') ->from('#__patchtester_tests') - ->where('id = ' . (int) $id) + ->where('pull_id = ' . (int) $id) )->loadObject(); } } 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 f829d66..5c334c2 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 @@ -63,7 +63,7 @@ foreach ($this->items as $i => $item) : applied) : ?> - + From 3b1f1578daf2a2dd27310106002d8302da534e2d Mon Sep 17 00:00:00 2001 From: datsepp Date: Thu, 12 Sep 2019 10:52:34 +0200 Subject: [PATCH 14/27] Reworked patchChain as json to store pull_id and db_id for checking later on on reverting or resetting. --- .../Controller/ResetController.php | 5 ++-- .../com_patchtester/PatchTester/Helper.php | 2 +- .../PatchTester/Model/PullModel.php | 27 ++++++++++--------- .../View/Pulls/tmpl/default_items.php | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php index c345768..c0b2fda 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php @@ -47,7 +47,7 @@ class ResetController extends AbstractController // Get PatchChain as array, remove any EOL set by php $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); - $patchChain = array_reverse(explode(PHP_EOL, file_get_contents($patchChainPath))); + $patchChain = array_reverse(json_decode(file_get_contents($patchChainPath))); // Check the applied patches in the database first $appliedPatches = $testsModel->getAppliedPatches(); @@ -55,7 +55,8 @@ class ResetController extends AbstractController if (count($patchChain) && count($appliedPatches)) { // Get only the pull_id and remove all occurrences with patchChain - $appliedPatches = array_map(function($patch) { return $patch->pull_id; }, $appliedPatches); + $appliedPatches = array_map(function($patch) { return $patch->id; }, $appliedPatches); + $patchChain = array_map(function($patch) { return $patch->id; }, $patchChain); $appliedPatches = array_diff($appliedPatches, $patchChain); } diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index b408f8b..df9a2d9 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -82,7 +82,7 @@ abstract class Helper // Set name of the zip archive $options->set('zip.name', 'build.zip'); $options->set('zip.log.name', 'deleted_files.log'); - $options->set('zip.chain.name', 'patch_chain.log'); + $options->set('zip.chain.name', 'patch_chain.json'); // Set temp archive for extracting and downloading files $options->set('folder.temp', Factory::getConfig()->get('tmp_path')); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index c30d782..04b97ad 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -316,19 +316,19 @@ class PullModel extends AbstractModel // Clear temp folder and store applied patch in database Folder::delete($tempPath); - $this->saveAppliedPatch($id, $files, $sha); + $lastInserted = $this->saveAppliedPatch($id, $files, $sha); // Write or create patch chain for correct order of patching if (!file_exists($patchChainPath) || filesize($patchChainPath) === 0) { - File::write($patchChainPath, $id); + File::write($patchChainPath, json_encode([["id" => $lastInserted, "pull_id" => $id]])); } else { // Remove any from php set EOL in log file, add id and rewrite file - $patchChain = explode(PHP_EOL, file_get_contents($patchChainPath)); - $patchChain[] = $id; - File::write($patchChainPath, implode(PHP_EOL, $patchChain)); + $patchChain = json_decode(file_get_contents($patchChainPath)); + $patchChain[] = ["id" => $lastInserted, "pull_id" => $id]; + File::write($patchChainPath, json_encode($patchChain)); } // Change the media version @@ -548,7 +548,7 @@ class PullModel extends AbstractModel * @param array $fileList List of files * @param string $sha sha-key from pull request * - * @return void + * @return integer $id last inserted id * * @since 3.0 */ @@ -565,6 +565,7 @@ class PullModel extends AbstractModel $db = $this->getDb(); $db->insertObject('#__patchtester_tests', $record); + $insertId = $db->insertid(); if (!is_null($sha)) { @@ -576,6 +577,8 @@ class PullModel extends AbstractModel ->where($db->quoteName('pull_id') . ' = ' . (int) $id) )->execute(); } + + return $insertId; } /** @@ -624,17 +627,17 @@ class PullModel extends AbstractModel // Get PatchChain as array, remove any EOL set by php $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); - $patchChain = array_reverse(explode(PHP_EOL, file_get_contents($patchChainPath))); + $patchChain = array_reverse(json_decode(file_get_contents($patchChainPath))); // Allow only reverts in order of the patch chain - if ($patchChain[0] != $testRecord->pull_id) + if ($patchChain[0]->id != $id) { - throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain[0])); + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain[0]->pull_id)); } else { array_shift($patchChain); - File::write($patchChainPath, implode(PHP_EOL, array_reverse($patchChain))); + File::write($patchChainPath, json_encode(array_reverse($patchChain))); } // We don't want to restore files from an older version @@ -831,7 +834,7 @@ class PullModel extends AbstractModel $db->getQuery(true) ->update('#__patchtester_pulls') ->set('sha = ' . $db->quote('')) - ->where($db->quoteName('pull_id') . ' = ' . (int) $testRecord->pull_id) + ->where($db->quoteName('id') . ' = ' . (int) $testRecord->id) )->execute(); // And delete the record from the tests table @@ -861,7 +864,7 @@ class PullModel extends AbstractModel $db->getQuery(true) ->select('*') ->from('#__patchtester_tests') - ->where('pull_id = ' . (int) $id) + ->where('id = ' . (int) $id) )->loadObject(); } } 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 5c334c2..f829d66 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 @@ -63,7 +63,7 @@ foreach ($this->items as $i => $item) : applied) : ?> - + From 26b5399df6d781a236af9b637add08e724c2f396 Mon Sep 17 00:00:00 2001 From: datsepp Date: Thu, 12 Sep 2019 12:08:51 +0200 Subject: [PATCH 15/27] First attempt to move the patch_chain.json to database. --- .../Controller/ResetController.php | 28 +--- .../PatchTester/Model/PullModel.php | 129 +++++++++++++++--- .../install/sql/mysql/install.sql | 7 + .../install/sql/mysql/uninstall.sql | 1 + .../install/sql/postgresql/install.sql | 7 + .../install/sql/postgresql/uninstall.sql | 1 + .../install/sql/sqlsrv/install.sql | 10 ++ .../install/sql/sqlsrv/uninstall.sql | 1 + .../install/sql/updates/mysql/4.0.0.sql | 6 + .../install/sql/updates/postgresql/4.0.0.sql | 6 + .../install/sql/updates/sqlsrv/4.0.0.sql | 9 ++ 11 files changed, 166 insertions(+), 39 deletions(-) create mode 100644 administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql create mode 100644 administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql create mode 100644 administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php index c0b2fda..074c35f 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php @@ -13,7 +13,6 @@ use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\Filesystem\File; -use PatchTester\Helper; use PatchTester\Model\PullModel; use PatchTester\Model\PullsModel; use PatchTester\Model\TestsModel; @@ -42,25 +41,10 @@ class ResetController extends AbstractController $pullsModel = new PullsModel($this->context, null, Factory::getDbo()); $testsModel = new TestsModel(null, Factory::getDbo()); - // Get the CIServer Registry - $ciSettings = Helper::initializeCISettings(); - - // Get PatchChain as array, remove any EOL set by php - $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); - $patchChain = array_reverse(json_decode(file_get_contents($patchChainPath))); - // Check the applied patches in the database first - $appliedPatches = $testsModel->getAppliedPatches(); + $appliedPatches = $pullModel->getPatchesDividedInProcs(); - if (count($patchChain) && count($appliedPatches)) - { - // Get only the pull_id and remove all occurrences with patchChain - $appliedPatches = array_map(function($patch) { return $patch->id; }, $appliedPatches); - $patchChain = array_map(function($patch) { return $patch->id; }, $patchChain); - $appliedPatches = array_diff($appliedPatches, $patchChain); - } - - if (count($appliedPatches)) + if (count($appliedPatches[0])) { $revertErrored = false; @@ -69,7 +53,7 @@ class ResetController extends AbstractController { try { - $pullModel->revertWithGitHub($patch); + $pullModel->revertWithGitHub($patch->id); } catch (\RuntimeException $e) { @@ -78,16 +62,16 @@ class ResetController extends AbstractController } } - if (count($patchChain)) + if (count($appliedPatches[1])) { $revertErrored = false; // Let's try to cleanly revert all applied patches with ci - foreach ($patchChain as $patch) + foreach ($appliedPatches as $patch) { try { - $pullModel->revertWithCIServer($patch); + $pullModel->revertWithCIServer($patch->id); } catch (\RuntimeException $e) { diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 04b97ad..cb3b832 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -208,7 +208,6 @@ class PullModel extends AbstractModel $tempPath = $ciSettings->get('folder.temp') . "/$id"; $backupsPath = $ciSettings->get('folder.backups') . "/$id"; - $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); $delLogPath = $tempPath . '/' . $ciSettings->get('zip.log.name'); $zipPath = $tempPath . '/' . $ciSettings->get('zip.name'); @@ -319,17 +318,7 @@ class PullModel extends AbstractModel $lastInserted = $this->saveAppliedPatch($id, $files, $sha); // Write or create patch chain for correct order of patching - if (!file_exists($patchChainPath) || filesize($patchChainPath) === 0) - { - File::write($patchChainPath, json_encode([["id" => $lastInserted, "pull_id" => $id]])); - } - else - { - // Remove any from php set EOL in log file, add id and rewrite file - $patchChain = json_decode(file_get_contents($patchChainPath)); - $patchChain[] = ["id" => $lastInserted, "pull_id" => $id]; - File::write($patchChainPath, json_encode($patchChain)); - } + $this->appendPatchChain($lastInserted, $id); // Change the media version $version = new Version; @@ -626,18 +615,16 @@ class PullModel extends AbstractModel $testRecord = $this->getTestRecord($id); // Get PatchChain as array, remove any EOL set by php - $patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name'); - $patchChain = array_reverse(json_decode(file_get_contents($patchChainPath))); + $patchChain = $this->getLastChain(); // Allow only reverts in order of the patch chain - if ($patchChain[0]->id != $id) + if ($patchChain[0]->insert_id != $id) { throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain[0]->pull_id)); } else { - array_shift($patchChain); - File::write($patchChainPath, json_encode(array_reverse($patchChain))); + $this->removeLastChain($patchChain[0]->insert_id); } // We don't want to restore files from an older version @@ -867,4 +854,112 @@ class PullModel extends AbstractModel ->where('id = ' . (int) $id) )->loadObject(); } + + /** + * Retrieves a list of patches in chain + * + * @return mixed + * + * @since 3.0 + */ + private function getPatchChain() + { + $db = $this->getDb(); + + $db->setQuery( + $db->getQuery(true) + ->select('*') + ->from($db->quoteName('#__patchtester_chain')) + ->order('id DESC') + ); + + return $db->loadObjectList('pull_id'); + } + + /** + * Returns the last value of the ci patch chain + * + * @return stdClass $chain last chain of the table + * + * @since 3.0.0 + */ + private function getLastChain() + { + $db = $this->getDb(); + + return $db->setQuery( + $db->getQuery(true) + ->select('*') + ->from('#__patchtester_chain') + ->order('id DESC'), 0, 1 + )->loadObject(); + } + + /** + * Returns a two dimensional array with applied patches + * by the github or ci procedure + * + * @return array two-dimensional array with github patches + * and ci patches + * + * @since 3.0.0 + */ + public function getPatchesDividedInProcs() + { + $db = $this->getDb(); + + $appliedByGit = $db->setQuery( + $db->getQuery(true) + ->select('pulls.id, pulls.pull_id') + ->from('#__patchtester_chain chain') + ->leftJoin('#__patchtester_pulls pulls', 'chain.id != pulls.id') + )->loadObject(); + + $appliedByCI = $this->getPatchChain(); + + return [$appliedByGit, $appliedByCI]; + } + + /** + * Adds a value to the patch chain in the database + * + * @param integer $insertId ID of the patch in the database + * @param integer $pullId ID of the pull request + * + * @return integer $insertId last inserted element + * + * @since 3.0.0 + */ + private function appendPatchChain($insertId, $pullId) + { + $record = (object) array( + 'insert_id' => $insertId, + 'pull_id' => $pullId, + ); + + $db = $this->getDb(); + + $db->insertObject('#__patchtester_chain', $record); + return $db->insertid(); + } + + /** + * Removes the last value of the chain + * + * @param integer $insertId ID of the patch in the database + * + * @return void + * + * @since 3.0.0 + */ + private function removeLastChain($insertId) + { + $db = $this->getDb(); + + $db->setQuery( + $db->getQuery(true) + ->delete('#__patchtester_chain') + ->where('insert_id = ' . (int) $insertId) + )->execute(); + } } diff --git a/administrator/components/com_patchtester/install/sql/mysql/install.sql b/administrator/components/com_patchtester/install/sql/mysql/install.sql index 2210654..a76d520 100644 --- a/administrator/components/com_patchtester/install/sql/mysql/install.sql +++ b/administrator/components/com_patchtester/install/sql/mysql/install.sql @@ -19,3 +19,10 @@ CREATE TABLE IF NOT EXISTS `#__patchtester_tests` ( `applied_version` varchar(25) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `#__patchtester_chain` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `insert_id` int(11) NOT NULL + `pull_id` int(11) NOT NULL + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/administrator/components/com_patchtester/install/sql/mysql/uninstall.sql b/administrator/components/com_patchtester/install/sql/mysql/uninstall.sql index 3c1bf05..8f9a6b6 100644 --- a/administrator/components/com_patchtester/install/sql/mysql/uninstall.sql +++ b/administrator/components/com_patchtester/install/sql/mysql/uninstall.sql @@ -1,2 +1,3 @@ DROP TABLE IF EXISTS `#__patchtester_pulls`; DROP TABLE IF EXISTS `#__patchtester_tests`; +DROP TABLE IF EXISTS `#__patchtester_chain`; diff --git a/administrator/components/com_patchtester/install/sql/postgresql/install.sql b/administrator/components/com_patchtester/install/sql/postgresql/install.sql index 45c96ad..f000ca0 100644 --- a/administrator/components/com_patchtester/install/sql/postgresql/install.sql +++ b/administrator/components/com_patchtester/install/sql/postgresql/install.sql @@ -19,3 +19,10 @@ CREATE TABLE IF NOT EXISTS "#__patchtester_tests" ( "applied_version" character varying(25) NOT NULL, PRIMARY KEY ("id") ); + +CREATE TABLE IF NOT EXISTS "#__patchtester_chain" ( + "id" serial NOT NULL, + "insert_id" bigint NOT NULL, + "pull_id" bigint NOT NULL + PRIMARY KEY (`id`) +); diff --git a/administrator/components/com_patchtester/install/sql/postgresql/uninstall.sql b/administrator/components/com_patchtester/install/sql/postgresql/uninstall.sql index 9fcc3f6..a972c22 100644 --- a/administrator/components/com_patchtester/install/sql/postgresql/uninstall.sql +++ b/administrator/components/com_patchtester/install/sql/postgresql/uninstall.sql @@ -1,2 +1,3 @@ DROP TABLE IF EXISTS "#__patchtester_pulls"; DROP TABLE IF EXISTS "#__patchtester_tests"; +DROP TABLE IF EXISTS "#__patchtester_chain"; diff --git a/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql b/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql index ae89443..a6d5998 100644 --- a/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql +++ b/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql @@ -25,3 +25,13 @@ CREATE TABLE [#__patchtester_tests]( [id] ASC ) WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ); + +CREATE TABLE [#__patchtester_chain] ( + [id] [bigint] IDENTITY(1,1) NOT NULL, + [insert_id] [bigint] NOT NULL + [pull_id] [bigint] NOT NULL + CONSTRAINT [PK_#__patchtester_chain] PRIMARY KEY CLUSTERED +( + [id] ASC +) WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) +); diff --git a/administrator/components/com_patchtester/install/sql/sqlsrv/uninstall.sql b/administrator/components/com_patchtester/install/sql/sqlsrv/uninstall.sql index f396275..53c9b4e 100644 --- a/administrator/components/com_patchtester/install/sql/sqlsrv/uninstall.sql +++ b/administrator/components/com_patchtester/install/sql/sqlsrv/uninstall.sql @@ -1,2 +1,3 @@ DROP TABLE [#__patchtester_pulls]; DROP TABLE [#__patchtester_tests]; +DROP TABLE [#__patchtester_chain]; diff --git a/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql b/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql new file mode 100644 index 0000000..a92d4e8 --- /dev/null +++ b/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS `#__patchtester_chain` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `insert_id` int(11) NOT NULL + `pull_id` int(11) NOT NULL + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql b/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql new file mode 100644 index 0000000..83a2e6c --- /dev/null +++ b/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS "#__patchtester_chain" ( + "id" serial NOT NULL, + "insert_id" bigint NOT NULL, + "pull_id" bigint NOT NULL + PRIMARY KEY (`id`) +); diff --git a/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql b/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql new file mode 100644 index 0000000..35049c7 --- /dev/null +++ b/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql @@ -0,0 +1,9 @@ +CREATE TABLE [#__patchtester_chain] ( + [id] [bigint] IDENTITY(1,1) NOT NULL, + [insert_id] [bigint] NOT NULL + [pull_id] [bigint] NOT NULL + CONSTRAINT [PK_#__patchtester_chain] PRIMARY KEY CLUSTERED +( + [id] ASC +) WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) +); From 4ffb145b610972100a7b8199e8d4faeb51573a77 Mon Sep 17 00:00:00 2001 From: datsepp Date: Thu, 12 Sep 2019 12:58:17 +0200 Subject: [PATCH 16/27] Fixes to previous commit. --- .../PatchTester/Controller/ResetController.php | 11 ++++++----- .../com_patchtester/PatchTester/Helper.php | 1 - .../PatchTester/Model/PullModel.php | 17 +++++++++-------- .../install/sql/mysql/install.sql | 4 ++-- .../install/sql/postgresql/install.sql | 2 +- .../install/sql/sqlsrv/install.sql | 4 ++-- .../install/sql/updates/mysql/4.0.0.sql | 4 ++-- .../install/sql/updates/postgresql/4.0.0.sql | 2 +- .../install/sql/updates/sqlsrv/4.0.0.sql | 4 ++-- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php index 074c35f..ec852f8 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php @@ -44,12 +44,12 @@ class ResetController extends AbstractController // Check the applied patches in the database first $appliedPatches = $pullModel->getPatchesDividedInProcs(); - if (count($appliedPatches[0])) + if (count($appliedPatches["git"])) { $revertErrored = false; // Let's try to cleanly revert all applied patches - foreach ($appliedPatches as $patch) + foreach ($appliedPatches["git"] as $patch) { try { @@ -62,16 +62,17 @@ class ResetController extends AbstractController } } - if (count($appliedPatches[1])) + if (count($appliedPatches["ci"])) { + $revertErrored = false; // Let's try to cleanly revert all applied patches with ci - foreach ($appliedPatches as $patch) + foreach ($appliedPatches["ci"] as $patch) { try { - $pullModel->revertWithCIServer($patch->id); + $pullModel->revertWithCIServer($patch->insert_id); } catch (\RuntimeException $e) { diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index df9a2d9..bfdd39e 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -82,7 +82,6 @@ abstract class Helper // Set name of the zip archive $options->set('zip.name', 'build.zip'); $options->set('zip.log.name', 'deleted_files.log'); - $options->set('zip.chain.name', 'patch_chain.json'); // Set temp archive for extracting and downloading files $options->set('folder.temp', Factory::getConfig()->get('tmp_path')); diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index cb3b832..e449a2e 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -618,13 +618,13 @@ class PullModel extends AbstractModel $patchChain = $this->getLastChain(); // Allow only reverts in order of the patch chain - if ($patchChain[0]->insert_id != $id) + if ($patchChain->insert_id != $id) { - throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain[0]->pull_id)); + throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain->pull_id)); } else { - $this->removeLastChain($patchChain[0]->insert_id); + $this->removeLastChain($patchChain->insert_id); } // We don't want to restore files from an older version @@ -910,14 +910,15 @@ class PullModel extends AbstractModel $appliedByGit = $db->setQuery( $db->getQuery(true) - ->select('pulls.id, pulls.pull_id') - ->from('#__patchtester_chain chain') - ->leftJoin('#__patchtester_pulls pulls', 'chain.id != pulls.id') - )->loadObject(); + ->select('tests.id, tests.pull_id') + ->from('#__patchtester_tests tests') + ->leftJoin('#__patchtester_chain chain', 'tests.id = chain.insert_id') + ->where('chain.insert_id IS NULL') + )->loadObjectList('pull_id'); $appliedByCI = $this->getPatchChain(); - return [$appliedByGit, $appliedByCI]; + return ["git" => $appliedByGit, "ci" => $appliedByCI]; } /** diff --git a/administrator/components/com_patchtester/install/sql/mysql/install.sql b/administrator/components/com_patchtester/install/sql/mysql/install.sql index a76d520..9113485 100644 --- a/administrator/components/com_patchtester/install/sql/mysql/install.sql +++ b/administrator/components/com_patchtester/install/sql/mysql/install.sql @@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS `#__patchtester_tests` ( CREATE TABLE IF NOT EXISTS `#__patchtester_chain` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `insert_id` int(11) NOT NULL - `pull_id` int(11) NOT NULL + `insert_id` int(11) NOT NULL, + `pull_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/administrator/components/com_patchtester/install/sql/postgresql/install.sql b/administrator/components/com_patchtester/install/sql/postgresql/install.sql index f000ca0..85a2ba9 100644 --- a/administrator/components/com_patchtester/install/sql/postgresql/install.sql +++ b/administrator/components/com_patchtester/install/sql/postgresql/install.sql @@ -23,6 +23,6 @@ CREATE TABLE IF NOT EXISTS "#__patchtester_tests" ( CREATE TABLE IF NOT EXISTS "#__patchtester_chain" ( "id" serial NOT NULL, "insert_id" bigint NOT NULL, - "pull_id" bigint NOT NULL + "pull_id" bigint NOT NULL, PRIMARY KEY (`id`) ); diff --git a/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql b/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql index a6d5998..119b506 100644 --- a/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql +++ b/administrator/components/com_patchtester/install/sql/sqlsrv/install.sql @@ -28,8 +28,8 @@ CREATE TABLE [#__patchtester_tests]( CREATE TABLE [#__patchtester_chain] ( [id] [bigint] IDENTITY(1,1) NOT NULL, - [insert_id] [bigint] NOT NULL - [pull_id] [bigint] NOT NULL + [insert_id] [bigint] NOT NULL, + [pull_id] [bigint] NOT NULL, CONSTRAINT [PK_#__patchtester_chain] PRIMARY KEY CLUSTERED ( [id] ASC diff --git a/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql b/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql index a92d4e8..44d1d88 100644 --- a/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql +++ b/administrator/components/com_patchtester/install/sql/updates/mysql/4.0.0.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS `#__patchtester_chain` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `insert_id` int(11) NOT NULL - `pull_id` int(11) NOT NULL + `insert_id` int(11) NOT NULL, + `pull_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql b/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql index 83a2e6c..fb4458d 100644 --- a/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql +++ b/administrator/components/com_patchtester/install/sql/updates/postgresql/4.0.0.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS "#__patchtester_chain" ( "id" serial NOT NULL, "insert_id" bigint NOT NULL, - "pull_id" bigint NOT NULL + "pull_id" bigint NOT NULL, PRIMARY KEY (`id`) ); diff --git a/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql b/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql index 35049c7..3c6fac8 100644 --- a/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql +++ b/administrator/components/com_patchtester/install/sql/updates/sqlsrv/4.0.0.sql @@ -1,7 +1,7 @@ CREATE TABLE [#__patchtester_chain] ( [id] [bigint] IDENTITY(1,1) NOT NULL, - [insert_id] [bigint] NOT NULL - [pull_id] [bigint] NOT NULL + [insert_id] [bigint] NOT NULL, + [pull_id] [bigint] NOT NULL, CONSTRAINT [PK_#__patchtester_chain] PRIMARY KEY CLUSTERED ( [id] ASC From f9eb75c1b77b3094465a6897a1ffe525f68a4138 Mon Sep 17 00:00:00 2001 From: datsepp Date: Thu, 12 Sep 2019 15:25:46 +0200 Subject: [PATCH 17/27] Added gate way to prevent reverting ci applied pulls with git option. Now they will be removed by ci automatically. --- .../PatchTester/Model/PullModel.php | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index e449a2e..a7396f4 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -156,8 +156,7 @@ class PullModel extends AbstractModel $params = ComponentHelper::getParams('com_patchtester'); // Decide based on repository settings whether patch will be applied through Github or CIServer - if ((bool) $params->get('ci_switch', 1) && $params->get('repo', 'joomla-cms') === 'joomla-cms' - && $params->get('org', 'joomla') === 'joomla') + if ((bool) $params->get('ci_switch', 1)) { return $this->applyWithCIServer($id); } @@ -586,8 +585,7 @@ class PullModel extends AbstractModel $params = ComponentHelper::getParams('com_patchtester'); // Decide based on repository settings whether patch will be applied through Github or CIServer - if ((bool) $params->get('ci_switch', 1) && $params->get('repo', 'joomla-cms') === 'joomla-cms' - && $params->get('org', 'joomla') === 'joomla') + if ((bool) $params->get('ci_switch', 1) || $id === $this->getPatchChain($id)->insert_id) { return $this->revertWithCIServer($id); } @@ -615,7 +613,7 @@ class PullModel extends AbstractModel $testRecord = $this->getTestRecord($id); // Get PatchChain as array, remove any EOL set by php - $patchChain = $this->getLastChain(); + $patchChain = $this->getPatchChain(-1); // Allow only reverts in order of the patch chain if ($patchChain->insert_id != $id) @@ -862,7 +860,7 @@ class PullModel extends AbstractModel * * @since 3.0 */ - private function getPatchChain() + private function getPatchChains() { $db = $this->getDb(); @@ -877,22 +875,39 @@ class PullModel extends AbstractModel } /** - * Returns the last value of the ci patch chain + * Returns a chain by specific value, returns the last + * element on $id = -1 and the first on $id = null + * + * @param integer $id specific id of a pull * * @return stdClass $chain last chain of the table * * @since 3.0.0 */ - private function getLastChain() + private function getPatchChain($id = null) { - $db = $this->getDb(); + $db = $this->getDb(); - return $db->setQuery( - $db->getQuery(true) - ->select('*') - ->from('#__patchtester_chain') - ->order('id DESC'), 0, 1 - )->loadObject(); + $query = $db->getQuery(true) + ->select('*') + ->from('#__patchtester_chain'); + + if (!is_null($id) && $id !== -1) + { + $query = $query->where('insert_id =' . (int) $id); + } + + if ($id === -1) + { + $query = $query->order('id DESC'); + } + + if (is_null($id)) + { + $query = $query->order('id ASC'); + } + + return $db->setQuery($query,0,1)->loadObject(); } /** @@ -916,7 +931,7 @@ class PullModel extends AbstractModel ->where('chain.insert_id IS NULL') )->loadObjectList('pull_id'); - $appliedByCI = $this->getPatchChain(); + $appliedByCI = $this->getPatchChains(); return ["git" => $appliedByGit, "ci" => $appliedByCI]; } From f958707cafeef4348608f70df3757f3b533d4047 Mon Sep 17 00:00:00 2001 From: datsepp Date: Thu, 12 Sep 2019 15:43:41 +0200 Subject: [PATCH 18/27] Modified default value for server.url in ciSettings. --- administrator/components/com_patchtester/PatchTester/Helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index bfdd39e..bb9b11c 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -88,7 +88,7 @@ abstract class Helper $options->set('folder.backups', JPATH_COMPONENT . '/backups'); // Set full url for addressing the file - $options->set('zip.url', $options->get('server.url') . '/%s/' . $options->get('zip.name')); + $options->set('zip.url', $options->get('server.url') . '/artifacts/joomla-cms/4.0-dev/%s/patchtester/' . $options->get('zip.name')); return $options; } From 0e1d2017f13dc0fc0e564b17035fdde1b501ecfe Mon Sep 17 00:00:00 2001 From: Sebb Date: Thu, 12 Sep 2019 15:49:23 +0200 Subject: [PATCH 19/27] Updated composer.lock --- composer.lock | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 7adfec8..38c9fb1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "35e372f08cd218b7040fd37d8e7dcaeb", + "content-hash": "74b98490277fecd02473d802a0fe279a", "packages": [], "packages-dev": [ { @@ -375,12 +375,12 @@ "source": { "type": "git", "url": "https://github.com/joomla-projects/crowdin-sync.git", - "reference": "8a61f12161b30ff4aa0402ad0dccd599b38714af" + "reference": "c1db9d2186a273b66297f4fbf239bbc06b70a9fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-projects/crowdin-sync/zipball/8a61f12161b30ff4aa0402ad0dccd599b38714af", - "reference": "8a61f12161b30ff4aa0402ad0dccd599b38714af", + "url": "https://api.github.com/repos/joomla-projects/crowdin-sync/zipball/c1db9d2186a273b66297f4fbf239bbc06b70a9fb", + "reference": "c1db9d2186a273b66297f4fbf239bbc06b70a9fb", "shasum": "" }, "require": { @@ -401,7 +401,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "CLI application to synchronize a project with Crowdin", "homepage": "https://github.com/joomla-projects/crowdin-sync", @@ -409,7 +409,7 @@ "crowdin", "joomla" ], - "time": "2019-03-29T12:07:12+00:00" + "time": "2019-09-10T14:24:41+00:00" }, { "name": "joomla/filter", @@ -1067,7 +1067,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^5.3.10|^7.0" + "php": "^7.0", + "ext-json": "*" }, "platform-dev": { "php": "^5.6|^7.0" From 5daeb04450e9b776ffd9bf368e49484ac00d460f Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Sat, 14 Sep 2019 18:54:57 +0200 Subject: [PATCH 20/27] Updated some lines to Joomla coding standards. --- .../Controller/ResetController.php | 1 - .../PatchTester/Model/PullModel.php | 32 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php index ec852f8..a3ec0f8 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php @@ -64,7 +64,6 @@ class ResetController extends AbstractController if (count($appliedPatches["ci"])) { - $revertErrored = false; // Let's try to cleanly revert all applied patches with ci diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index a7396f4..4687a97 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -185,7 +185,7 @@ class PullModel extends AbstractModel // Get the Github object $github = Helper::initializeGithub(); - // retrieve pullData for sha later on. + // Retrieve pullData for sha later on. try { $pull = $this->retrieveGitHubData($github, $id); @@ -244,20 +244,20 @@ class PullModel extends AbstractModel throw new \RuntimeException(Text::_('COM_PATCHTESTER_ZIP_EXTRACT_FAILED')); } - // remove zip to avoid get listing afterwards + // Remove zip to avoid get listing afterwards File::delete($zipPath); - // get files from deleted_logs + // Get files from deleted_logs $deletedFiles = (file($delLogPath) ? file($delLogPath) : []); $deletedFiles = array_map('trim', $deletedFiles); - if(file_exists($delLogPath)) + if (file_exists($delLogPath)) { - // remove deleted_logs to avoid get listing afterwards + // Remove deleted_logs to avoid get listing afterwards File::delete($delLogPath); } - // retrieve all files and merge them into one array + // Retrieve all files and merge them into one array $files = Folder::files($tempPath, null, true, true); $files = str_replace(Path::clean("$tempPath\\"), '', $files); $files = array_merge($files, $deletedFiles); @@ -273,7 +273,7 @@ class PullModel extends AbstractModel array_pop($filePath); $filePath = implode("\\", $filePath); - // deleted_logs returns files as well as folder, if value is folder, unset and skip + // Deleted_logs returns files as well as folder, if value is folder, unset and skip if (is_dir(JPATH_ROOT . "/$file")) { unset($files[$key]); @@ -302,7 +302,7 @@ class PullModel extends AbstractModel File::copy("$tempPath/$file", JPATH_ROOT . "/$file"); } } - catch(\RuntimeException $e) + catch (\RuntimeException $e) { Folder::delete($tempPath); @@ -487,8 +487,8 @@ class PullModel extends AbstractModel /** * Patches the code with the supplied pull request * - * @param GitHub $github github object - * @param integer $id Id of the pull request + * @param GitHub $github github object + * @param integer $id Id of the pull request * * @return Response * @@ -651,7 +651,6 @@ class PullModel extends AbstractModel // Delete file from root of it exists if (file_Exists(JPATH_ROOT . "/$file")) { - File::delete(JPATH_ROOT . "/$file"); // Move from backup, if it exists there @@ -677,7 +676,7 @@ class PullModel extends AbstractModel File::move("$backupsPath/$file", JPATH_ROOT . "/$file"); } } - catch(\RuntimeException $e) + catch (\RuntimeException $e) { throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_FAILED_REVERT_PATCH', $file, $e->getMessage())); } @@ -837,7 +836,7 @@ class PullModel extends AbstractModel * * @param integer $id ID of the record * - * @return stdClass $testRecord The record looking for + * @return stdClass $testRecord The record looking for * * @since 3.0.0 */ @@ -878,9 +877,9 @@ class PullModel extends AbstractModel * Returns a chain by specific value, returns the last * element on $id = -1 and the first on $id = null * - * @param integer $id specific id of a pull + * @param integer $id specific id of a pull * - * @return stdClass $chain last chain of the table + * @return stdClass $chain last chain of the table * * @since 3.0.0 */ @@ -907,7 +906,7 @@ class PullModel extends AbstractModel $query = $query->order('id ASC'); } - return $db->setQuery($query,0,1)->loadObject(); + return $db->setQuery($query, 0, 1)->loadObject(); } /** @@ -956,6 +955,7 @@ class PullModel extends AbstractModel $db = $this->getDb(); $db->insertObject('#__patchtester_chain', $record); + return $db->insertid(); } From b5b063650287f6254a4b66fc6a40a464c561167b Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Sun, 15 Sep 2019 18:23:58 +0200 Subject: [PATCH 21/27] Re-added J3 templates and replaced JScript via anchor with event binding. Removed temp folder and updated build.sh script. --- .../PatchTester/View/Pulls/tmpl/default.php | 235 +++++++----------- .../View/Pulls/tmpl/default_items.php | 73 +++--- .../language/en-GB/en-GB.com_patchtester.ini | 1 - .../components/com_patchtester/temp/readme.md | 1 - .../html/com_patchtester/fetch/default.php | 28 +++ .../html/com_patchtester/pulls/default.php | 163 ++++++++++++ .../com_patchtester/pulls/default_items.php | 72 ++++++ build/patchtester/build.sh | 1 + 8 files changed, 396 insertions(+), 178 deletions(-) delete mode 100644 administrator/components/com_patchtester/temp/readme.md create mode 100644 administrator/templates/atum/html/com_patchtester/fetch/default.php create mode 100644 administrator/templates/atum/html/com_patchtester/pulls/default.php create mode 100644 administrator/templates/atum/html/com_patchtester/pulls/default_items.php 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 6467150..fcc7ad5 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php +++ b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php @@ -6,158 +6,115 @@ * @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::_('searchtools.form', '#adminForm', $searchToolsOptions); +HTMLHelper::_('bootstrap.tooltip'); +HTMLHelper::_('formbehavior.chosen', 'select'); 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->getLimitBox(); ?> +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + items)) : ?> +
+ +
+ + + + + + + + + + trackerAlias !== false) : ?> + + + + + + + loadTemplate('items'); ?> + +
+ + + + + + + + + + + + + + + +
+ - pagination->getListFooter(); ?> + pagination->getListFooter(); ?> - - - - -
-
-
-
- + + + + +
+ \ No newline at end of file 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 f829d66..126ca22 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 @@ -9,64 +9,63 @@ use Joomla\CMS\Language\Text; /** @var \PatchTester\View\DefaultHtmlView $this */ - foreach ($this->items as $i => $item) : $status = ''; - if ($item->applied) : - $status = ' class="table-active"'; + $status = ' class="success"'; 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) : ?> - +
- '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 new file mode 100644 index 0000000..6467150 --- /dev/null +++ b/administrator/templates/atum/html/com_patchtester/pulls/default.php @@ -0,0 +1,163 @@ + 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 new file mode 100644 index 0000000..f829d66 --- /dev/null +++ b/administrator/templates/atum/html/com_patchtester/pulls/default_items.php @@ -0,0 +1,72 @@ +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) : ?> + + + + + + + Date: Wed, 18 Sep 2019 15:13:24 +0200 Subject: [PATCH 22/27] Re-configured CI url in Helper and in default values for CI settings. --- .../components/com_patchtester/PatchTester/Helper.php | 4 ++-- administrator/components/com_patchtester/config.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Helper.php b/administrator/components/com_patchtester/PatchTester/Helper.php index bb9b11c..80e1853 100644 --- a/administrator/components/com_patchtester/PatchTester/Helper.php +++ b/administrator/components/com_patchtester/PatchTester/Helper.php @@ -77,7 +77,7 @@ abstract class Helper $options = new Registry; // Set CI server address for the request - $options->set('server.url', $params->get('ci_server', 'https://ci.joomla.org')); + $options->set('server.url', $params->get('ci_server', 'https://ci.joomla.org:444')); // Set name of the zip archive $options->set('zip.name', 'build.zip'); @@ -88,7 +88,7 @@ abstract class Helper $options->set('folder.backups', JPATH_COMPONENT . '/backups'); // Set full url for addressing the file - $options->set('zip.url', $options->get('server.url') . '/artifacts/joomla-cms/4.0-dev/%s/patchtester/' . $options->get('zip.name')); + $options->set('zip.url', $options->get('server.url') . '/artifacts/joomla/joomla-cms/4.0-dev/%s/patchtester/' . $options->get('zip.name')); return $options; } diff --git a/administrator/components/com_patchtester/config.xml b/administrator/components/com_patchtester/config.xml index 6aec092..e80c43b 100644 --- a/administrator/components/com_patchtester/config.xml +++ b/administrator/components/com_patchtester/config.xml @@ -109,7 +109,7 @@ label="COM_PATCHTESTER_FIELD_CI_SERVER_NAME" description="COM_PATCHTESTER_FIELD_CI_SERVER_NAME_DESC" autocomplete="off" - default="https://ci.joomla.org" + default="https://ci.joomla.org:444" /> Date: Mon, 23 Sep 2019 15:33:46 +0200 Subject: [PATCH 23/27] Added an additional condition to ignore the "apply by ci path" automatically if j3 is used. Fixed a bug where patches could be applied by the old patcher even if there are no files to patch, because they got ignored during parsing. --- .../com_patchtester/PatchTester/Model/PullModel.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 4687a97..928e16d 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -156,7 +156,7 @@ class PullModel extends AbstractModel $params = ComponentHelper::getParams('com_patchtester'); // Decide based on repository settings whether patch will be applied through Github or CIServer - if ((bool) $params->get('ci_switch', 1)) + if (version_compare(JVERSION, "4", "ge") && (bool) $params->get('ci_switch', 1)) { return $this->applyWithCIServer($id); } @@ -366,6 +366,11 @@ class PullModel extends AbstractModel $parsedFiles = $this->parseFileList($files); + if (!count($parsedFiles)) + { + return false; + } + foreach ($parsedFiles as $file) { switch ($file->action) @@ -585,7 +590,7 @@ class PullModel extends AbstractModel $params = ComponentHelper::getParams('com_patchtester'); // Decide based on repository settings whether patch will be applied through Github or CIServer - if ((bool) $params->get('ci_switch', 1) || $id === $this->getPatchChain($id)->insert_id) + if (version_compare(JVERSION, "4", "ge") && ((bool) $params->get('ci_switch', 1) || $id === $this->getPatchChain($id)->insert_id)) { return $this->revertWithCIServer($id); } From 986b6cf36c34f5beb7abcc62250d348ad0e2738c Mon Sep 17 00:00:00 2001 From: Sebastian Enns <34925579+datsepp@users.noreply.github.com> Date: Mon, 30 Sep 2019 12:10:54 +0200 Subject: [PATCH 24/27] Apply suggestions from code review Removed white spaces between separators and short-array syntax Co-Authored-By: SharkyKZ --- .../components/com_patchtester/PatchTester/Model/PullModel.php | 2 +- .../com_patchtester/language/en-GB/en-GB.com_patchtester.ini | 2 +- .../com_patchtester/language/en-US/en-US.com_patchtester.ini | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 928e16d..5c61f64 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -248,7 +248,7 @@ class PullModel extends AbstractModel File::delete($zipPath); // Get files from deleted_logs - $deletedFiles = (file($delLogPath) ? file($delLogPath) : []); + $deletedFiles = (file($delLogPath) ? file($delLogPath) : array()); $deletedFiles = array_map('trim', $deletedFiles); if (file_exists($delLogPath)) diff --git a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini index 6481cd0..bb7a7bc 100644 --- a/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini @@ -102,7 +102,7 @@ COM_PATCHTESTER_RESET_OK="The reset process has completed successfully." COM_PATCHTESTER_REVERT_OK="Patch successfully reverted" COM_PATCHTESTER_REVERT_PATCH="Revert Patch" COM_PATCHTESTER_RTC="RTC" -COM_PATCHTESTER_SERVER_RESPONDED_NOT_200 ="The patch could not be applied either due to missing connection to the server or missing patch on the server." +COM_PATCHTESTER_SERVER_RESPONDED_NOT_200="The patch could not be applied either due to missing connection to the server or missing patch on the server." COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch" COM_PATCHTESTER_TOOLBAR_FETCH_DATA="Fetch Data" COM_PATCHTESTER_TOOLBAR_RESET="Reset" diff --git a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini index 711789b..6220024 100644 --- a/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/en-US/en-US.com_patchtester.ini @@ -99,7 +99,7 @@ COM_PATCHTESTER_RESET_OK="The reset process has completed successfully." COM_PATCHTESTER_REVERT_OK="Patch successfully reverted" COM_PATCHTESTER_REVERT_PATCH="Revert Patch" COM_PATCHTESTER_RTC="RTC" -COM_PATCHTESTER_SERVER_RESPONDED_NOT_200 ="The patch could not be applied either due to missing connection to the server or missing patch on the server." +COM_PATCHTESTER_SERVER_RESPONDED_NOT_200="The patch could not be applied either due to missing connection to the server or missing patch on the server." COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch" COM_PATCHTESTER_TOOLBAR_FETCH_DATA="Fetch Data" COM_PATCHTESTER_TOOLBAR_RESET="Reset" From 5a19d0a2a3848db416711805fafa36ad303831f6 Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Mon, 30 Sep 2019 12:13:48 +0200 Subject: [PATCH 25/27] Reverted some changes f.e. white-spaces between separators in ini files and already removed new lines, changed to single quotes instead of double quotes where necessary, reformatted config and template files and reverted changes in composer.json file. --- .../Controller/ResetController.php | 8 +- .../PatchTester/Model/PullModel.php | 2 +- .../PatchTester/View/Pulls/tmpl/default.php | 173 +++++++++-------- .../View/Pulls/tmpl/default_items.php | 80 ++++---- .../components/com_patchtester/config.xml | 155 ++++++++------- .../language/de-DE/de-DE.com_patchtester.ini | 181 +++++++++--------- .../com_patchtester/pulls/default_items.php | 76 ++++---- composer.json | 3 +- 8 files changed, 349 insertions(+), 329 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php index a3ec0f8..334f750 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ResetController.php @@ -44,12 +44,12 @@ class ResetController extends AbstractController // Check the applied patches in the database first $appliedPatches = $pullModel->getPatchesDividedInProcs(); - if (count($appliedPatches["git"])) + if (count($appliedPatches['git'])) { $revertErrored = false; // Let's try to cleanly revert all applied patches - foreach ($appliedPatches["git"] as $patch) + foreach ($appliedPatches['git'] as $patch) { try { @@ -62,12 +62,12 @@ class ResetController extends AbstractController } } - if (count($appliedPatches["ci"])) + if (count($appliedPatches['ci'])) { $revertErrored = false; // Let's try to cleanly revert all applied patches with ci - foreach ($appliedPatches["ci"] as $patch) + foreach ($appliedPatches['ci'] as $patch) { try { diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php index 928e16d..f15b0e0 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullModel.php @@ -937,7 +937,7 @@ class PullModel extends AbstractModel $appliedByCI = $this->getPatchChains(); - return ["git" => $appliedByGit, "ci" => $appliedByCI]; + return array('git' => $appliedByGit, 'ci' => $appliedByCI); } /** 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 fcc7ad5..8fb3e7c 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php +++ b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php @@ -10,111 +10,126 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; -/** @var \PatchTester\View\Pulls\PullsHtmlView $this */ +/** @var \PatchTester\View\Pulls\PullsHtmlView $this */ + HTMLHelper::_('behavior.core'); HTMLHelper::_('bootstrap.tooltip'); HTMLHelper::_('formbehavior.chosen', 'select'); 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')); + +$listOrder = $this->escape($this->state->get('list.fullordering', 'a.pull_id DESC')); $filterApplied = $this->escape($this->state->get('filter.applied')); -$filterBranch = $this->escape($this->state->get('filter.branch')); -$filterRtc = $this->escape($this->state->get('filter.rtc')); +$filterBranch = $this->escape($this->state->get('filter.branch')); +$filterRtc = $this->escape($this->state->get('filter.rtc')); ?> -
-
-
- -
- - -
-
- + +
+
+ +
+ + +
+
+ pagination->getLimitBox(); ?> -
-
- - -
-
- - -
-
- - -
-
- - -
-
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
items)) : ?> -
+
-
+
- - - -
+ + + + - + - + - + - + + trackerAlias !== false) : ?> - + - - + - - - + + + + loadTemplate('items'); ?> - -
- + - + - + - + - + - + - + -
+ +
pagination->getListFooter(); ?> - - - + + + -
+
\ No newline at end of file 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 126ca22..50fbea9 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 @@ -9,63 +9,71 @@ use Joomla\CMS\Language\Text; /** @var \PatchTester\View\DefaultHtmlView $this */ + foreach ($this->items as $i => $item) : $status = ''; + if ($item->applied) : $status = ' class="success"'; endif; ?> - > - + > + pull_id; ?> - - - escape($item->title); ?> + + + escape($item->title); ?> applied) : ?> -
- sha, 0, 10)); ?> -
+
+ sha, 0, 10)); ?> +
- - + + escape($item->branch); ?> - - + + is_rtc) : ?> - + - + - - - - - - + + + + + + trackerAlias !== false) : ?> - - - - - + + + + + - + applied) : ?> -
- -
+
+ +
- + - - + + applied) : ?> -
+ +
- + - - + +
- +
@@ -68,56 +65,56 @@
@@ -126,19 +123,19 @@
diff --git a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini index 3b9191b..3427036 100644 --- a/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini +++ b/administrator/components/com_patchtester/language/de-DE/de-DE.com_patchtester.ini @@ -3,108 +3,105 @@ ; License GNU General Public License version 2 or later ; Note : All ini files need to be saved as UTF-8 -COM_PATCHTESTER = "Joomla! Patch Tester" -COM_PATCHTESTER_40_WARNING = "Solange Joomla! 4.0 in der Entwicklung ist, muss der Patch-Tester als experimentell angesehen werden, da Änderungen in Joomla, einschließlich des in einem Patch enthaltenen Codes, möglicherweise nicht rückwärts-kompatibel sind." -COM_PATCHTESTER_API_LIMIT_ACTION = "Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die angeforderte Aktion anzuführen. Das Limit wird um %s zurückgesetzt" -COM_PATCHTESTER_API_LIMIT_LIST = "Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die Daten zu aktualisieren. Das Limit wird um %s zurückgesetzt" -COM_PATCHTESTER_APPLIED = "Angewendet" -COM_PATCHTESTER_APPLIED_COMMIT_SHA = "Angewandter Commit SHA: %s" -COM_PATCHTESTER_APPLY_OK = "Patch erfolgreich angewendet" -COM_PATCHTESTER_APPLY_PATCH = "Patch installieren" -COM_PATCHTESTER_BRANCH = "Versionszweig" -COM_PATCHTESTER_CONFIGURATION = "Joomla! Patch-Tester Einstellungen" -COM_PATCHTESTER_CONFIRM_RESET = "Das Zurücksetzen versucht, alle installierten Patches rückgängig zu machen. Dabei werden alle Backup-Dateien entfernt. Dies könnte dazu führen, dass die Umgebung nicht mehr stabil ist. Sind Sie sicher, dass Sie fortfahren möchten?" -COM_PATCHTESTER_CONFLICT_S = "Der Patch konnte nicht installiert werden, weil es einen Konflikt mit einem anderen Patch gibt: %s" -COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB = "Keine Verbindung zu GitHub: %s" -COM_PATCHTESTER_ERROR_APPLIED_PATCHES = "Daten von GitHub können nicht abgerufen werden, solange Patches installiert sind. Entfernen Sie bitte die Patches, bevor Sie fortfahren." -COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE = "Die Datei %1$s konnte nicht nach %2$s kopiert werden." -COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE = "Die Datei %s kann nicht gelöscht werden." -COM_PATCHTESTER_ERROR_CANNOT_WRITE_FILE = "Die Datei %s kann nicht geschrieben werden." -COM_PATCHTESTER_ERROR_GITHUB_FETCH = "Fehler beim Abrufen der Patches von GitHub: %s" -COM_PATCHTESTER_ERROR_INSERT_DATABASE = "Fehler beim Eintragen der Patches in die Datenbank: %s" -COM_PATCHTESTER_ERROR_MODEL_NOT_FOUND = "Model-Klasse %s nicht gefunden." -COM_PATCHTESTER_ERROR_READING_DATABASE_TABLE = "%1$s - Fehler beim Abrufen von Tabellendaten (%2$s)" -COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE = "Fehler beim Leeren der Pulls-Tabelle: %s" -COM_PATCHTESTER_ERROR_TRUNCATING_TESTS_TABLE = "Fehler beim Leeren der Tests-Tabelle %s" -COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING = "Die Patch-Dateien sind in mit einem nicht unterstützten Format codiert." -COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND = "Ansicht nicht gefunden [Name, Format]: %1$s, %2$s" +COM_PATCHTESTER="Joomla! Patch Tester" +COM_PATCHTESTER_40_WARNING="Solange Joomla! 4.0 in der Entwicklung ist, muss der Patch-Tester als experimentell angesehen werden, da Änderungen in Joomla, einschließlich des in einem Patch enthaltenen Codes, möglicherweise nicht rückwärts-kompatibel sind." +COM_PATCHTESTER_API_LIMIT_ACTION="Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die angeforderte Aktion anzuführen. Das Limit wird um %s zurückgesetzt" +COM_PATCHTESTER_API_LIMIT_LIST="Das Github API Limit für diese Aktion wurde erreicht. Es konnte keine Verbindung zu Github aufgebaut werden um die Daten zu aktualisieren. Das Limit wird um %s zurückgesetzt" +COM_PATCHTESTER_APPLIED="Angewendet" +COM_PATCHTESTER_APPLIED_COMMIT_SHA="Angewandter Commit SHA: %s" +COM_PATCHTESTER_APPLY_OK="Patch erfolgreich angewendet" +COM_PATCHTESTER_APPLY_PATCH="Patch installieren" +COM_PATCHTESTER_BRANCH="Versionszweig" +COM_PATCHTESTER_CONFIGURATION="Joomla! Patch-Tester Einstellungen" +COM_PATCHTESTER_CONFIRM_RESET="Das Zurücksetzen versucht, alle installierten Patches rückgängig zu machen. Dabei werden alle Backup-Dateien entfernt. Dies könnte dazu führen, dass die Umgebung nicht mehr stabil ist. Sind Sie sicher, dass Sie fortfahren möchten?" +COM_PATCHTESTER_CONFLICT_S="Der Patch konnte nicht installiert werden, weil es einen Konflikt mit einem anderen Patch gibt: %s" +COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB="Keine Verbindung zu GitHub: %s" +COM_PATCHTESTER_ERROR_APPLIED_PATCHES="Daten von GitHub können nicht abgerufen werden, solange Patches installiert sind. Entfernen Sie bitte die Patches, bevor Sie fortfahren." +COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE="Die Datei %1$s konnte nicht nach %2$s kopiert werden." +COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE="Die Datei %s kann nicht gelöscht werden." +COM_PATCHTESTER_ERROR_CANNOT_WRITE_FILE="Die Datei %s kann nicht geschrieben werden." +COM_PATCHTESTER_ERROR_GITHUB_FETCH="Fehler beim Abrufen der Patches von GitHub: %s" +COM_PATCHTESTER_ERROR_INSERT_DATABASE="Fehler beim Eintragen der Patches in die Datenbank: %s" +COM_PATCHTESTER_ERROR_MODEL_NOT_FOUND="Model-Klasse %s nicht gefunden." +COM_PATCHTESTER_ERROR_READING_DATABASE_TABLE="%1$s - Fehler beim Abrufen von Tabellendaten (%2$s)" +COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE="Fehler beim Leeren der Pulls-Tabelle: %s" +COM_PATCHTESTER_ERROR_TRUNCATING_TESTS_TABLE="Fehler beim Leeren der Tests-Tabelle %s" +COM_PATCHTESTER_ERROR_UNSUPPORTED_ENCODING="Die Patch-Dateien sind in mit einem nicht unterstützten Format codiert." +COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND="Ansicht nicht gefunden [Name, Format]: %1$s, %2$s" COM_PATCHTESTER_FAILED_APPLYING_PATCH="Der Patch konnte nicht angewendet werden aufgrund eines Problems mit %1$s. %2$s" COM_PATCHTESTER_FAILED_REVERT_PATCH="Der Patch konnte nicht zurückgesetzt werden aufgrund eines Problems mit %1$s. %2$s" -COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED = "Fehler beim Abrufen der Daten von GitHub." -COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW = "Alle Daten wurden abgerufen. Schließen Sie bitte dieses Popup um die Seite neu zu laden." -COM_PATCHTESTER_FETCH_INITIALIZING = "Vorbereitungen für das Abrufen der Daten von GitHub" -COM_PATCHTESTER_FETCH_INITIALIZING_DESCRIPTION = "Überprüfe die Vorbereitungen für den Datenabruf. Bitte haben Sie etwas Geduld." -COM_PATCHTESTER_FETCH_PAGE_NUMBER = "Verarbeite Seite %s der GitHub-Daten" -COM_PATCHTESTER_FETCH_PAGE_NUMBER_OF_TOTAL = "Verarbeite Seite %1$s von %2$s der GitHub-Daten" -COM_PATCHTESTER_FETCH_PROCESSING = "Verarbeite Daten von GitHub" -COM_PATCHTESTER_FETCH_SUCCESSFUL = "Patches wurden erfolgreich abgerufen" -COM_PATCHTESTER_FIELD_GH_AUTH_DESC = "Wähle die 'Anmeldeinformationen' für die Authentifizierung durch Deinen GitHub Usernamen und Passwort oder 'Token' für die Verwendung eines GitHub API Token" -COM_PATCHTESTER_FIELD_GH_AUTH_LABEL = "GitHub Authentifizierungs-Methode" -COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_CREDENTIALS = "Anmeldeinformationen" -COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_TOKEN = "Token" -COM_PATCHTESTER_FIELD_GH_PASSWORD_LABEL = "GitHub-Passwort" -COM_PATCHTESTER_FIELD_GH_PASSWORD_DESC = "Passwort für das im 'GitHub Konto' eingetragene Benutzerkonto. Beachte, dass für Konten mit Zwei-Faktor-Authentifizierung auch ein Token generiert werden muss." -COM_PATCHTESTER_FIELD_GH_TOKEN_DESC = "Verwenden Sie dieses Feld, um ein GitHub API-Token anstelle von Benutzernamen und Passwort anzugeben. Beachten Sie, dass dies erforderlich ist, wenn Ihr Konto Zwei-Faktor-Authentifizierung aktiviert hat." -COM_PATCHTESTER_FIELD_GH_TOKEN_LABEL = "GitHub-Token" -COM_PATCHTESTER_FIELD_GH_USER_LABEL = "GitHub Benutzername" -COM_PATCHTESTER_FIELD_GH_USER_DESC = "Name des GitHub Kontos, das für die Authentifizierung des API genutzt wird." -COM_PATCHTESTER_FIELD_ORG_LABEL = "Projektinhaber" -COM_PATCHTESTER_FIELD_ORG_DESC = "Benutzername oder Organisation auf Github, welcher die Pull Requests überwachen soll." -COM_PATCHTESTER_FIELD_REPO_LABEL = "Individuelle Projekt-Repository" -COM_PATCHTESTER_FIELD_REPO_DESC = "Name des GitHub Repositorys, dessen Pull Requests überwacht werden." -COM_PATCHTESTER_FIELD_REPOSITORY_DESC = "Verfügbare Joomla! Repositories. Wähle um die Organisation und die Repository Feldwerte automatisch zu füllen." -COM_PATCHTESTER_FIELD_REPOSITORY_LABEL = "GitHub Repository" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_JOOMLA_CMS = "Joomla! CMS" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER = "Joomla! Patch-Tester Komponente" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB = "Joomla! Webkataloginstallations-Plugin" -COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS = "Joomla! Weblinks-Paket" -COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM = "Benutzerdefiniert" +COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED="Fehler beim Abrufen der Daten von GitHub." +COM_PATCHTESTER_FETCH_COMPLETE_CLOSE_WINDOW="Alle Daten wurden abgerufen. Schließen Sie bitte dieses Popup um die Seite neu zu laden." +COM_PATCHTESTER_FETCH_INITIALIZING="Vorbereitungen für das Abrufen der Daten von GitHub" +COM_PATCHTESTER_FETCH_INITIALIZING_DESCRIPTION="Überprüfe die Vorbereitungen für den Datenabruf. Bitte haben Sie etwas Geduld." +COM_PATCHTESTER_FETCH_PAGE_NUMBER="Verarbeite Seite %s der GitHub-Daten" +COM_PATCHTESTER_FETCH_PAGE_NUMBER_OF_TOTAL="Verarbeite Seite %1$s von %2$s der GitHub-Daten" +COM_PATCHTESTER_FETCH_PROCESSING="Verarbeite Daten von GitHub" +COM_PATCHTESTER_FETCH_SUCCESSFUL="Patches wurden erfolgreich abgerufen" +COM_PATCHTESTER_FIELD_GH_AUTH_DESC="Wähle die 'Anmeldeinformationen' für die Authentifizierung durch Deinen GitHub Usernamen und Passwort oder 'Token' für die Verwendung eines GitHub API Token" +COM_PATCHTESTER_FIELD_GH_AUTH_LABEL="GitHub Authentifizierungs-Methode" +COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_CREDENTIALS="Anmeldeinformationen" +COM_PATCHTESTER_FIELD_GH_AUTH_OPTION_TOKEN="Token" +COM_PATCHTESTER_FIELD_GH_PASSWORD_LABEL="GitHub-Passwort" +COM_PATCHTESTER_FIELD_GH_PASSWORD_DESC="Passwort für das im 'GitHub Konto' eingetragene Benutzerkonto. Beachte, dass für Konten mit Zwei-Faktor-Authentifizierung auch ein Token generiert werden muss." +COM_PATCHTESTER_FIELD_GH_TOKEN_DESC="Verwenden Sie dieses Feld, um ein GitHub API-Token anstelle von Benutzernamen und Passwort anzugeben. Beachten Sie, dass dies erforderlich ist, wenn Ihr Konto Zwei-Faktor-Authentifizierung aktiviert hat." +COM_PATCHTESTER_FIELD_GH_TOKEN_LABEL="GitHub-Token" +COM_PATCHTESTER_FIELD_GH_USER_LABEL="GitHub Benutzername" +COM_PATCHTESTER_FIELD_GH_USER_DESC="Name des GitHub Kontos, das für die Authentifizierung des API genutzt wird." +COM_PATCHTESTER_FIELD_ORG_LABEL="Projektinhaber" +COM_PATCHTESTER_FIELD_ORG_DESC="Benutzername oder Organisation auf Github, welcher die Pull Requests überwachen soll." +COM_PATCHTESTER_FIELD_REPO_LABEL="Individuelle Projekt-Repository" +COM_PATCHTESTER_FIELD_REPO_DESC="Name des GitHub Repositorys, dessen Pull Requests überwacht werden." +COM_PATCHTESTER_FIELD_REPOSITORY_DESC="Verfügbare Joomla! Repositories. Wähle um die Organisation und die Repository Feldwerte automatisch zu füllen." +COM_PATCHTESTER_FIELD_REPOSITORY_LABEL="GitHub Repository" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_JOOMLA_CMS="Joomla! CMS" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_PATCHTESTER="Joomla! Patch-Tester Komponente" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_INSTALL_FROM_WEB="Joomla! Webkataloginstallations-Plugin" +COM_PATCHTESTER_FIELD_REPOSITORY_OPTION_WEBLINKS="Joomla! Weblinks-Paket" +COM_PATCHTESTER_FIELD_REPOSITORY_CUSTOM="Benutzerdefiniert" COM_PATCHTESTER_FIELD_CI_SERVER_NAME="CI Server Adresse" COM_PATCHTESTER_FIELD_CI_SERVER_NAME_DESC="Server Adresse für das Herunterladen kompilierter Patches." COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH="Switch CI Integration" COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_DESC="Schaltet die CI Integration an oder aus." COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_ON="An" COM_PATCHTESTER_FIELD_CI_SERVER_SWITCH_OPTION_OFF="Aus" -COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC = "Konfigurationswerte für GitHub Repository" -COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL = "GitHub Repository" -COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC = "Konfigurationswerte für GitHub Authentifizierung" -COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL = "GitHub Authentifizierung" +COM_PATCHTESTER_FIELDSET_REPOSITORIES_DESC="Konfigurationswerte für GitHub Repository" +COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL="GitHub Repository" +COM_PATCHTESTER_FIELDSET_AUTHENTICATION_DESC="Konfigurationswerte für GitHub Authentifizierung" +COM_PATCHTESTER_FIELDSET_AUTHENTICATION_LABEL="GitHub Authentifizierung" COM_PATCHTESTER_FIELDSET_CI_SETTINGS="CI Server Einstellungen" COM_PATCHTESTER_FIELDSET_CI_SETTINGS_DESC="Konfigurationswerte für CI Server Patching" -COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S = "Die zu löschende Datei existiert nicht: %s" -COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S = "Die zu ändernde Datei existiert nicht: %s" -COM_PATCHTESTER_FILTER_APPLIED_PATCHES = "Angewendete Patches filtern" -COM_PATCHTESTER_FILTER_BRANCH = "Versionszweig filtern" -COM_PATCHTESTER_FILTER_RTC_PATCHES = "RTC Patches filtern" -COM_PATCHTESTER_FILTER_SEARCH_DESCRIPTION = "Die Liste nach Titel oder mit 'id:' nach Pull Request ID durchsuchen." -COM_PATCHTESTER_GITHUB = "GitHub" -COM_PATCHTESTER_HEADING_FETCH_DATA = "Rufe GitHub Daten ab" -COM_PATCHTESTER_JISSUE = "J! Issue" -COM_PATCHTESTER_JISSUES = "Issue-Tracker" -COM_PATCHTESTER_PULL_ID = "Pull-ID" -COM_PATCHTESTER_NO_CREDENTIALS = "In den Optionen wurden noch keine Benutzerdaten eingetragen. Deshalb können höchstens 60 Anfragen pro Stunde an das Github API gestellt werden. Mit Benutzerdaten sind bis zu 5.000 Anfragen pro Stunde möglich." -COM_PATCHTESTER_NO_FILES_TO_PATCH = "Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind." -COM_PATCHTESTER_NO_ITEMS = "Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen." -COM_PATCHTESTER_NOT_APPLIED = "Nicht angewendet" +COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S="Die zu löschende Datei existiert nicht: %s" +COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S="Die zu ändernde Datei existiert nicht: %s" +COM_PATCHTESTER_FILTER_APPLIED_PATCHES="Angewendete Patches filtern" +COM_PATCHTESTER_FILTER_BRANCH="Versionszweig filtern" +COM_PATCHTESTER_FILTER_RTC_PATCHES="RTC Patches filtern" +COM_PATCHTESTER_FILTER_SEARCH_DESCRIPTION="Die Liste nach Titel oder mit 'id:' nach Pull Request ID durchsuchen." +COM_PATCHTESTER_GITHUB="GitHub" +COM_PATCHTESTER_HEADING_FETCH_DATA="Rufe GitHub Daten ab" +COM_PATCHTESTER_JISSUE="J! Issue" +COM_PATCHTESTER_JISSUES="Issue-Tracker" +COM_PATCHTESTER_PULL_ID="Pull-ID" +COM_PATCHTESTER_NO_CREDENTIALS="In den Optionen wurden noch keine Benutzerdaten eingetragen. Deshalb können höchstens 60 Anfragen pro Stunde an das Github API gestellt werden. Mit Benutzerdaten sind bis zu 5.000 Anfragen pro Stunde möglich." +COM_PATCHTESTER_NO_FILES_TO_PATCH="Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind." +COM_PATCHTESTER_NO_ITEMS="Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen." +COM_PATCHTESTER_NOT_APPLIED="Nicht angewendet" COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="Der Patch kann nicht zurückgesetzt werden, es muss zunächst erstmal der Patch mit der Pull ID %s zurückgesetzt werden." -COM_PATCHTESTER_NOT_RTC = "Nicht RTC" -COM_PATCHTESTER_READY_TO_COMMIT = "Ready to Commit" -COM_PATCHTESTER_REPO_IS_GONE = "Der Patch konnte nicht angewendet werden, weil das Repository fehlt" -COM_PATCHTESTER_REQUIREMENT_HTTPS = "HTTPS Wrapper müssen aktiviert sein" -COM_PATCHTESTER_REQUIREMENT_OPENSSL = "Die OpenSSL-Erweiterung muss installiert und in der php.ini aktivert sein" -COM_PATCHTESTER_REQUIREMENTS_HEADING = "Die Vorraussetzungen sind nicht erfüllt" -COM_PATCHTESTER_REQUIREMENTS_NOT_MET = "Ihr System erfüllt nicht die Vorraussetzungen um den Patch-Tester auszuführen:" -COM_PATCHTESTER_RESET_HAS_ERRORS = "Die Daten wurden zurück gesetzt. Leider sind dabei Fehler aufgetreten. Bitte entferne alle .txt Dateien im Verzeichnis '%1$s' und leere die Datenbanktabelle '%2$s'." -COM_PATCHTESTER_RESET_OK = "Die Daten wurden erfolgreich zurück gesetzt." -COM_PATCHTESTER_REVERT_OK = "Der Patch wurde erfolgreich entfernt" -COM_PATCHTESTER_REVERT_PATCH = "Patch entfernen" -COM_PATCHTESTER_RTC = "RTC" -COM_PATCHTESTER_SERVER_RESPONDED_NOT_200 = "Es konnte entweder keine Verbindung zum Server aufgebaut werden oder der angegebene Pull Request existiert nicht auf dem Server." -COM_PATCHTESTER_TEST_THIS_PATCH = "Diesen Patch testen" -COM_PATCHTESTER_TOOLBAR_FETCH_DATA = "Daten abrufen" -COM_PATCHTESTER_TOOLBAR_RESET = "Zurücksetzen" +COM_PATCHTESTER_NOT_RTC="Nicht RTC" +COM_PATCHTESTER_READY_TO_COMMIT="Ready to Commit" +COM_PATCHTESTER_REPO_IS_GONE="Der Patch konnte nicht angewendet werden, weil das Repository fehlt" +COM_PATCHTESTER_REQUIREMENT_HTTPS="HTTPS Wrapper müssen aktiviert sein" +COM_PATCHTESTER_REQUIREMENT_OPENSSL="Die OpenSSL-Erweiterung muss installiert und in der php.ini aktivert sein" +COM_PATCHTESTER_REQUIREMENTS_HEADING="Die Vorraussetzungen sind nicht erfüllt" +COM_PATCHTESTER_REQUIREMENTS_NOT_MET="Ihr System erfüllt nicht die Vorraussetzungen um den Patch-Tester auszuführen:" +COM_PATCHTESTER_RESET_HAS_ERRORS="Die Daten wurden zurück gesetzt. Leider sind dabei Fehler aufgetreten. Bitte entferne alle .txt Dateien im Verzeichnis '%1$s' und leere die Datenbanktabelle '%2$s'." +COM_PATCHTESTER_RESET_OK="Die Daten wurden erfolgreich zurück gesetzt." +COM_PATCHTESTER_REVERT_OK="Der Patch wurde erfolgreich entfernt" +COM_PATCHTESTER_REVERT_PATCH="Patch entfernen" +COM_PATCHTESTER_RTC="RTC" +COM_PATCHTESTER_SERVER_RESPONDED_NOT_200="Es konnte entweder keine Verbindung zum Server aufgebaut werden oder der angegebene Pull Request existiert nicht auf dem Server." +COM_PATCHTESTER_TEST_THIS_PATCH="Diesen Patch testen" +COM_PATCHTESTER_TOOLBAR_FETCH_DATA="Daten abrufen" +COM_PATCHTESTER_TOOLBAR_RESET="Zurücksetzen" COM_PATCHTESTER_ZIP_DOES_NOT_EXIST="Der Patch konnte nicht angewendet werden, weil er nicht vom Server heruntergeladen werden konnte." COM_PATCHTESTER_ZIP_EXTRACT_FAILED="Der Patch konnte nicht angewendet werden, weil nicht entpackt werden konnte." - - - diff --git a/administrator/templates/atum/html/com_patchtester/pulls/default_items.php b/administrator/templates/atum/html/com_patchtester/pulls/default_items.php index f829d66..82eb7a9 100644 --- a/administrator/templates/atum/html/com_patchtester/pulls/default_items.php +++ b/administrator/templates/atum/html/com_patchtester/pulls/default_items.php @@ -17,56 +17,60 @@ foreach ($this->items as $i => $item) : $status = ' class="table-active"'; endif; ?> - > - + > + pull_id; ?> - - - escape($item->title); ?> - + + escape($item->branch); ?> - - + + is_rtc) : ?> - + - + - - + + applied) : ?> - + - + - - + + applied) : ?> - + - + - - + + Date: Tue, 1 Oct 2019 13:23:01 +0200 Subject: [PATCH 26/27] Apply suggestions from code review Added some new lines at the end of templates, whites-spaces between casting and attribute, replaced back ticks with double quotes. Co-Authored-By: SharkyKZ --- .../com_patchtester/PatchTester/View/Pulls/tmpl/default.php | 2 +- .../PatchTester/View/Pulls/tmpl/default_items.php | 6 +++--- .../com_patchtester/install/sql/postgresql/install.sql | 2 +- .../atum/html/com_patchtester/pulls/default_items.php | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) 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 8fb3e7c..fb16cf8 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php +++ b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default.php @@ -132,4 +132,4 @@ $filterRtc = $this->escape($this->state->get('filter.rtc'));
- \ No newline at end of file + 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 50fbea9..405e87a 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 @@ -68,12 +68,12 @@ foreach ($this->items as $i => $item) : applied) : ?> + data-task="revert-applied; ?>">
+ data-task="apply-pull_id; ?>"> -items as $i => $item) : if ($item->applied) : $status = ' class="table-active"'; endif; - ?> +?> > pull_id; ?> @@ -66,10 +66,10 @@ foreach ($this->items as $i => $item) : applied) : ?> + data-task="revert-applied; ?>"> + data-task="apply-pull_id; ?>"> From 4103c5f154db6847192296bb641e4644e4f718aa Mon Sep 17 00:00:00 2001 From: Sebastian Enns Date: Tue, 1 Oct 2019 14:07:26 +0200 Subject: [PATCH 27/27] Regenerated composer.lock, reformatted config.xml and replaced let as well as arrow functions in patchtester.js file. --- .../components/com_patchtester/config.xml | 150 +++++++++--------- composer.lock | 5 +- media/com_patchtester/js/patchtester.js | 21 +-- 3 files changed, 88 insertions(+), 88 deletions(-) diff --git a/administrator/components/com_patchtester/config.xml b/administrator/components/com_patchtester/config.xml index 40a5f9c..cc100bb 100644 --- a/administrator/components/com_patchtester/config.xml +++ b/administrator/components/com_patchtester/config.xml @@ -2,18 +2,18 @@
@@ -23,40 +23,40 @@
@@ -65,56 +65,56 @@
@@ -123,19 +123,19 @@
diff --git a/composer.lock b/composer.lock index 38c9fb1..f2662f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "74b98490277fecd02473d802a0fe279a", + "content-hash": "35e372f08cd218b7040fd37d8e7dcaeb", "packages": [], "packages-dev": [ { @@ -1067,8 +1067,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.0", - "ext-json": "*" + "php": "^5.3.10|^7.0" }, "platform-dev": { "php": "^5.6|^7.0" diff --git a/media/com_patchtester/js/patchtester.js b/media/com_patchtester/js/patchtester.js index 442df94..2f80987 100644 --- a/media/com_patchtester/js/patchtester.js +++ b/media/com_patchtester/js/patchtester.js @@ -9,10 +9,10 @@ if (typeof Joomla === 'undefined') { throw new Error('PatchTester JavaScript requires the Joomla core JavaScript API') } -document.addEventListener("DOMContentLoaded", (event) => { +document.addEventListener("DOMContentLoaded", function (event) { - let submitPatch = document.querySelectorAll(".submitPatch"); - let pullIdForm = document.querySelector("#pull_id"); + var submitPatch = document.querySelectorAll(".submitPatch"); + var pullIdForm = document.querySelector("#pull_id"); /** * EventListener which listens on submitPatch Button, @@ -21,12 +21,13 @@ document.addEventListener("DOMContentLoaded", (event) => { * * @param {Event} event */ - submitPatch.forEach((element) => element.addEventListener("click", (event) => { - let currentTarget = event.currentTarget, - data = currentTarget.dataset.task.split("-"), - task = data[0]; + submitPatch.forEach(function (element) { + element.addEventListener("click", function (event) { + var currentTarget = event.currentTarget; + var data = currentTarget.dataset.task.split("-"); - pullIdForm.value = data[1]; - Joomla.submitform(task); - })); + pullIdForm.value = data[1]; + Joomla.submitform(data[0]); + }); + }); });