function testPageWithVirtualPagesGetsTable() { $importantpage = $this->objFromFixture('SiteTree', 'importantpage'); $link = new SubsitesVirtualPage(); $link->CopyContentFromID = $importantpage->ID; $link->write(); $link->doPublish(); $fields = $importantpage->getCMSFields(); $this->assertNotNull($fields->fieldByName('Root.VirtualPages')); }
function run($request) { $subsiteFromId = $request->getVar('from'); if (!is_numeric($subsiteFromId)) { throw new InvalidArgumentException('Missing "from" parameter'); } $subsiteFrom = DataObject::get_by_id('Subsite', $subsiteFromId); if (!$subsiteFrom) { throw new InvalidArgumentException('Subsite not found'); } $subsiteToId = $request->getVar('to'); if (!is_numeric($subsiteToId)) { throw new InvalidArgumentException('Missing "to" parameter'); } $subsiteTo = DataObject::get_by_id('Subsite', $subsiteToId); if (!$subsiteTo) { throw new InvalidArgumentException('Subsite not found'); } $useVirtualPages = (bool) $request->getVar('virtual'); Subsite::changeSubsite($subsiteFrom); // Copy data from this template to the given subsite. Does this using an iterative depth-first search. // This will make sure that the new parents on the new subsite are correct, and there are no funny // issues with having to check whether or not the new parents have been added to the site tree // when a page, etc, is duplicated $stack = array(array(0, 0)); while (count($stack) > 0) { list($sourceParentID, $destParentID) = array_pop($stack); $children = Versioned::get_by_stage('SiteTree', 'Live', "\"ParentID\" = {$sourceParentID}", ''); if ($children) { foreach ($children as $child) { if ($useVirtualPages) { $childClone = new SubsitesVirtualPage(); $childClone->writeToStage('Stage'); $childClone->CopyContentFromID = $child->ID; $childClone->SubsiteID = $subsiteTo->ID; } else { $childClone = $child->duplicateToSubsite($subsiteTo->ID, true); } $childClone->ParentID = $destParentID; $childClone->writeToStage('Stage'); $childClone->publish('Stage', 'Live'); array_push($stack, array($child->ID, $childClone->ID)); $this->log(sprintf('Copied "%s" (#%d, %s)', $child->Title, $child->ID, $child->Link())); } } unset($children); } }
function testUnpublishingParentPageUnpublishesSubsiteVirtualPages() { StaticPublisher::$disable_realtime = true; // Go to main site, get parent page $subsite = $this->objFromFixture('Subsite_Template', 'main'); Subsite::changeSubsite($subsite->ID); $page = $this->objFromFixture('SiteTree', 'importantpage'); // Create two SVPs on other subsites $subsite = $this->objFromFixture('Subsite_Template', 'subsite1'); Subsite::changeSubsite($subsite->ID); $vp1 = new SubsitesVirtualPage(); $vp1->CopyContentFromID = $page->ID; $vp1->write(); $vp1->doPublish(); $subsite = $this->objFromFixture('Subsite_Template', 'subsite2'); Subsite::changeSubsite($subsite->ID); $vp2 = new SubsitesVirtualPage(); $vp2->CopyContentFromID = $page->ID; $vp2->write(); $vp2->doPublish(); // Switch back to main site, unpublish source $subsite = $this->objFromFixture('Subsite_Template', 'main'); Subsite::changeSubsite($subsite->ID); $page = $this->objFromFixture('SiteTree', 'importantpage'); $page->doUnpublish(); Subsite::changeSubsite($vp1->SubsiteID); $onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = " . $vp1->ID); $this->assertFalse($onLive, 'SVP has been removed from live'); $subsite = $this->objFromFixture('Subsite_Template', 'subsite2'); Subsite::changeSubsite($vp2->SubsiteID); $onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = " . $vp2->ID); $this->assertFalse($onLive, 'SVP has been removed from live'); }
/** * Similar to {@link SiteTreeSubsitesTest->testTwoPagesWithSameURLOnDifferentSubsites()} * and {@link SiteTreeSubsitesTest->testPagesInDifferentSubsitesCanShareURLSegment()}. */ function testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite() { Subsite::$write_hostmap = false; $subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite2 = $this->objFromFixture('Subsite', 'subsite2'); Subsite::changeSubsite($subsite1->ID); $subsite1Page = $this->objFromFixture('Page', 'subsite1_staff'); $subsite1Page->URLSegment = 'staff'; $subsite1Page->write(); // saving on subsite1, and linking to subsite1 $subsite1Vp = new SubsitesVirtualPage(); $subsite1Vp->CopyContentFromID = $subsite1Page->ID; $subsite1Vp->SubsiteID = $subsite1->ID; $subsite1Vp->write(); $this->assertNotEquals($subsite1Vp->URLSegment, $subsite1Page->URLSegment, "Doesn't allow explicit URLSegment overrides when already existing in same subsite"); //Change to subsite 2 Subsite::changeSubsite($subsite2->ID); // saving in subsite2 (which already has a page with URLSegment 'contact-us'), // but linking to a page in subsite1 $subsite2Vp = new SubsitesVirtualPage(); $subsite2Vp->CopyContentFromID = $subsite1Page->ID; $subsite2Vp->SubsiteID = $subsite2->ID; $subsite2Vp->write(); $this->assertEquals($subsite2Vp->URLSegment, $subsite1Page->URLSegment, "Does allow explicit URLSegment overrides when only existing in a different subsite"); }