From 0657aee21a5919529d867f5028f006bdb38491b7 Mon Sep 17 00:00:00 2001
From: Chris Gross <gross.364@osu.edu>
Date: Thu, 31 May 2018 17:15:15 -0400
Subject: [PATCH] 7.x-1.8 Release Candidate 1

---
 profiles/wcm_base/CHANGELOG.txt               |  4 ++
 .../modules/contrib/menu_block/PATCHES.txt    |  1 +
 .../contrib/menu_block/menu_block.module      | 41 +++++++++++++++++++
 profiles/wcm_base/wcm_base.make               |  1 +
 4 files changed, 47 insertions(+)

diff --git a/profiles/wcm_base/CHANGELOG.txt b/profiles/wcm_base/CHANGELOG.txt
index 32c08e0d..badb6691 100644
--- a/profiles/wcm_base/CHANGELOG.txt
+++ b/profiles/wcm_base/CHANGELOG.txt
@@ -1,3 +1,7 @@
+WCM Base 7.x-1.8-rc1, 2018-05-31
+--------------------------------
+- WCM Base: Added patch to rebuild Menu Block IDs on cache clear.
+
 WCM Base 7.x-1.7, 2018-05-30
 ----------------------------
 - WCM Base: Patched Menu Block module to allow custom delta values.
diff --git a/profiles/wcm_base/modules/contrib/menu_block/PATCHES.txt b/profiles/wcm_base/modules/contrib/menu_block/PATCHES.txt
index 630faf80..2310c258 100644
--- a/profiles/wcm_base/modules/contrib/menu_block/PATCHES.txt
+++ b/profiles/wcm_base/modules/contrib/menu_block/PATCHES.txt
@@ -1,4 +1,5 @@
 The following patches have been applied to this project:
 - http://drupal.org/files/issues/2018-05-14/menu_block-customize_deltas-2076119-7.patch
+- http://drupal.org/files/issues/2018-06-01/menu_block-rebuild-block-ids-2932156-5.patch
 
 This file was automatically generated by Drush Make (http://drupal.org/project/drush).
diff --git a/profiles/wcm_base/modules/contrib/menu_block/menu_block.module b/profiles/wcm_base/modules/contrib/menu_block/menu_block.module
index a5bf3964..42533815 100644
--- a/profiles/wcm_base/modules/contrib/menu_block/menu_block.module
+++ b/profiles/wcm_base/modules/contrib/menu_block/menu_block.module
@@ -1070,3 +1070,44 @@ function menu_block_menu_link_update($link) {
 function menu_block_menu_link_delete($link) {
   menu_block_menu_link_insert($link);
 }
+
+/**
+ * Implements hook_flush_caches().
+ *
+ * Tell Drupal to execute callback that rebuilds menu_block_ids variable.
+ */
+function menu_block_flush_caches() {
+  register_shutdown_function('menu_block_rebuild_block_ids');
+  return array();
+}
+
+/**
+ * Rebuild menu_block_ids from existing menu_block delta values in block table.
+ */
+function menu_block_rebuild_block_ids() {
+  $existing = variable_get('menu_block_ids', array());
+  //  exclude non-numeric delta values (eg menu blocks exported into Features modules)
+  $new = array();
+  $result = db_query('select distinct delta from block where module = :module and delta is not null', array(':module' => 'menu_block'));
+  if ($result) {
+    foreach ($result as $row) {
+      $id = $row->delta;
+      if ($id) {
+        $new[] = $id;
+      }
+    }
+  }
+  sort($new);
+  if ($new != $existing) {
+    $missing = array_diff($existing, $new);
+    if ($missing) {
+      watchdog('menu_block', 'Removing obsolete block IDs from menu_block_ids variable: !list', array('!list' => implode(',', $missing)));
+    }
+    $additions = array_diff($new, $existing);
+    if ($additions) {
+      watchdog('menu_block', 'Adding missing block IDs to menu_block_ids variable: !list', array('!list' => implode(',', $additions)));
+    }
+    variable_set('menu_block_ids', $new);
+  }
+}
+
diff --git a/profiles/wcm_base/wcm_base.make b/profiles/wcm_base/wcm_base.make
index 866e83b7..55edd9dc 100644
--- a/profiles/wcm_base/wcm_base.make
+++ b/profiles/wcm_base/wcm_base.make
@@ -82,6 +82,7 @@ projects[mailsystem][subdir] = contrib
 projects[menu_block][version] = 2.7
 projects[menu_block][subdir] = contrib
 projects[menu_block][patch][2076119] = http://drupal.org/files/issues/2018-05-14/menu_block-customize_deltas-2076119-7.patch
+projects[menu_block][patch][2932156] = http://drupal.org/files/issues/2018-06-01/menu_block-rebuild-block-ids-2932156-5.patch
 
 projects[migrate][version] = 2.8
 projects[migrate][subdir] = contrib
-- 
GitLab