mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
BUGFIX: working DMS tags
This commit is contained in:
parent
08ec5a7cac
commit
7b18e3ba7e
@ -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();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user