Commit 4615f8c3 authored by alexpott's avatar alexpott

Issue #2388905 by chx: menu link storage override requires too much copy-paste

parent a1246044
......@@ -171,20 +171,7 @@ public function rebuild(array $definitions) {
$this->saveRecursive($id, $children, $links);
}
}
// Find any previously discovered menu links that no longer exist.
if ($definitions) {
$query = $this->connection->select($this->table, NULL, $this->options);
$query->addField($this->table, 'id');
$query->condition('discovered', 1);
$query->condition('id', array_keys($definitions), 'NOT IN');
// Starting from links with the greatest depth will minimize the amount
// of re-parenting done by the menu storage.
$query->orderBy('depth', 'DESC');
$result = $query->execute()->fetchCol();
}
else {
$result = array();
}
$result = $this->findNoLongerExistingLinks($definitions);
// Remove all such items.
if ($result) {
......@@ -218,9 +205,7 @@ protected function purgeMultiple(array $ids) {
}
}
}
$query = $this->connection->delete($this->table, $this->options);
$query->condition('id', $ids, 'IN');
$query->execute();
$this->doDeleteMultiple($ids);
}
/**
......@@ -431,9 +416,7 @@ public function delete($id) {
$this->save($child);
}
$this->connection->delete($this->table, $this->options)
->condition('id', $id)
->execute();
$this->doDeleteMultiple([$id]);
$this->updateParentalStatus($item);
// Many children may have moved.
......@@ -1442,4 +1425,41 @@ protected static function schemaDefinition() {
return $schema;
}
/**
* Find any previously discovered menu links that no longer exist.
*
* @param array $definitions
* The new menu link definitions.
* @return array
* A list of menu link IDs that no longer exist.
*/
protected function findNoLongerExistingLinks(array $definitions) {
if ($definitions) {
$query = $this->connection->select($this->table, NULL, $this->options);
$query->addField($this->table, 'id');
$query->condition('discovered', 1);
$query->condition('id', array_keys($definitions), 'NOT IN');
// Starting from links with the greatest depth will minimize the amount
// of re-parenting done by the menu storage.
$query->orderBy('depth', 'DESC');
$result = $query->execute()->fetchCol();
}
else {
$result = array();
}
return $result;
}
/**
* Purge menu links from the database.
*
* @param array $ids
* A list of menu link IDs to be purged.
*/
protected function doDeleteMultiple(array $ids) {
$this->connection->delete($this->table, $this->options)
->condition('id', $ids, 'IN')
->execute();
}
}
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