From 273499059dab03fbd4c6dee73e44116d498cff05 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sat, 19 Jan 2013 12:13:19 -0800
Subject: [PATCH] Issue #1848998 by dawehner, chx, xjm: Fixed Module/Bundle
 services not available in update.php.

---
 core/includes/update.inc                      |  1 +
 .../Tests/Upgrade/SystemUpgradePathTest.php   | 12 ++++++++++++
 core/modules/system/system.install            | 19 +++++++++++++++++++
 core/modules/views/views.install              | 14 ++++++++++++++
 4 files changed, 46 insertions(+)

diff --git a/core/includes/update.inc b/core/includes/update.inc
index 1a9066052c3d..cdcae638258a 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -633,6 +633,7 @@ function update_module_enable(array $modules) {
     // installed module is always 0. Using 8000 here would be inconsistent
     // since $module_update_8000() may involve a schema change, and we want
     // to install the schema as it was before any updates were added.
+    module_load_install($module);
     $function = $module . '_schema_0';
     if (function_exists($function)) {
       $schema = $function();
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
index ea6d6aaaaecf..2384f58b3c3a 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
@@ -108,4 +108,16 @@ public function testVariableUpgrade() {
       }
     }
   }
+
+  /**
+   * Check whether views got enabled.
+   */
+  public function testFrontpageUpgrade() {
+    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
+
+    // Reset the module enable list to get the current result.
+    module_list_reset();
+    $this->assertTrue(module_exists('views'), 'Views is enabled after the upgrade.');
+  }
+
 }
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index b63ca4607b0b..c0e3fe61bf09 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -2194,6 +2194,25 @@ function system_update_8045() {
   }
 }
 
+/**
+ * Enable Views if the node listing is set as the frontpage.
+ */
+function system_update_8046() {
+  $front_page = config('system.site')->get('page.front');
+  if (!isset($front_page) || $front_page == 'node') {
+    update_module_enable(array('views'));
+
+    // Register views to the container, so views can use it's services.
+    $module_list = drupal_container()->getParameter('container.modules');
+    drupal_load('module', 'views');
+
+    drupal_container()->get('kernel')->updateModules(array_keys($module_list), array('views' => 'core/modules/views/views.module'));
+
+    // This does not fire a hook just calls views.
+    config_install_default_config('module', 'views');
+  }
+}
+
 /**
  * @} End of "defgroup updates-7.x-to-8.x".
  * The next series of updates should start at 9000.
diff --git a/core/modules/views/views.install b/core/modules/views/views.install
index d395d0838221..8bda10e53984 100644
--- a/core/modules/views/views.install
+++ b/core/modules/views/views.install
@@ -26,3 +26,17 @@ function views_schema() {
 
   return $schema;
 }
+
+/**
+ * Provide an initial schema.
+ *
+ * @see update_module_enable().
+ */
+function views_schema_0() {
+  module_load_install('system');
+  // Add the cache_views_info and cache_views_results tables.
+  $cache_schema = system_schema_cache_8007();
+  $schema['cache_views_info'] = $cache_schema;
+  $schema['cache_views_results'] = $cache_schema;
+  return $schema;
+}
-- 
GitLab