diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index 4be9fce..82729ac 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -282,15 +282,25 @@ public function save(array $link) { * depth. */ protected function doSave(array $link) { - $original = $this->loadFull($link['id'], FALSE); $affected_menus = []; + // Get the existing definition if it exist. This does not use + // self::loadFull() because we want to compare with $link after calling + // self::preSave() and therefore we need to avoid the unserialization. + $query = $this->connection->select($this->table, $this->options); + $query->fields($this->table); + $query->condition('id', $link['id']); + $original = $this->safeExecuteSelect($query)->fetchAssoc(); + if ($original) { $link['mlid'] = $original['mlid']; $link['has_children'] = $original['has_children']; $affected_menus[$original['menu_name']] = $original['menu_name']; $fields = $this->preSave($link, $original); + // If $link matches the $original data then exit early as there are no + // changes to make. if (array_diff_assoc($fields, $original) === []) { + // @todo should we return an empty array as nothing has changed? return $affected_menus; } } @@ -303,7 +313,7 @@ protected function doSave(array $link) { $link['mlid'] = $this->connection->insert($this->table, $options) ->fields(['id' => $link['id'], 'menu_name' => $link['menu_name']]) ->execute(); - $fields = $this->preSave($link, $original); + $fields = $this->preSave($link, []); } // We may be moving the link to a new menu. $affected_menus[$fields['menu_name']] = $fields['menu_name']; @@ -722,14 +732,12 @@ public function load($id) { * * @param string $id * The menu link ID. - * @param bool $unserialize - * Determines if fields be unserialized. Defaults to TRUE. * * @return array * The loaded menu link definition or an empty array if not be found. */ - protected function loadFull($id, $unserialize = TRUE) { - $loaded = $this->loadFullMultiple([$id], $unserialize); + protected function loadFull($id) { + $loaded = $this->loadFullMultiple([$id]); return isset($loaded[$id]) ? $loaded[$id] : []; } @@ -738,23 +746,19 @@ protected function loadFull($id, $unserialize = TRUE) { * * @param array $ids * The IDs to load. - * @param bool $unserialize - * Determines if fields be unserialized. Defaults to TRUE. * * @return array * The loaded menu link definitions. */ - protected function loadFullMultiple(array $ids, $unserialize = TRUE) { + protected function loadFullMultiple(array $ids) { $query = $this->connection->select($this->table, $this->options); $query->fields($this->table); $query->condition('id', $ids, 'IN'); $loaded = $this->safeExecuteSelect($query)->fetchAllAssoc('id', \PDO::FETCH_ASSOC); - if ($unserialize) { - foreach ($loaded as &$link) { - foreach ($this->serializedFields() as $name) { - if (isset($link[$name])) { - $link[$name] = unserialize($link[$name]); - } + foreach ($loaded as &$link) { + foreach ($this->serializedFields() as $name) { + if (isset($link[$name])) { + $link[$name] = unserialize($link[$name]); } } }