| @@ 1681-1710 (lines=30) @@ | ||
| 1678 | * |
|
| 1679 | * @return void |
|
| 1680 | */ |
|
| 1681 | private function cascadeRefresh($entity, array &$visited) |
|
| 1682 | { |
|
| 1683 | $class = $this->em->getClassMetadata(get_class($entity)); |
|
| 1684 | $associationMappings = array_filter( |
|
| 1685 | $class->associationMappings, |
|
| 1686 | function ($assoc) { |
|
| 1687 | return $assoc['isCascadeRefresh']; |
|
| 1688 | } |
|
| 1689 | ); |
|
| 1690 | foreach ($associationMappings as $assoc) { |
|
| 1691 | $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); |
|
| 1692 | switch (true) { |
|
| 1693 | case ($relatedEntities instanceof PersistentCollection): |
|
| 1694 | // Unwrap so that foreach() does not initialize |
|
| 1695 | $relatedEntities = $relatedEntities->unwrap(); |
|
| 1696 | // break; is commented intentionally! |
|
| 1697 | case ($relatedEntities instanceof Collection): |
|
| 1698 | case (is_array($relatedEntities)): |
|
| 1699 | foreach ($relatedEntities as $relatedEntity) { |
|
| 1700 | $this->doRefresh($relatedEntity, $visited); |
|
| 1701 | } |
|
| 1702 | break; |
|
| 1703 | case ($relatedEntities !== null): |
|
| 1704 | $this->doRefresh($relatedEntities, $visited); |
|
| 1705 | break; |
|
| 1706 | default: |
|
| 1707 | // Do nothing |
|
| 1708 | } |
|
| 1709 | } |
|
| 1710 | } |
|
| 1711 | ||
| 1712 | /** |
|
| 1713 | * Cascades a detach operation to associated entities. |
|
| @@ 1720-1749 (lines=30) @@ | ||
| 1717 | * |
|
| 1718 | * @return void |
|
| 1719 | */ |
|
| 1720 | private function cascadeDetach($entity, array &$visited) |
|
| 1721 | { |
|
| 1722 | $class = $this->em->getClassMetadata(get_class($entity)); |
|
| 1723 | $associationMappings = array_filter( |
|
| 1724 | $class->associationMappings, |
|
| 1725 | function ($assoc) { |
|
| 1726 | return $assoc['isCascadeDetach']; |
|
| 1727 | } |
|
| 1728 | ); |
|
| 1729 | foreach ($associationMappings as $assoc) { |
|
| 1730 | $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); |
|
| 1731 | switch (true) { |
|
| 1732 | case ($relatedEntities instanceof PersistentCollection): |
|
| 1733 | // Unwrap so that foreach() does not initialize |
|
| 1734 | $relatedEntities = $relatedEntities->unwrap(); |
|
| 1735 | // break; is commented intentionally! |
|
| 1736 | case ($relatedEntities instanceof Collection): |
|
| 1737 | case (is_array($relatedEntities)): |
|
| 1738 | foreach ($relatedEntities as $relatedEntity) { |
|
| 1739 | $this->doDetach($relatedEntity, $visited); |
|
| 1740 | } |
|
| 1741 | break; |
|
| 1742 | case ($relatedEntities !== null): |
|
| 1743 | $this->doDetach($relatedEntities, $visited); |
|
| 1744 | break; |
|
| 1745 | default: |
|
| 1746 | // Do nothing |
|
| 1747 | } |
|
| 1748 | } |
|
| 1749 | } |
|
| 1750 | ||
| 1751 | /** |
|
| 1752 | * Cascades a merge operation to associated entities. |
|