BUGFIX: working DMS tags

This commit is contained in:
Julian Seidenberg 2012-07-27 12:36:45 +12:00
parent 08ec5a7cac
commit 7b18e3ba7e
2 changed files with 18 additions and 11 deletions

View File

@ -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();
// }
}
/**

View File

@ -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");