From d5ebf1c266242f9b7f5c9186db9513a33d9bfcf3 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 11:58:05 +0200 Subject: [PATCH 1/9] check schema --- .../src/Application/ConsoleApplication.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/libraries/src/Application/ConsoleApplication.php b/libraries/src/Application/ConsoleApplication.php index 5d8be7624e194..308aba6deadb2 100644 --- a/libraries/src/Application/ConsoleApplication.php +++ b/libraries/src/Application/ConsoleApplication.php @@ -584,4 +584,52 @@ protected function getDefaultInputDefinition(): InputDefinition ] ); } + + /** + * Gets a user state. + * + * @param string $key The path of the state. + * @param mixed $default Optional default value, returned if the internal value is null. + * + * @return mixed The user state or null. + * + * @since __DEPLOY_VERSION__ + */ + public function getUserState($key, $default = null) + { + $registry = $this->getSession()->get('registry'); + + if ($registry !== null) { + return $registry->get($key, $default); + } + + return $default; + } + + /** + * Gets the value of a user state variable. + * + * @param string $key The key of the user state variable. + * @param string $request The name of the variable passed in a request. + * @param string $default The default value for the variable if not found. Optional. + * @param string $type Filter for the variable, for valid values see {@link InputFilter::clean()}. Optional. + * + * @return mixed The request user state. + * + * @since __DEPLOY_VERSION__ + */ + public function getUserStateFromRequest($key, $request, $default = null, $type = 'none') + { + $cur_state = $this->getUserState($key, $default); + $new_state = $this->input->get($request, null, $type); + + if ($new_state === null) { + return $cur_state; + } + + // Save the new value only if it was set in this request. + $this->setUserState($key, $new_state); + + return $new_state; + } } From c179855d4d9f45e8a3579e7b072c1994cb51b707 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 12:01:14 +0200 Subject: [PATCH 2/9] check schema --- libraries/src/Console/UpdateCoreCommand.php | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 495954bb6cb9e..2574b801b8c10 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -165,6 +165,20 @@ public function doExecute(InputInterface $input, OutputInterface $output): int return self::ERR_CHECKS_FAILED; } + $this->progressBar->advance(); + $this->progressBar->setMessage('Check Database Table Structure...'); + + $errors = $this->checkSchema(); + + if ($errors > 0) { + + $this->ioStyle->error('Database Table Structure not Up to Date'); + $this->progressBar->finish(); + $this->ioStyle->info('There were ' . $errors . ' errors' ); + + return self::ERR_CHECKS_FAILED; + } + $this->progressBar->advance(); $this->progressBar->setMessage('Starting Joomla! update ...'); @@ -386,4 +400,29 @@ public function copyFileTo($file, $dir): void { Folder::copy($file, $dir, '', true); } + + /** + * Check the schema version + * + * @return integer the number of errors + * + * @since __DEPLOY_VERSION__ + */ + public function checkSchema(): int + { + $app = $this->getApplication(); + $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); + $errors = 0; + $dbmodel = $app->bootComponent('com_installer')->getMVCFactory($app)->createModel('Database', 'Administrator'); + + $changeSet = $dbmodel->getItems(); + foreach ($changeSet as $i => $item) { + $errors = $item['errorsCount']; + foreach ($item['errorsMessage'] as $msg) { + $this->ioStyle->info($msg); + } + } + + return $errors; + } } From 38369329ef579c373def84f81dd2d7d60832baf3 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 12:26:46 +0200 Subject: [PATCH 3/9] core only --- libraries/src/Console/UpdateCoreCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 2574b801b8c10..b3d99f32efad9 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -10,6 +10,7 @@ namespace Joomla\CMS\Console; use Joomla\Application\Cli\CliInput; +use Joomla\CMS\Extension\ExtensionHelper; use Joomla\CMS\Filesystem\File; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Installer\InstallerHelper; @@ -413,9 +414,14 @@ public function checkSchema(): int $app = $this->getApplication(); $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); $errors = 0; + $coreExtensionInfo = ExtensionHelper::getExtensionRecord('joomla', 'file'); + $dbmodel = $app->bootComponent('com_installer')->getMVCFactory($app)->createModel('Database', 'Administrator'); + // Ensure we only get information for core + $dbmodel->setState('filter.extension_id', $coreExtensionInfo->extension_id); $changeSet = $dbmodel->getItems(); + foreach ($changeSet as $i => $item) { $errors = $item['errorsCount']; foreach ($item['errorsMessage'] as $msg) { From 890283ebb02a3ca14913bbc51b69e6a910a8d90f Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 14:20:25 +0200 Subject: [PATCH 4/9] cs --- libraries/src/Console/UpdateCoreCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index b3d99f32efad9..7faecc05aa9ed 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -175,7 +175,7 @@ public function doExecute(InputInterface $input, OutputInterface $output): int $this->ioStyle->error('Database Table Structure not Up to Date'); $this->progressBar->finish(); - $this->ioStyle->info('There were ' . $errors . ' errors' ); + $this->ioStyle->info('There were ' . $errors . ' errors'); return self::ERR_CHECKS_FAILED; } @@ -413,7 +413,7 @@ public function checkSchema(): int { $app = $this->getApplication(); $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); - $errors = 0; + $errors = 0; $coreExtensionInfo = ExtensionHelper::getExtensionRecord('joomla', 'file'); $dbmodel = $app->bootComponent('com_installer')->getMVCFactory($app)->createModel('Database', 'Administrator'); From 0489e7baabc7496c970b01b2aafd5898afc60d31 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 14:53:32 +0200 Subject: [PATCH 5/9] Update libraries/src/Console/UpdateCoreCommand.php Co-authored-by: Richard Fath --- libraries/src/Console/UpdateCoreCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 7faecc05aa9ed..758c55b3967a0 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -172,7 +172,6 @@ public function doExecute(InputInterface $input, OutputInterface $output): int $errors = $this->checkSchema(); if ($errors > 0) { - $this->ioStyle->error('Database Table Structure not Up to Date'); $this->progressBar->finish(); $this->ioStyle->info('There were ' . $errors . ' errors'); From 8347c2d620a726a85838f6282d7b70ebdf49308c Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 15:12:27 +0200 Subject: [PATCH 6/9] Update libraries/src/Console/UpdateCoreCommand.php Co-authored-by: Richard Fath --- libraries/src/Console/UpdateCoreCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 758c55b3967a0..d18a9842f0879 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -402,7 +402,7 @@ public function copyFileTo($file, $dir): void } /** - * Check the schema version + * Check Database Table Structure * * @return integer the number of errors * From 98e6192187e88a9e160dd7b1c4bbb2e019b9508e Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 15:12:36 +0200 Subject: [PATCH 7/9] Update libraries/src/Console/UpdateCoreCommand.php Co-authored-by: Richard Fath --- libraries/src/Console/UpdateCoreCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index d18a9842f0879..232b5ac5f7750 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -410,7 +410,7 @@ public function copyFileTo($file, $dir): void */ public function checkSchema(): int { - $app = $this->getApplication(); + $app = $this->getApplication(); $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); $errors = 0; $coreExtensionInfo = ExtensionHelper::getExtensionRecord('joomla', 'file'); From a118ecb62c717963081482a7b0667c2dc8abc13b Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 15:21:32 +0200 Subject: [PATCH 8/9] Update UpdateCoreCommand.php --- libraries/src/Console/UpdateCoreCommand.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 232b5ac5f7750..29ac416232863 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -410,7 +410,7 @@ public function copyFileTo($file, $dir): void */ public function checkSchema(): int { - $app = $this->getApplication(); + $app = $this->getApplication(); $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); $errors = 0; $coreExtensionInfo = ExtensionHelper::getExtensionRecord('joomla', 'file'); @@ -419,13 +419,13 @@ public function checkSchema(): int // Ensure we only get information for core $dbmodel->setState('filter.extension_id', $coreExtensionInfo->extension_id); - $changeSet = $dbmodel->getItems(); - foreach ($changeSet as $i => $item) { - $errors = $item['errorsCount']; - foreach ($item['errorsMessage'] as $msg) { - $this->ioStyle->info($msg); - } + // We're filtering by a single extension which must always exist - so can safely access this through element 0 of the array + $changeInformation = $dbmodel->getItems()[0]; + $errors = $changeInformation['errorsCount']; + + foreach ($changeInformation['errorsMessage'] as $msg) { + $this->ioStyle->info($msg); } return $errors; From 922dcb3ab959383f9e217222ee0a022ebe4094a8 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 24 Apr 2023 15:28:00 +0200 Subject: [PATCH 9/9] Update libraries/src/Console/UpdateCoreCommand.php Co-authored-by: Richard Fath --- libraries/src/Console/UpdateCoreCommand.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 29ac416232863..2031567012f48 100644 --- a/libraries/src/Console/UpdateCoreCommand.php +++ b/libraries/src/Console/UpdateCoreCommand.php @@ -410,9 +410,8 @@ public function copyFileTo($file, $dir): void */ public function checkSchema(): int { - $app = $this->getApplication(); + $app = $this->getApplication(); $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); - $errors = 0; $coreExtensionInfo = ExtensionHelper::getExtensionRecord('joomla', 'file'); $dbmodel = $app->bootComponent('com_installer')->getMVCFactory($app)->createModel('Database', 'Administrator'); @@ -422,12 +421,11 @@ public function checkSchema(): int // We're filtering by a single extension which must always exist - so can safely access this through element 0 of the array $changeInformation = $dbmodel->getItems()[0]; - $errors = $changeInformation['errorsCount']; foreach ($changeInformation['errorsMessage'] as $msg) { $this->ioStyle->info($msg); } - return $errors; + return $changeInformation['errorsCount']; } }