Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/Opus/Licence.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ protected function init()
{
$active = new Field('Active');
$active->setCheckbox(true);
$active->setType('bool');

$commentInternal = new Field('CommentInternal');
$commentInternal->setTextarea(true);
Expand Down Expand Up @@ -152,6 +153,7 @@ protected function init()

$podAllowed = new Field('PodAllowed');
$podAllowed->setCheckbox(true);
$podAllowed->setType('bool');

$this->addField($active)
->addField($commentInternal)
Expand Down
14 changes: 12 additions & 2 deletions library/Opus/Model/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,18 @@ public function setValue($value)
}
} else {
// strong comparison for other values
if ($value === $this->value) {
return $this;
switch($this->getType()) {
case 'bool':
// Initially the stored value is null which matches false, but field needs to be set
// TODO better way?
if ((bool) $value === (bool) $this->value && ($this->value !== null || $value === null)) {
return $this;
}
break;
default:
if ($value === $this->value) {
return $this;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions library/Opus/Model/Plugin/updatedocument_filter.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Opus\DnbInstitute[]=DnbContactId
Opus\DnbInstitute[]=IsGrantor
Opus\DnbInstitute[]=IsPublisher

Opus\Licence[]=Active
Opus\Licence[]=SortOrder
Opus\Licence[]=CommentInternal
Opus\Licence[]=PodAllowed
Expand Down
17 changes: 17 additions & 0 deletions tests/Opus/LicenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,21 @@ public function testAddLicence()

$this->assertEquals($licenceId, $licences[0]->getId());
}

public function testIsModified()
{
$licence = Licence::new();
$licence->setNameLong('Test Licence');
$licence->setLinkLicence('http://www.example.org/licence');
$licence->setActive(true);
$licenceId = $licence->store();

$licence = Licence::get($licenceId);

$this->assertFalse($licence->isModified());

$licence->setActive('1');

$this->assertFalse($licence->isModified());
}
}
33 changes: 33 additions & 0 deletions tests/Opus/Model/Plugin/InvalidateDocumentCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function setUp(): void
'collections_roles',
'collections',
'link_documents_collections',
'document_licences',
'link_documents_licences',
]);

$this->collectionRole = new CollectionRole();
Expand Down Expand Up @@ -703,4 +705,35 @@ public function testStoringUnchangedDocumentDoesNotUpdateServerDateModified()
$doc->store();
$this->assertEquals($lastModified, $doc->getServerDateModified()->getUnixTimestamp());
}

public function testLicenceActiveDoesNotUpdateServerDateModified()
{
$doc = new Document();

$licence = new Licence();
$licence->setLanguage('deu');
$licence->setNameLong('Test Licence');
$licence->setLinkLicence('http://long.org/licence');
$licence->setActive(1);
$licenceId = $licence->store();

$doc->setLicence([$licence]);
$docId = $doc->store();

$doc = new Document($docId);

$this->assertCount(1, $doc->getLicence());

$serverDateModified = $doc->getServerDateModified()->getUnixTimestamp();

sleep(2);

$licence = new Licence($licenceId);
$licence->setActive(true);
$licence->store();

$doc = new Document($docId);

$this->assertEquals($serverDateModified, $doc->getServerDateModified()->getUnixTimestamp());
}
}