Permalink
Browse files

Also remove ancestors data when removing former fixtures (refs #198)

  • Loading branch information...
1 parent dfeb22b commit 7f5d1ea0db8e1b20b8ebef54827bebe5699da6d6 @jpetitcolas jpetitcolas committed Dec 10, 2012
Showing with 26 additions and 9 deletions.
  1. +26 −9 DataFixtures/Loader/AbstractDataLoader.php
View
35 DataFixtures/Loader/AbstractDataLoader.php
@@ -92,18 +92,35 @@ protected function deleteCurrentData($data = null)
if (in_array($class, $this->deletedClasses)) {
continue;
}
+ $this->deleteClassData($class);
+ }
+ }
+ }
- // Check that peer class exists before calling doDeleteAll()
- $peerClass = constant($class.'::PEER');
- if (!class_exists($peerClass)) {
- throw new \InvalidArgumentException(sprintf('Unknown class "%sPeer".', $class));
- }
+ /**
+ * Delete data for a given class, and for its ancestors (if any).
+ *
+ * @param string $class Class name to delete
+ */
+ protected function deleteClassData($class)
+ {
+ // Check that peer class exists before calling doDeleteAll()
+ $peerClass = constant($class.'::PEER');
+ if (!class_exists($peerClass)) {
+ throw new \InvalidArgumentException(sprintf('Unknown class "%sPeer".', $class));
+ }
+
+ // bypass the soft_delete behavior if enabled
+ $deleteMethod = method_exists($peerClass, 'doForceDeleteAll') ? 'doForceDeleteAll' : 'doDeleteAll';
+ call_user_func(array($peerClass, $deleteMethod), $this->con);
- // bypass the soft_delete behavior if enabled
- $deleteMethod = method_exists($peerClass, 'doForceDeleteAll') ? 'doForceDeleteAll' : 'doDeleteAll';
- call_user_func(array($peerClass, $deleteMethod), $this->con);
+ $this->deletedClasses[] = $class;
- $this->deletedClasses[] = $class;
+ // Remove ancestors data
+ if(false !== ($parentClass = get_parent_class(get_parent_class($class)))) {
+ $reflectionClass = new \ReflectionClass($parentClass);
+ if(!$reflectionClass->isAbstract()) {
+ $this->deleteClassData($parentClass);
}
}
}

0 comments on commit 7f5d1ea

Please sign in to comment.