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; + } } diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php index 495954bb6cb9e..2031567012f48 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; @@ -165,6 +166,19 @@ 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,32 @@ public function copyFileTo($file, $dir): void { Folder::copy($file, $dir, '', true); } + + /** + * Check Database Table Structure + * + * @return integer the number of errors + * + * @since __DEPLOY_VERSION__ + */ + public function checkSchema(): int + { + $app = $this->getApplication(); + $app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR); + $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); + + // 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]; + + foreach ($changeInformation['errorsMessage'] as $msg) { + $this->ioStyle->info($msg); + } + + return $changeInformation['errorsCount']; + } }