From 7b18e3ba7e49a605e6b80c1e0eb6704fffb9c30c Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Fri, 27 Jul 2012 12:36:45 +1200 Subject: [PATCH] BUGFIX: working DMS tags --- code/DMSDocument.php | 25 ++++++++++++++++--------- tests/DMSTagTest.php | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/code/DMSDocument.php b/code/DMSDocument.php index f1c1ef4..d8cc293 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -108,10 +108,6 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { $valueFilter = array("Category" => $category); if (!empty($value)) $valueFilter['Value'] = $value; - if ($this->ID == 2) { - Debug::Show($this); - Debug::Show($this->Tags()); - } $tags = $this->Tags()->filter($valueFilter); return $tags; } @@ -174,14 +170,15 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { $documentList->remove($this); //delete the entire tag if it has no relations left - if ($documentList->Count() == 0) $tagsToDelete[] = $t->ID; + if ($documentList->Count() == 0) $t->delete(); } + //TODO: remove this comment if unit tests work fine //delete after the loop, so it doesn't conflict with the loop of the $tags list - foreach($tagsToDelete as $tID) { - $tag = DataObject::get_by_id("DMSTag",$tID); - $tag->delete(); - } +// foreach($tagsToDelete as $tID) { +// $tag = DataObject::get_by_id("DMSTag",$tID); +// $tag->delete(); +// } } } @@ -190,10 +187,20 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { * @return null */ function removeAllTags() { + $tagsToDelete = array(); $allTags = $this->Tags(); foreach($allTags as $tag) { + $documentlist = $tag->Documents(); + $documentlist->remove($this); if ($tag->Documents()->Count() == 0) $tag->delete(); } + + //TODO: remove this comment if unit tests work fine + //delete after the loop, so it doesn't conflict with the loop of the $tags list +// foreach($tagsToDelete as $tID) { +// $tag = DataObject::get_by_id("DMSTag",$tID); +// $tag->delete(); +// } } /** diff --git a/tests/DMSTagTest.php b/tests/DMSTagTest.php index eb927c8..5df13f2 100644 --- a/tests/DMSTagTest.php +++ b/tests/DMSTagTest.php @@ -27,7 +27,7 @@ class DMSTagTest extends SapphireTest { $doc2->write(); $doc2->addTag("fruit","banana"); - $fruits = $doc->getTags("fruit"); + $fruits = $doc2->getTags("fruit"); $this->assertNotNull($fruits,"Something returned for fruit tags"); $this->assertEquals(count($fruits),1,"Only 1 fruit tags returned"); @@ -35,7 +35,7 @@ class DMSTagTest extends SapphireTest { $doc->removeAllTags(); //banana fruit remains - $doc2->getTags("fruit"); + $fruits = $doc2->getTags("fruit"); $this->assertNotNull($fruits,"Something returned for fruit tags"); $this->assertEquals(count($fruits),1,"Only 1 fruit tags returned");