Last active
December 16, 2015 19:59
-
-
Save khuppenbauer/5489450 to your computer and use it in GitHub Desktop.
Remove an object from Repository with foreign keys disabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Package\Domain\Repository; | |
/* * | |
* This script belongs to the Flow package "Your.Package". * | |
* * | |
* */ | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\Flow\Persistence\Doctrine\Repository; | |
/** | |
* @Flow\Scope("singleton") | |
*/ | |
class YourRepository extends Repository { | |
/** | |
* Doctrine's Entity Manager. Note that "ObjectManager" is the name of the related | |
* interface ... | |
* | |
* @Flow\Inject | |
* @var \Doctrine\Common\Persistence\ObjectManager | |
*/ | |
protected $entityManager; | |
/** | |
* Removes an object from this repository. | |
* | |
* @param object $object The object to remove | |
* @return void | |
* @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException | |
* @api | |
*/ | |
public function remove($object) { | |
if (!is_object($object) || !($object instanceof $this->entityClassName)) { | |
$type = (is_object($object) ? get_class($object) : gettype($object)); | |
throw new \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException('The value given to remove() was ' . $type . ' , however the ' . get_class($this) . ' can only handle ' . $this->entityClassName . ' instances.', 1298403442); | |
} | |
$this->entityManager->getConnection()->exec('SET foreign_key_checks = 0'); | |
$this->persistenceManager->remove($object); | |
$this->entityManager->getConnection()->exec('SET foreign_key_checks = 1'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment