From 535bfcbe80de5d697b768c3a657214fdeff0eac3 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 30 Oct 2016 09:58:39 +0100 Subject: Move related event things in Event folder --- .../Subscriber/SQLiteCascadeDeleteSubscriber.php | 70 ---------------------- .../Subscriber/TablePrefixSubscriber.php | 51 ---------------- 2 files changed, 121 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Subscriber/SQLiteCascadeDeleteSubscriber.php delete mode 100644 src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php (limited to 'src/Wallabag/CoreBundle/Subscriber') diff --git a/src/Wallabag/CoreBundle/Subscriber/SQLiteCascadeDeleteSubscriber.php b/src/Wallabag/CoreBundle/Subscriber/SQLiteCascadeDeleteSubscriber.php deleted file mode 100644 index f7210bd3..00000000 --- a/src/Wallabag/CoreBundle/Subscriber/SQLiteCascadeDeleteSubscriber.php +++ /dev/null @@ -1,70 +0,0 @@ -doctrine = $doctrine; - } - - /** - * @return array - */ - public function getSubscribedEvents() - { - return [ - 'preRemove', - ]; - } - - /** - * We removed everything related to the upcoming removed entry because SQLite can't handle it on it own. - * We do it in the preRemove, because we can't retrieve tags in the postRemove (because the entry id is gone). - * - * @param LifecycleEventArgs $args - */ - public function preRemove(LifecycleEventArgs $args) - { - $entity = $args->getEntity(); - - if (!$this->doctrine->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver || - !$entity instanceof Entry) { - return; - } - - $em = $this->doctrine->getManager(); - - if (null !== $entity->getTags()) { - foreach ($entity->getTags() as $tag) { - $entity->removeTag($tag); - } - } - - if (null !== $entity->getAnnotations()) { - foreach ($entity->getAnnotations() as $annotation) { - $em->remove($annotation); - } - } - - $em->flush(); - } -} diff --git a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php deleted file mode 100644 index 0379ad6a..00000000 --- a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php +++ /dev/null @@ -1,51 +0,0 @@ -prefix = (string) $prefix; - } - - public function getSubscribedEvents() - { - return ['loadClassMetadata']; - } - - public function loadClassMetadata(LoadClassMetadataEventArgs $args) - { - $classMetadata = $args->getClassMetadata(); - - // if we are in an inheritance hierarchy, only apply this once - if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { - return; - } - - $classMetadata->setTableName($this->prefix.$classMetadata->getTableName()); - - foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { - if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) { - $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; - $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName; - } - } - } -} -- cgit v1.2.3