From 3f2826115909bd0a60a2cd3ea43c2fe36a3b5d7f Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Jul 2011 13:38:41 +0200 Subject: [PATCH] some more fixes for #55 --- lib/Controller/EntityController.php | 4 ++++ lib/Model/Channel.php | 15 +++++++++++++-- lib/Model/Entity.php | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/Controller/EntityController.php b/lib/Controller/EntityController.php index 29b88e3..44edf8e 100644 --- a/lib/Controller/EntityController.php +++ b/lib/Controller/EntityController.php @@ -71,6 +71,10 @@ class EntityController extends Controller { */ public function delete($identifier) { $entity = $this->get($identifier); + + if ($entity instanceof Model\Channel) { + $entity->clearData($this->em); + } $this->em->remove($entity); $this->em->flush(); diff --git a/lib/Model/Channel.php b/lib/Model/Channel.php index 3f246b3..0954a76 100644 --- a/lib/Model/Channel.php +++ b/lib/Model/Channel.php @@ -49,14 +49,25 @@ class Channel extends Entity { $this->data = new ArrayCollection(); $this->groups = new ArrayCollection(); } - + /** * Add a new data to the database - * @todo move to Logger\Logger? */ public function addData(\Volkszaehler\Model\Data $data) { $this->data->add($data); } + + + /** + * Purge data + * + * prevents doctrine of using single delete statements + * @todo filter from & to + */ + public function clearData(\Doctrine\ORM\EntityManager $em) { + $sql = 'DELETE FROM data WHERE channel_id = ?'; + return $em->getConnection()->executeQuery($sql, array($this->id)); + } } ?> diff --git a/lib/Model/Entity.php b/lib/Model/Entity.php index 25197da..c59faba 100644 --- a/lib/Model/Entity.php +++ b/lib/Model/Entity.php @@ -59,7 +59,7 @@ abstract class Entity { protected $type; /** - * @OneToMany(targetEntity="Property", mappedBy="entity", cascade={"persist"}, orphanRemoval=true) + * @OneToMany(targetEntity="Property", mappedBy="entity", cascade={"remove", "persist"}, orphanRemoval=true) * @OrderBy({"key" = "ASC"}) */ protected $properties = NULL;