Commit 9340bf97 authored by catch's avatar catch

Issue #3031740 by alexpott, tmanhollan, catch, collinhaines: Updating to 8.6.8...

Issue #3031740 by alexpott, tmanhollan, catch, collinhaines: Updating to 8.6.8 or 8.6.9 with Drush 8 causes data loss via update_fix_compatibility()
parent 9ec3433f
......@@ -16,6 +16,10 @@
* Disables any extensions that are incompatible with the current core version.
*/
function update_fix_compatibility() {
// Fix extension objects if the update is being done via Drush 8. In non-Drush
// environments this will already be fixed by the UpdateKernel this point.
UpdateKernel::fixSerializedExtensionObjects(\Drupal::getContainer());
$extension_config = \Drupal::configFactory()->getEditable('core.extension');
$save = FALSE;
foreach (['module', 'theme'] as $type) {
......@@ -30,10 +34,6 @@ function update_fix_compatibility() {
$extension_config->set('module', module_config_sort($extension_config->get('module')));
$extension_config->save();
}
// Fix extension objects if the update is being done via Drush 8. In non-Drush
// environments this will already be fixed by the UpdateKernel this point.
UpdateKernel::fixSerializedExtensionObjects(\Drupal::getContainer());
}
/**
......
......@@ -219,6 +219,9 @@ public static function fixSerializedExtensionObjects(ContainerInterface $contain
// will be PHP warnings. This silently fixes Drupal so that the update can
// continue.
$callable = function () use ($container) {
// Reset static caches in profile list so the module list is rebuilt
// correctly.
$container->get('extension.list.profile')->reset();
foreach ($container->getParameter('cache_bins') as $service_id => $bin) {
$container->get($service_id)->deleteAll();
}
......
......@@ -18,6 +18,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PrivateStream;
......@@ -2173,3 +2174,67 @@ function system_update_8501() {
}
}
}
/**
* Fix missing install profile after updating to Drupal 8.6.9 with Drush 8.
*/
function system_update_8601() {
$extension_config = \Drupal::configFactory()->getEditable('core.extension');
$install_profile = $extension_config->get('profile');
if (!$install_profile) {
// There's no install profile configured.
return;
}
$modules = $extension_config->get('module');
if (isset($modules[$install_profile])) {
// The install profile is already in the installed module list.
return;
}
// Ensure the install profile is available.
if (!\Drupal::service('extension.list.module')->exists($install_profile)) {
return t('The %install_profile install profile configured in core.extension is not available.', ['%install_profile' => $install_profile]);
}
// Add the install profile to the list of enabled modules.
$modules[$install_profile] = 1000;
$modules = module_config_sort($modules);
$extension_config
->set('module', $modules)
->save(TRUE);
// Build a module list from the updated extension configuration.
$current_module_filenames = \Drupal::moduleHandler()->getModuleList();
$current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
$current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
$module_filenames = [];
foreach ($current_modules as $name => $weight) {
if (isset($current_module_filenames[$name])) {
$module_filenames[$name] = $current_module_filenames[$name];
}
else {
$module_path = \Drupal::service('extension.list.module')->getPath($name);
$pathname = "$module_path/$name.info.yml";
$filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
$module_filenames[$name] = new Extension(\Drupal::root(), 'module', $pathname, $filename);
}
}
// Update the module handler list to contain the missing install profile.
\Drupal::moduleHandler()->setModuleList($module_filenames);
\Drupal::moduleHandler()->load($install_profile);
// Clear the static cache of the "extension.list.module" service to pick
// up the new install profile correctly.
\Drupal::service('extension.list.profile')->reset();
// Clear the static cache of the "extension.list.module" service to pick
// up the new module, since it merges the installation status of modules
// into its statically cached list.
\Drupal::service('extension.list.module')->reset();
// Update the kernel to include the missing profile.
\Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
return t('The %install_profile install profile has been added to the installed module list.', ['%install_profile' => $install_profile]);
}
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\system\Functional\Update;
use Drupal\Core\Database\Database;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -39,6 +40,41 @@ public function testUpdatedSite() {
$this->assertSame('Australia/Sydney', $this->config('system.date')->get('timezone.default'));
}
/**
* Tests system_update_8601().
*/
public function testWithMissingProfile() {
// Remove the install profile from the module list to simulate how Drush 8
// and update_fix_compatibility() worked together to remove the install
// profile. See https://www.drupal.org/project/drupal/issues/3031740.
$connection = Database::getConnection();
$config = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$config = unserialize($config);
unset($config['module']['minimal']);
$connection->update('config')
->fields([
'data' => serialize($config),
'collection' => '',
'name' => 'core.extension',
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
$this->runUpdates();
$this->assertSession()->pageTextContains('The minimal install profile has been added to the installed module list.');
// Login and check that the status report is working correctly.
$this->drupalLogin($this->rootUser);
$this->drupalGet('admin/reports/status');
$this->assertSession()->pageTextContains("Installation Profile Minimal");
}
/**
* {@inheritdoc}
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment