From 2c204bb0b65fe78a0d18fec0cce49360964a22ae Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Thu, 1 Mar 2018 12:15:44 +1100 Subject: [PATCH 1/3] remove DMSSiteTreeExtension.getDocumentSets() because it messes with the page history (readonly mode) --- code/DMS.php | 2 +- code/extensions/DMSSiteTreeExtension.php | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/code/DMS.php b/code/DMS.php index 887e877..46950a0 100644 --- a/code/DMS.php +++ b/code/DMS.php @@ -151,7 +151,7 @@ class DMS extends Object implements DMSInterface public function getDocumentSetsByPage(SiteTree $page) { - return $page->getDocumentSets(); + return $page->DocumentSets(); } /** diff --git a/code/extensions/DMSSiteTreeExtension.php b/code/extensions/DMSSiteTreeExtension.php index abeb7de..a4c53aa 100644 --- a/code/extensions/DMSSiteTreeExtension.php +++ b/code/extensions/DMSSiteTreeExtension.php @@ -52,16 +52,6 @@ class DMSSiteTreeExtension extends DataExtension )); } - /** - * Get a list of document sets for the owner page - * - * @return ArrayList - */ - public function getDocumentSets() - { - return $this->owner->DocumentSets(); - } - /** * Get a list of all documents from all document sets for the owner page * @@ -71,7 +61,7 @@ class DMSSiteTreeExtension extends DataExtension { $documents = ArrayList::create(); - foreach ($this->getDocumentSets() as $documentSet) { + foreach ($this->owner->DocumentSets() as $documentSet) { /** @var DocumentSet $documentSet */ $documents->merge($documentSet->getDocuments()); } From 86e01cb6d170c762e97d28edaa397b6b4a690d24 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Thu, 1 Mar 2018 12:31:44 +1100 Subject: [PATCH 2/3] fix template and tests --- templates/Includes/DocumentSets.ss | 4 ++-- tests/DMSDocumentSetTest.php | 6 +++--- tests/DMSEmbargoTest.php | 2 +- tests/tasks/MigrateToDocumentSetsTaskTest.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/Includes/DocumentSets.ss b/templates/Includes/DocumentSets.ss index 632fb29..3998fa8 100644 --- a/templates/Includes/DocumentSets.ss +++ b/templates/Includes/DocumentSets.ss @@ -1,6 +1,6 @@ -<% if $getDocumentSets %> +<% if $DocumentSets %>
- <% loop $getDocumentSets %> + <% loop $DocumentSets %> <% include DocumentSet %> <% end_loop %>
diff --git a/tests/DMSDocumentSetTest.php b/tests/DMSDocumentSetTest.php index c088618..f1bdac4 100644 --- a/tests/DMSDocumentSetTest.php +++ b/tests/DMSDocumentSetTest.php @@ -50,9 +50,9 @@ class DMSDocumentSetTest extends SapphireTest $ds2 = $this->objFromFixture('DMSDocumentSet', 'ds2'); $ds3 = $this->objFromFixture('DMSDocumentSet', 'ds3'); - $this->assertCount(0, $s4->getDocumentSets(), 'Page 4 has no document sets associated'); - $this->assertCount(2, $s1->getDocumentSets(), 'Page 1 has 2 document sets'); - $this->assertEquals(array($ds1->ID, $ds2->ID), $s1->getDocumentSets()->column('ID')); + $this->assertCount(0, $s4->DocumentSets(), 'Page 4 has no document sets associated'); + $this->assertCount(2, $s1->DocumentSets(), 'Page 1 has 2 document sets'); + $this->assertEquals(array($ds1->ID, $ds2->ID), $s1->DocumentSets()->column('ID')); } /** diff --git a/tests/DMSEmbargoTest.php b/tests/DMSEmbargoTest.php index bd5faed..54ca2a7 100644 --- a/tests/DMSEmbargoTest.php +++ b/tests/DMSEmbargoTest.php @@ -142,7 +142,7 @@ class DMSEmbargoTest extends SapphireTest $doc->Folder = "0"; $dID = $doc->write(); - $s1->getDocumentSets()->first()->getDocuments()->add($doc); + $s1->DocumentSets()->first()->getDocuments()->add($doc); $s1->publish('Stage', 'Live'); $s1->doPublish(); diff --git a/tests/tasks/MigrateToDocumentSetsTaskTest.php b/tests/tasks/MigrateToDocumentSetsTaskTest.php index de26945..d58ea16 100644 --- a/tests/tasks/MigrateToDocumentSetsTaskTest.php +++ b/tests/tasks/MigrateToDocumentSetsTaskTest.php @@ -65,9 +65,9 @@ class MigrateToDocumentSetsTaskTest extends SapphireTest $this->assertContains('Skipped: already has a set: 1', $result); // Test that some of the relationship records were written correctly - $this->assertCount(1, $firstPageSets = $this->objFromFixture('SiteTree', 'one')->getDocumentSets()); + $this->assertCount(1, $firstPageSets = $this->objFromFixture('SiteTree', 'one')->DocumentSets()); $this->assertSame('Default', $firstPageSets->first()->Title); - $this->assertCount(1, $this->objFromFixture('SiteTree', 'two')->getDocumentSets()); + $this->assertCount(1, $this->objFromFixture('SiteTree', 'two')->DocumentSets()); // With dryrun enabled and being run the second time, nothing should be done $result = $this->runTask(array('action' => 'create-default-document-set', 'dryrun' => '1')); From 1c226239f4bfa040e8250f6c98207ead840bfa74 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Wed, 11 Apr 2018 10:34:52 +1000 Subject: [PATCH 3/3] re-introduce getDocumentSets() as deprecated method to allow patch release --- code/extensions/DMSSiteTreeExtension.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/code/extensions/DMSSiteTreeExtension.php b/code/extensions/DMSSiteTreeExtension.php index a4c53aa..a6f6959 100644 --- a/code/extensions/DMSSiteTreeExtension.php +++ b/code/extensions/DMSSiteTreeExtension.php @@ -52,6 +52,19 @@ class DMSSiteTreeExtension extends DataExtension )); } + /** + * Get a list of document sets for the owner page + * + * @deprecated 3.0 Use DocumentSets() instead. + * + * @return ArrayList + */ + public function getDocumentSets() + { + Deprecation::notice('3.0', 'Use DocumentSets() instead'); + return $this->owner->hasManyComponent('DocumentSets'); + } + /** * Get a list of all documents from all document sets for the owner page *