Skip to content

Commit d20c455

Browse files
authored
[4][cli] schema update check (#40468)
1 parent a558728 commit d20c455

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

libraries/src/Application/ConsoleApplication.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,52 @@ protected function getDefaultInputDefinition(): InputDefinition
584584
]
585585
);
586586
}
587+
588+
/**
589+
* Gets a user state.
590+
*
591+
* @param string $key The path of the state.
592+
* @param mixed $default Optional default value, returned if the internal value is null.
593+
*
594+
* @return mixed The user state or null.
595+
*
596+
* @since __DEPLOY_VERSION__
597+
*/
598+
public function getUserState($key, $default = null)
599+
{
600+
$registry = $this->getSession()->get('registry');
601+
602+
if ($registry !== null) {
603+
return $registry->get($key, $default);
604+
}
605+
606+
return $default;
607+
}
608+
609+
/**
610+
* Gets the value of a user state variable.
611+
*
612+
* @param string $key The key of the user state variable.
613+
* @param string $request The name of the variable passed in a request.
614+
* @param string $default The default value for the variable if not found. Optional.
615+
* @param string $type Filter for the variable, for valid values see {@link InputFilter::clean()}. Optional.
616+
*
617+
* @return mixed The request user state.
618+
*
619+
* @since __DEPLOY_VERSION__
620+
*/
621+
public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
622+
{
623+
$cur_state = $this->getUserState($key, $default);
624+
$new_state = $this->input->get($request, null, $type);
625+
626+
if ($new_state === null) {
627+
return $cur_state;
628+
}
629+
630+
// Save the new value only if it was set in this request.
631+
$this->setUserState($key, $new_state);
632+
633+
return $new_state;
634+
}
587635
}

libraries/src/Console/UpdateCoreCommand.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Joomla\CMS\Console;
1111

1212
use Joomla\Application\Cli\CliInput;
13+
use Joomla\CMS\Extension\ExtensionHelper;
1314
use Joomla\CMS\Filesystem\File;
1415
use Joomla\CMS\Filesystem\Folder;
1516
use Joomla\CMS\Installer\InstallerHelper;
@@ -165,6 +166,19 @@ public function doExecute(InputInterface $input, OutputInterface $output): int
165166
return self::ERR_CHECKS_FAILED;
166167
}
167168

169+
$this->progressBar->advance();
170+
$this->progressBar->setMessage('Check Database Table Structure...');
171+
172+
$errors = $this->checkSchema();
173+
174+
if ($errors > 0) {
175+
$this->ioStyle->error('Database Table Structure not Up to Date');
176+
$this->progressBar->finish();
177+
$this->ioStyle->info('There were ' . $errors . ' errors');
178+
179+
return self::ERR_CHECKS_FAILED;
180+
}
181+
168182
$this->progressBar->advance();
169183
$this->progressBar->setMessage('Starting Joomla! update ...');
170184

@@ -386,4 +400,32 @@ public function copyFileTo($file, $dir): void
386400
{
387401
Folder::copy($file, $dir, '', true);
388402
}
403+
404+
/**
405+
* Check Database Table Structure
406+
*
407+
* @return integer the number of errors
408+
*
409+
* @since __DEPLOY_VERSION__
410+
*/
411+
public function checkSchema(): int
412+
{
413+
$app = $this->getApplication();
414+
$app->getLanguage()->load('com_installer', JPATH_ADMINISTRATOR);
415+
$coreExtensionInfo = ExtensionHelper::getExtensionRecord('joomla', 'file');
416+
417+
$dbmodel = $app->bootComponent('com_installer')->getMVCFactory($app)->createModel('Database', 'Administrator');
418+
419+
// Ensure we only get information for core
420+
$dbmodel->setState('filter.extension_id', $coreExtensionInfo->extension_id);
421+
422+
// We're filtering by a single extension which must always exist - so can safely access this through element 0 of the array
423+
$changeInformation = $dbmodel->getItems()[0];
424+
425+
foreach ($changeInformation['errorsMessage'] as $msg) {
426+
$this->ioStyle->info($msg);
427+
}
428+
429+
return $changeInformation['errorsCount'];
430+
}
389431
}

0 commit comments

Comments
 (0)