function testHomepageMapIsWithStaticPublishing() { $this->logInWithPermission('ADMIN'); $p1 = new Page(); $p1->URLSegment = strtolower(__CLASS__) . '-page-1'; $p1->HomepageForDomain = ''; $p1->write(); $p1->doPublish(); $p2 = new Page(); $p2->URLSegment = strtolower(__CLASS__) . '-page-2'; $p2->HomepageForDomain = 'domain1'; $p2->write(); $p2->doPublish(); $p3 = new Page(); $p3->URLSegment = strtolower(__CLASS__) . '-page-3'; $p3->HomepageForDomain = 'domain2,domain3'; $p3->write(); $p3->doPublish(); $map = SiteTree::generate_homepage_domain_map(); $this->assertEquals($map, array('domain1' => strtolower(__CLASS__) . '-page-2', 'domain2' => strtolower(__CLASS__) . '-page-3', 'domain3' => strtolower(__CLASS__) . '-page-3'), 'Homepage/domain map is correct when static publishing is enabled'); }
/** * Publish this page. * * @uses SiteTreeDecorator->onBeforePublish() * @uses SiteTreeDecorator->onAfterPublish() */ function doPublish() { if (!$this->canPublish()) { return false; } $original = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = {$this->ID}"); if (!$original) { $original = new SiteTree(); } // Handle activities undertaken by decorators $this->invokeWithExtensions('onBeforePublish', $original); $this->Status = "Published"; //$this->PublishedByID = Member::currentUser()->ID; $this->write(); $this->publish("Stage", "Live"); DB::query("UPDATE \"SiteTree_Live\"\n\t\t\tSET \"Sort\" = (SELECT \"SiteTree\".\"Sort\" FROM \"SiteTree\" WHERE \"SiteTree_Live\".\"ID\" = \"SiteTree\".\"ID\")\n\t\t\tWHERE EXISTS (SELECT \"SiteTree\".\"Sort\" FROM \"SiteTree\" WHERE \"SiteTree_Live\".\"ID\" = \"SiteTree\".\"ID\") AND \"ParentID\" = " . sprintf('%d', $this->ParentID)); // Publish any virtual pages that might need publishing $linkedPages = $this->VirtualPages(); if ($linkedPages) { foreach ($linkedPages as $page) { $page->copyFrom($page->CopyContentFrom()); $page->write(); if ($page->ExistsOnLive) { $page->doPublish(); } } } // Need to update pages linking to this one as no longer broken, on the live site $origMode = Versioned::get_reading_mode(); Versioned::reading_stage('Live'); foreach ($this->DependentPages(false) as $page) { // $page->write() calls syncLinkTracking, which does all the hard work for us. $page->write(); } Versioned::set_reading_mode($origMode); // Check to write CMS homepage map. $usingStaticPublishing = false; foreach (ClassInfo::subclassesFor('StaticPublisher') as $class) { if ($this->hasExtension($class)) { $usingStaticPublishing = true; } } // NOTE: if you change the path here, you must also change it in sapphire/static-main.php if (self::$write_homepage_map) { if ($usingStaticPublishing && ($map = SiteTree::generate_homepage_domain_map())) { @file_put_contents(BASE_PATH . '/' . ASSETS_DIR . '/_homepage-map.php', "<?php\n\$homepageMap = " . var_export($map, true) . "; ?>"); } else { if (file_exists(BASE_PATH . '/' . ASSETS_DIR . '/_homepage-map.php')) { unlink(BASE_PATH . '/' . ASSETS_DIR . '/_homepage-map.php'); } } } // Handle activities undertaken by decorators $this->invokeWithExtensions('onAfterPublish', $original); return true; }