From ef27e9954c9809b64f38925ea9aa5fd86a9cbe64 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 10 May 2024 11:45:25 +1200 Subject: [PATCH] FIX Remove deprecated restore batch action --- code/BatchActions/CMSBatchAction_Restore.php | 72 ------------------ tests/php/Controllers/CMSBatchActionsTest.php | 74 ------------------- .../php/Forms/SiteTreeURLSegmentFieldTest.php | 1 - 3 files changed, 147 deletions(-) delete mode 100644 code/BatchActions/CMSBatchAction_Restore.php diff --git a/code/BatchActions/CMSBatchAction_Restore.php b/code/BatchActions/CMSBatchAction_Restore.php deleted file mode 100644 index d9699c6c..00000000 --- a/code/BatchActions/CMSBatchAction_Restore.php +++ /dev/null @@ -1,72 +0,0 @@ -toArray(); - // because of https://bugs.php.net/bug.php?id=50688 - /** @var SiteTree $page */ - foreach ($pageArray as $page) { - $page->getPageLevel(); - } - usort($pageArray, function (SiteTree $a, SiteTree $b) { - return $a->getPageLevel() - $b->getPageLevel(); - }); - $pages = new ArrayList($pageArray); - - // Restore - return $this->batchaction( - $pages, - 'doRestoreToStage', - _t(__CLASS__ . '.RESTORED_PAGES', 'Restored %d pages') - ); - } - - /** - * {@see SiteTree::canEdit()} - * - * @param array $ids - * @return array - */ - public function applicablePages($ids) - { - // Basic permission check based on SiteTree::canEdit - if (!Permission::check(["ADMIN", "SITETREE_EDIT_ALL"])) { - return []; - } - - // Get pages that exist in stage and remove them from the restore-able set - $stageIDs = Versioned::get_by_stage($this->managedClass, Versioned::DRAFT)->column('ID'); - return array_values(array_diff($ids ?? [], $stageIDs)); - } -} diff --git a/tests/php/Controllers/CMSBatchActionsTest.php b/tests/php/Controllers/CMSBatchActionsTest.php index 6ed8f8d3..94598ea5 100644 --- a/tests/php/Controllers/CMSBatchActionsTest.php +++ b/tests/php/Controllers/CMSBatchActionsTest.php @@ -4,7 +4,6 @@ namespace SilverStripe\CMS\Tests\Controllers; use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive; use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish; -use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore; use SilverStripe\CMS\BatchActions\CMSBatchAction_Unpublish; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Config; @@ -105,77 +104,4 @@ class CMSBatchActionsTest extends SapphireTest $this->assertContains($this->idFromFixture(SiteTree::class, 'unpublished'), $applicable); $this->assertContains($this->idFromFixture(SiteTree::class, 'modified'), $applicable); } - - /** - * Test restore batch actions - */ - public function testBatchRestoreApplicable() - { - $this->logInWithPermission('ADMIN'); - $pages = Versioned::get_including_deleted(SiteTree::class); - $ids = $pages->column('ID'); - $action = new CMSBatchAction_Restore(); - - // Test applicable pages - $applicable = $action->applicablePages($ids); - $this->assertNotContains($this->idFromFixture(SiteTree::class, 'published'), $applicable); - $this->assertContains($this->idFromFixture(SiteTree::class, 'archived'), $applicable); - $this->assertContains($this->idFromFixture(SiteTree::class, 'archivedx'), $applicable); - $this->assertContains($this->idFromFixture(SiteTree::class, 'archivedy'), $applicable); - $this->assertNotContains($this->idFromFixture(SiteTree::class, 'unpublished'), $applicable); - $this->assertNotContains($this->idFromFixture(SiteTree::class, 'modified'), $applicable); - } - - public function testBatchRestore() - { - $this->logInWithPermission('ADMIN'); - $pages = Versioned::get_including_deleted(SiteTree::class); - $action = new CMSBatchAction_Restore(); - $archivedID = $this->idFromFixture(SiteTree::class, 'archived'); - $archivedxID = $this->idFromFixture(SiteTree::class, 'archivedx'); - $archivedyID = $this->idFromFixture(SiteTree::class, 'archivedy'); - - // Just restore one child - $list = $pages->filter('ID', $archivedxID); - $this->assertEquals(1, $list->count()); - $this->assertEquals($archivedID, $list->first()->ParentID); - - // Run restore - $result = json_decode($action->run($list)->getBody(), true); - $this->assertEquals( - [ - $archivedxID => $archivedxID, - ], - $result['success'] - ); - $archivedx = SiteTree::get()->byID($archivedxID); - $this->assertNotNull($archivedx); - $this->assertEquals(0, $archivedx->ParentID); // Restore to root because parent is unrestored - - // Restore both remaining pages - $list = $pages - ->filter('ID', [$archivedID, $archivedyID]) - ->sort('Title'); - $this->assertEquals(2, $list->count()); - $this->assertEquals($archivedID, $list->first()->ParentID); // archivedy - $this->assertEquals(0, $list->last()->ParentID); // archived (parent) - - // Run restore - $result = json_decode($action->run($list)->getBody(), true); - $this->assertEquals( - [ - // Order of archived is opposite to order items are passed in, as - // these are sorted by level first - $archivedID => $archivedID, - $archivedyID => $archivedyID, - ], - $result['success'] - ); - $archived = SiteTree::get()->byID($archivedID); - $archivedy = SiteTree::get()->byID($archivedyID); - $this->assertNotNull($archived); - $this->assertNotNull($archivedy); - $this->assertEquals($archivedID, $archivedy->ParentID); // Not restored to root, but to the parent - $this->assertEquals(0, $archived->ParentID); // Root stays root - } } diff --git a/tests/php/Forms/SiteTreeURLSegmentFieldTest.php b/tests/php/Forms/SiteTreeURLSegmentFieldTest.php index c1f020b2..1c9f7df3 100644 --- a/tests/php/Forms/SiteTreeURLSegmentFieldTest.php +++ b/tests/php/Forms/SiteTreeURLSegmentFieldTest.php @@ -4,7 +4,6 @@ namespace SilverStripe\CMS\Tests\Controllers; use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive; use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish; -use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore; use SilverStripe\CMS\BatchActions\CMSBatchAction_Unpublish; use SilverStripe\CMS\Forms\SiteTreeURLSegmentField; use SilverStripe\CMS\Model\SiteTree;