Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions libraries/src/Application/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
42 changes: 42 additions & 0 deletions libraries/src/Console/UpdateCoreCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ...');

Expand Down Expand Up @@ -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'];
}
}