/** * Test Hierarchy::AllHistoricalChildren(). */ function testAllHistoricalChildren() { // Delete some objs $this->objFromFixture('HierarchyTest_Object', 'obj2b')->delete(); $this->objFromFixture('HierarchyTest_Object', 'obj3a')->delete(); $this->objFromFixture('HierarchyTest_Object', 'obj3')->delete(); // Check that obj1-3 appear at the top level of the AllHistoricalChildren tree $this->assertEquals(array("Obj 1", "Obj 2", "Obj 3"), singleton('HierarchyTest_Object')->AllHistoricalChildren()->column('Title')); // Check numHistoricalChildren $this->assertEquals(3, singleton('HierarchyTest_Object')->numHistoricalChildren()); // Check that both obj 2 children are returned $obj2 = $this->objFromFixture('HierarchyTest_Object', 'obj2'); $this->assertEquals(array("Obj 2a", "Obj 2b"), $obj2->AllHistoricalChildren()->column('Title')); // Check numHistoricalChildren $this->assertEquals(2, $obj2->numHistoricalChildren()); // Obj 3 has been deleted; let's bring it back from the grave $obj3 = Versioned::get_including_deleted("HierarchyTest_Object", "\"Title\" = 'Obj 3'")->First(); // Check that both obj 3 children are returned $this->assertEquals(array("Obj 3a", "Obj 3b"), $obj3->AllHistoricalChildren()->column('Title')); // Check numHistoricalChildren $this->assertEquals(2, $obj3->numHistoricalChildren()); }
/** * Test Versioned::get_including_deleted() */ public function testGetIncludingDeleted() { // Get all ids of pages $allPageIDs = DataObject::get('VersionedTest_DataObject', "\"ParentID\" = 0", "\"VersionedTest_DataObject\".\"ID\" ASC")->column('ID'); // Modify a page, ensuring that the Version ID and Record ID will differ, // and then subsequently delete it $targetPage = $this->objFromFixture('VersionedTest_DataObject', 'page3'); $targetPage->Content = 'To be deleted'; $targetPage->write(); $targetPage->delete(); // Get all items, ignoring deleted $remainingPages = DataObject::get("VersionedTest_DataObject", "\"ParentID\" = 0", "\"VersionedTest_DataObject\".\"ID\" ASC"); // Check that page 3 has gone $this->assertNotNull($remainingPages); $this->assertEquals(array("Page 1", "Page 2"), $remainingPages->column('Title')); // Get all including deleted $allPages = Versioned::get_including_deleted("VersionedTest_DataObject", "\"ParentID\" = 0", "\"VersionedTest_DataObject\".\"ID\" ASC"); // Check that page 3 is still there $this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title')); // Check that the returned pages have the correct IDs $this->assertEquals($allPageIDs, $allPages->column('ID')); // Check that this still works if we switch to reading the other stage Versioned::reading_stage("Live"); $allPages = Versioned::get_including_deleted("VersionedTest_DataObject", "\"ParentID\" = 0", "\"VersionedTest_DataObject\".\"ID\" ASC"); $this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title')); // Check that the returned pages still have the correct IDs $this->assertEquals($allPageIDs, $allPages->column('ID')); }
public function run() { $this->log("Upgrading formfield rules and custom settings"); // List of rules that have been created in all stages $fields = Versioned::get_including_deleted('EditableFormField'); foreach ($fields as $field) { $this->upgradeField($field); } }
/** * Test which pages can be published via batch actions */ public function testBatchArchive() { $this->logInWithPermission('ADMIN'); $pages = Versioned::get_including_deleted('Page'); $ids = $pages->column('ID'); $action = new CMSBatchAction_Archive(); // Test applicable pages $applicable = $action->applicablePages($ids); $this->assertContains($this->idFromFixture('Page', 'published'), $applicable); $this->assertNotContains($this->idFromFixture('Page', 'archived'), $applicable); $this->assertContains($this->idFromFixture('Page', 'unpublished'), $applicable); $this->assertContains($this->idFromFixture('Page', 'modified'), $applicable); }
/** * Test Hierarchy::AllHistoricalChildren(). */ function testAllHistoricalChildren() { // Delete some pages $this->objFromFixture('Page', 'page2b')->delete(); $this->objFromFixture('Page', 'page3a')->delete(); $this->objFromFixture('Page', 'page3')->delete(); // Check that page1-3 appear at the top level of the AllHistoricalChildren tree $this->assertEquals(array("Page 1", "Page 2", "Page 3"), singleton('Page')->AllHistoricalChildren()->column('Title')); // Check that both page 2 children are returned $page2 = $this->objFromFixture('Page', 'page2'); $this->assertEquals(array("Page 2a", "Page 2b"), $page2->AllHistoricalChildren()->column('Title')); // Page 3 has been deleted; let's bring it back from the grave $page3 = Versioned::get_including_deleted("SiteTree", "Title = 'Page 3'")->First(); // Check that both page 3 children are returned $this->assertEquals(array("Page 3a", "Page 3b"), $page3->AllHistoricalChildren()->column('Title')); }
/** * Test Versioned::get_including_deleted() */ function testGetIncludingDeleted() { // Delete a page $this->objFromFixture('Page', 'page3')->delete(); // Get all items, ignoring deleted $remainingPages = DataObject::get("SiteTree", "\"ParentID\" = 0", "\"SiteTree\".\"ID\" ASC"); // Check that page 3 has gone $this->assertNotNull($remainingPages); $this->assertEquals(array("Page 1", "Page 2"), $remainingPages->column('Title')); // Get all including deleted $allPages = Versioned::get_including_deleted("SiteTree", "\"ParentID\" = 0", "\"SiteTree\".\"ID\" ASC"); // Check that page 3 is still there $this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title')); // Check that this still works if we switch to reading the other stage Versioned::reading_stage("Live"); $allPages = Versioned::get_including_deleted("SiteTree", "\"ParentID\" = 0", "\"SiteTree\".\"ID\" ASC"); $this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title')); }
/** * Return all the children that this page had, including pages that were deleted * from both stage & live. */ public function AllHistoricalChildren() { $baseClass = ClassInfo::baseDataClass($this->owner->class); return Versioned::get_including_deleted($baseClass, "\"ParentID\" = " . (int) $this->owner->ID, "\"{$baseClass}\".\"ID\" ASC"); }
/** * Return the number of children that this page ever had, including pages that were deleted */ public function numHistoricalChildren() { if (!$this->owner->hasExtension('Versioned')) { throw new Exception('Hierarchy->AllHistoricalChildren() only works with Versioned extension applied'); } return Versioned::get_including_deleted(ClassInfo::baseDataClass($this->owner->class), "\"ParentID\" = " . (int) $this->owner->ID)->count(); }
function pagesIncluded() { $ids = array(); // TODO Not very memory efficient, but usually not very many deleted pages exist $pages = Versioned::get_including_deleted('SiteTree'); if ($pages) { foreach ($pages as $page) { $ids[] = array('ID' => $page->ID, 'ParentID' => $page->ParentID); } } return $ids; }
/** * Filters out all pages who's status is set to "Deleted". * * @see {@link SiteTree::getStatusFlags()} * @return SS_List */ public function getFilteredPages() { $pages = Versioned::get_including_deleted('SiteTree'); $pages = $this->applyDefaultFilters($pages); $pages = $pages->filterByCallback(function ($page) { // Doesn't exist on either stage or live return $page->getIsDeletedFromStage() && !$page->getExistsOnLive(); }); return $pages; }
/** * Return all the children that this page had, including pages that were deleted * from both stage & live. */ public function AllHistoricalChildren() { return Versioned::get_including_deleted(ClassInfo::baseDataClass($this->owner->class), "ParentID = " . (int) $this->owner->ID); }
/** * Safely query and return all pages queried * * @param array $ids * @return SS_List */ protected function getPages($ids) { // Check empty set if (empty($ids)) { return new ArrayList(); } $recordClass = $this->recordClass; // Bypass translatable filter if (class_exists('Translatable') && $recordClass::has_extension('Translatable')) { Translatable::disable_locale_filter(); } // Bypass versioned filter if ($recordClass::has_extension('Versioned')) { // Workaround for get_including_deleted not supporting byIDs filter very well // Ensure we select both stage / live records $pages = Versioned::get_including_deleted($recordClass, array('"RecordID" IN (' . DB::placeholders($ids) . ')' => $ids)); } else { $pages = DataObject::get($recordClass)->byIDs($ids); } if (class_exists('Translatable') && $recordClass::has_extension('Translatable')) { Translatable::enable_locale_filter(); } return $pages; }
public function testBatchRestore() { $this->logInWithPermission('ADMIN'); $pages = Versioned::get_including_deleted('SiteTree'); $action = new CMSBatchAction_Restore(); $archivedID = $this->idFromFixture('SiteTree', 'archived'); $archivedxID = $this->idFromFixture('SiteTree', 'archivedx'); $archivedyID = $this->idFromFixture('SiteTree', 'archivedy'); // Just restore one child $list = $pages->filter('RecordID', $archivedxID); $this->assertEquals(1, $list->count()); $this->assertEquals($archivedID, $list->first()->ParentID); // Run restore $result = json_decode($action->run($list), true); $this->assertEquals(array($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('RecordID', array($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), true); $this->assertEquals(array($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 }