|
@@ -38,8 +38,8 @@ class Closure implements Strategy
|
|
|
* @var array
|
|
|
*/
|
|
|
protected $pendingChildNodeInserts = array();
|
|
|
-
|
|
|
- /**
|
|
|
+
|
|
|
+ /**
|
|
|
* List of pending Nodes to remove
|
|
|
*
|
|
|
* @var array
|
|
@@ -61,8 +61,8 @@ class Closure implements Strategy
|
|
|
{
|
|
|
return Strategy::CLOSURE;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
+
|
|
|
+ /**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function processPrePersist($em, $entity)
|
|
@@ -108,20 +108,20 @@ class Closure implements Strategy
|
|
|
$entityTable = $meta->getTableName();
|
|
|
$closureTable = $closureMeta->getTableName();
|
|
|
$entries = array();
|
|
|
- $childrenIDs = array();
|
|
|
+ $childrenIDs = array();
|
|
|
$ancestorsIDs = array();
|
|
|
|
|
|
- // If node has children it means it already has a self referencing row, so we skip its insertion
|
|
|
- if ($addNodeChildrenToAncestors === false) {
|
|
|
+ // If node has children it means it already has a self referencing row, so we skip its insertion
|
|
|
+ if ($addNodeChildrenToAncestors === false) {
|
|
|
$entries[] = array(
|
|
|
'ancestor' => $id,
|
|
|
'descendant' => $id,
|
|
|
'depth' => 0
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$parent = $meta->getReflectionProperty($config['parent'])->getValue($entity);
|
|
|
-
|
|
|
+
|
|
|
if ( $parent ) {
|
|
|
$parentId = $meta->getReflectionProperty($identifier)->getValue($parent);
|
|
|
$dql = "SELECT c.ancestor, c.depth FROM {$closureMeta->name} c";
|
|
@@ -135,7 +135,7 @@ class Closure implements Strategy
|
|
|
'depth' => $ancestor['depth'] + 1
|
|
|
);
|
|
|
$ancestorsIDs[] = $ancestor['ancestor'];
|
|
|
-
|
|
|
+
|
|
|
if ($addNodeChildrenToAncestors === true) {
|
|
|
$dql = "SELECT c.descendant, c.depth FROM {$closureMeta->name} c";
|
|
|
$dql .= " WHERE c.ancestor = {$id} AND c.ancestor != c.descendant";
|
|
@@ -190,18 +190,15 @@ class Closure implements Strategy
|
|
|
$oldParent = $change[0];
|
|
|
$nodeId = $this->extractIdentifier($em, $entity);
|
|
|
$table = $closureMeta->getTableName();
|
|
|
-
|
|
|
+
|
|
|
if ($oldParent) {
|
|
|
$this->removeClosurePathsOfNodeID($em, $table, $nodeId);
|
|
|
|
|
|
$this->insertNode($em, $entity, true);
|
|
|
}
|
|
|
-
|
|
|
- //\Doctrine\Common\Util\Debug::dump($oldParent);
|
|
|
- //die();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
+
|
|
|
+ /**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function processScheduledDelete($em, $entity)
|
|
@@ -218,7 +215,7 @@ class Closure implements Strategy
|
|
|
}
|
|
|
|
|
|
public function removeNode(EntityManager $em, $entity, $maintainSelfReferencingRow = false, $maintainSelfReferencingRowOfChildren = false)
|
|
|
- {
|
|
|
+ {
|
|
|
$meta = $em->getClassMetadata(get_class($entity));
|
|
|
$config = $this->listener->getConfiguration($em, $meta->name);
|
|
|
$closureMeta = $em->getClassMetadata($config['closure']);
|
|
@@ -227,13 +224,13 @@ class Closure implements Strategy
|
|
|
$this->removeClosurePathsOfNodeID($em, $closureMeta->getTableName(), $id, $maintainSelfReferencingRow, $maintainSelfReferencingRowOfChildren);
|
|
|
}
|
|
|
|
|
|
- public function removeClosurePathsOfNodeID(EntityManager $em, $table, $nodeId, $maintainSelfReferencingRow = true, $maintainSelfReferencingRowOfChildren = true)
|
|
|
- {
|
|
|
+ public function removeClosurePathsOfNodeID(EntityManager $em, $table, $nodeId, $maintainSelfReferencingRow = true, $maintainSelfReferencingRowOfChildren = true)
|
|
|
+ {
|
|
|
$subquery = "SELECT c1.id FROM {$table} c1 ";
|
|
|
$subquery .= "WHERE c1.descendant IN ( SELECT c2.descendant FROM {$table} c2 WHERE c2.ancestor = :id ) ";
|
|
|
$subquery .= "AND ( c1.ancestor IN ( SELECT c3.ancestor FROM {$table} c3 WHERE c3.descendant = :id ";
|
|
|
|
|
|
- if ($maintainSelfReferencingRow === true)
|
|
|
+ if ($maintainSelfReferencingRow === true)
|
|
|
{
|
|
|
$subquery .= "AND c3.descendant != c3.ancestor ";
|
|
|
}
|
|
@@ -244,9 +241,9 @@ class Closure implements Strategy
|
|
|
}
|
|
|
|
|
|
$subquery .= " ) ) ";
|
|
|
-
|
|
|
+
|
|
|
$subquery = "DELETE FROM {$table} WHERE {$table}.id IN ( SELECT temp_table.id FROM ( {$subquery} ) temp_table )";
|
|
|
-
|
|
|
+
|
|
|
if (!$em->getConnection()->executeQuery($subquery, array('id' => $nodeId))) {
|
|
|
throw new \Gedmo\Exception\RuntimeException('Failed to delete old Closure records');
|
|
|
}
|