|
@@ 2278-2298 (lines=21) @@
|
| 2275 |
|
* @param object $document |
| 2276 |
|
* @param array $visited |
| 2277 |
|
*/ |
| 2278 |
|
private function cascadeDetach($document, array &$visited) |
| 2279 |
|
{ |
| 2280 |
|
$class = $this->dm->getClassMetadata(get_class($document)); |
| 2281 |
|
foreach ($class->fieldMappings as $mapping) { |
| 2282 |
|
if ( ! $mapping['isCascadeDetach']) { |
| 2283 |
|
continue; |
| 2284 |
|
} |
| 2285 |
|
$relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
| 2286 |
|
if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
| 2287 |
|
if ($relatedDocuments instanceof PersistentCollection) { |
| 2288 |
|
// Unwrap so that foreach() does not initialize |
| 2289 |
|
$relatedDocuments = $relatedDocuments->unwrap(); |
| 2290 |
|
} |
| 2291 |
|
foreach ($relatedDocuments as $relatedDocument) { |
| 2292 |
|
$this->doDetach($relatedDocument, $visited); |
| 2293 |
|
} |
| 2294 |
|
} elseif ($relatedDocuments !== null) { |
| 2295 |
|
$this->doDetach($relatedDocuments, $visited); |
| 2296 |
|
} |
| 2297 |
|
} |
| 2298 |
|
} |
| 2299 |
|
/** |
| 2300 |
|
* Cascades a merge operation to associated documents. |
| 2301 |
|
* |
|
@@ 2398-2419 (lines=22) @@
|
| 2395 |
|
* @param object $document |
| 2396 |
|
* @param array $visited |
| 2397 |
|
*/ |
| 2398 |
|
private function cascadeRemove($document, array &$visited) |
| 2399 |
|
{ |
| 2400 |
|
$class = $this->dm->getClassMetadata(get_class($document)); |
| 2401 |
|
foreach ($class->fieldMappings as $mapping) { |
| 2402 |
|
if ( ! $mapping['isCascadeRemove']) { |
| 2403 |
|
continue; |
| 2404 |
|
} |
| 2405 |
|
if ($document instanceof Proxy && ! $document->__isInitialized__) { |
| 2406 |
|
$document->__load(); |
| 2407 |
|
} |
| 2408 |
|
|
| 2409 |
|
$relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
| 2410 |
|
if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
| 2411 |
|
// If its a PersistentCollection initialization is intended! No unwrap! |
| 2412 |
|
foreach ($relatedDocuments as $relatedDocument) { |
| 2413 |
|
$this->doRemove($relatedDocument, $visited); |
| 2414 |
|
} |
| 2415 |
|
} elseif ($relatedDocuments !== null) { |
| 2416 |
|
$this->doRemove($relatedDocuments, $visited); |
| 2417 |
|
} |
| 2418 |
|
} |
| 2419 |
|
} |
| 2420 |
|
|
| 2421 |
|
/** |
| 2422 |
|
* Acquire a lock on the given document. |