function requireDefaultRecords()
 {
     if ($this->class == 'TestPage') {
         return;
     }
     $class = $this->class;
     if (!DataObject::get_one($class)) {
         // Try to create common parent
         $parent = SiteTree::get()->filter('URLSegment', 'feature-test-pages')->First();
         if (!$parent) {
             $parent = new Page(array('Title' => 'Feature Test Pages', 'Content' => 'A collection of pages for testing various features in the SilverStripe CMS', 'ShowInMenus' => 0));
             $parent->write();
             $parent->doPublish();
         }
         // Create actual page
         $page = new $class();
         $page->Title = str_replace("TestPage", "", $class);
         $page->ShowInMenus = 0;
         if ($parent) {
             $page->ParentID = $parent->ID;
         }
         $page->write();
         $page->publish('Stage', 'Live');
     }
 }
Example #2
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  * @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
  * @param string $toStage Place to copy to. Must be a stage name.
  * @param boolean $createNewVersion Set this to true to create a new version number.  By default, the existing version number will be copied over.
  */
 function doPublish()
 {
     parent::doPublish();
     // Run the page (reset the theme, it might've been disabled by LeftAndMain::init())
     $oldTheme = SSViewer::current_theme();
     SSViewer::set_theme(SSViewer::current_custom_theme());
     $response = Director::test(Director::makeRelative($this->Link()));
     SSViewer::set_theme($oldTheme);
     $errorContent = $response->getBody();
     // Make the base tag dynamic.
     // $errorContent = preg_replace('/<base[^>]+href="' . str_replace('/','\\/', Director::absoluteBaseURL()) . '"[^>]*>/i', '<base href="$BaseURL" />', $errorContent);
     // Check we have an assets base directory, creating if it we don't
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH, 02775);
     }
     // if the page is published in a language other than default language,
     // write a specific language version of the HTML page
     $filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
     if ($fh = fopen($filePath, "w")) {
         fwrite($fh, $errorContent);
         fclose($fh);
     } else {
         $fileErrorText = sprintf(_t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"%s\" for writing. Please check file permissions."), $errorFile);
         FormResponse::status_message($fileErrorText, 'bad');
         FormResponse::respond();
         return;
     }
 }
 /**
  * Publishing Versioning support.
  *
  * When publishing copy the editable form fields to the live database
  * Not going to version emails and submissions as they are likely to 
  * persist over multiple versions
  *
  * @return void
  */
 public function doPublish()
 {
     // remove fields on the live table which could have been orphaned.
     $live = Versioned::get_by_stage("EditableFormField", "Live", "\"EditableFormField\".\"ParentID\" = {$this->ID}");
     if ($live) {
         foreach ($live as $field) {
             $field->doDeleteFromStage('Live');
         }
     }
     // publish the draft pages
     if ($this->Fields()) {
         foreach ($this->Fields() as $field) {
             $field->doPublish('Stage', 'Live');
         }
     }
     parent::doPublish();
 }
 function testSubsiteVirtualPagesArentInappropriatelyPublished()
 {
     // Fixture
     $p = new Page();
     $p->Content = "test content";
     $p->write();
     $vp = new SubsitesVirtualPage();
     $vp->CopyContentFromID = $p->ID;
     $vp->write();
     // VP is oragne
     $this->assertTrue($vp->IsAddedToStage);
     // VP is still orange after we publish
     $p->doPublish();
     $this->fixVersionNumberCache($vp);
     $this->assertTrue($vp->IsAddedToStage);
     // A new VP created after P's initial construction
     $vp2 = new SubsitesVirtualPage();
     $vp2->CopyContentFromID = $p->ID;
     $vp2->write();
     $this->assertTrue($vp2->IsAddedToStage);
     // Also remains orange after a republish
     $p->Content = "new content";
     $p->write();
     $p->doPublish();
     $this->fixVersionNumberCache($vp2);
     $this->assertTrue($vp2->IsAddedToStage);
     // VP is now published
     $vp->doPublish();
     $this->fixVersionNumberCache($vp);
     $this->assertTrue($vp->ExistsOnLive);
     $this->assertFalse($vp->IsModifiedOnStage);
     // P edited, VP and P both go green
     $p->Content = "third content";
     $p->write();
     $this->fixVersionNumberCache($vp, $p);
     $this->assertTrue($p->IsModifiedOnStage);
     $this->assertTrue($vp->IsModifiedOnStage);
     // Publish, VP goes black
     $p->doPublish();
     $this->fixVersionNumberCache($vp);
     $this->assertTrue($vp->ExistsOnLive);
     $this->assertFalse($vp->IsModifiedOnStage);
 }
 function testStaticPublishing()
 {
     $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 = HomepageForDomainExtension::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');
 }
Example #6
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  * @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
  * @param string $toStage Place to copy to. Must be a stage name.
  * @param boolean $createNewVersion Set this to true to create a new version number.  By default, the existing version number will be copied over.
  */
 function doPublish()
 {
     parent::doPublish();
     // Run the page
     $response = Director::test(Director::makeRelative($this->Link()));
     $errorContent = $response->getBody();
     // Check we have an assets base directory, creating if it we don't
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH, 02775);
     }
     // if the page is published in a language other than default language,
     // write a specific language version of the HTML page
     $filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
     if ($fh = fopen($filePath, "w")) {
         fwrite($fh, $errorContent);
         fclose($fh);
     } else {
         $fileErrorText = sprintf(_t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"%s\" for writing. Please check file permissions."), $errorFile);
         FormResponse::status_message($fileErrorText, 'bad');
         FormResponse::respond();
         return;
     }
 }
 public function testStaticPublisherTheme()
 {
     // This will be the name of the default theme of this particular project
     $default_theme = Config::inst()->get('SSViewer', 'theme');
     $p1 = new Page();
     $p1->URLSegment = strtolower(__CLASS__) . '-page-1';
     $p1->HomepageForDomain = '';
     $p1->write();
     $p1->doPublish();
     $current_theme = Config::inst()->get('SSViewer', 'theme_enabled') ? Config::inst()->get('SSViewer', 'theme') : null;
     $this->assertEquals($current_theme, $default_theme, 'After a standard publication, the theme is correct');
     //We can set the static_publishing theme to something completely different:
     //Static publishing will use this one instead of the current_custom_theme if it is not false
     Config::inst()->update('StaticPublisher', 'static_publisher_theme', 'otherTheme');
     $current_theme = Config::inst()->get('StaticPublisher', 'static_publisher_theme');
     $this->assertNotEquals($current_theme, $default_theme, 'The static publisher theme overrides the custom theme');
 }
	function testActionsChangedOnStageRecord() {
		if(class_exists('SiteTreeCMSWorkflow')) return true;
		
		$author = $this->objFromFixture('Member', 'cmseditor');
		$this->session()->inst_set('loggedInAs', $author->ID);
		
		$page = new Page();
		$page->CanEditType = 'LoggedInUsers';
		$page->write();
		$page->doPublish();
		$page->Content = 'Changed on Stage';
		$page->write();
		$page->flushCache();
		
		$actions = $page->getCMSActions();
		$this->assertNotNull($actions->dataFieldByName('action_save'));
		$this->assertNotNull($actions->dataFieldByName('action_publish'));
		$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
		$this->assertNotNull($actions->dataFieldByName('action_delete'));
		$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
		$this->assertNotNull($actions->dataFieldByName('action_rollback'));
		$this->assertNull($actions->dataFieldByName('action_revert'));
	}
 public function testDeletingFromLiveSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage()
 {
     // Create page and virutal page
     $p = new Page();
     $p->Title = "source";
     $p->write();
     $this->assertTrue($p->doPublish());
     $vp = new VirtualPage();
     $vp->CopyContentFromID = $p->ID;
     $vp->write();
     $this->assertTrue($vp->doPublish());
     // All is fine, the virtual page doesn't have a broken link
     $this->assertFalse($vp->HasBrokenLink);
     // Delete the source page from draft, confirm that this creates a broken link
     $pID = $p->ID;
     $p->delete();
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $this->assertEquals(1, $vp->HasBrokenLink);
     // Delete the source page form live, confirm that the virtual page has also been unpublished
     $pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
     $this->assertTrue($pLive->doDeleteFromLive());
     $vpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $vp->ID);
     $this->assertNull($vpLive);
     // Delete from draft, confirm that the virtual page has a broken link on the draft site
     $pLive->delete();
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $this->assertEquals(1, $vp->HasBrokenLink);
 }
 public function testRevertToLiveFixesBrokenLinks()
 {
     // Create page and virutal page
     $p = new Page();
     $p->Title = "source";
     $p->write();
     $pageID = $p->ID;
     $this->assertTrue($p->doPublish());
     // Content links are one kind of link to pages
     $p2 = new Page();
     $p2->Title = "regular link";
     $p2->Content = "<a href=\"[sitetree_link,id={$p->ID}]\">test</a>";
     $p2->write();
     $this->assertTrue($p2->doPublish());
     // Virtual pages are another
     $vp = new VirtualPage();
     $vp->CopyContentFromID = $p->ID;
     $vp->write();
     // Redirector links are a third
     $rp = new RedirectorPage();
     $rp->Title = "redirector";
     $rp->LinkType = 'Internal';
     $rp->LinkToID = $p->ID;
     $rp->write();
     $this->assertTrue($rp->doPublish());
     // Confirm that there are no broken links to begin with
     $this->assertFalse($p2->HasBrokenLink);
     $this->assertFalse($vp->HasBrokenLink);
     $this->assertFalse($rp->HasBrokenLink);
     // Delete from draft and confirm that broken links are marked
     $pID = $p->ID;
     $p->delete();
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $p2->flushCache();
     $p2 = DataObject::get_by_id('SiteTree', $p2->ID);
     $rp->flushCache();
     $rp = DataObject::get_by_id('SiteTree', $rp->ID);
     $this->assertEquals(1, $p2->HasBrokenLink);
     $this->assertEquals(1, $vp->HasBrokenLink);
     $this->assertEquals(1, $rp->HasBrokenLink);
     // Call doRevertToLive and confirm that broken links are restored
     $pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
     $pLive->doRevertToLive();
     $p2->flushCache();
     $p2 = DataObject::get_by_id('SiteTree', $p2->ID);
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $rp->flushCache();
     $rp = DataObject::get_by_id('SiteTree', $rp->ID);
     $this->assertFalse((bool) $p2->HasBrokenLink);
     $this->assertFalse((bool) $vp->HasBrokenLink);
     $this->assertFalse((bool) $rp->HasBrokenLink);
 }
Example #11
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  *
  * @return bool
  */
 public function doPublish()
 {
     if (!parent::doPublish()) {
         return false;
     }
     return $this->writeStaticPage();
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($new_pages = $this->owner->PageStructure) {
         $new_pages = explode("\n", $new_pages);
         $curr_level_page = array();
         $level_sequence = array(1 => 0, 2 => 0, 3 => 0, 4 => 0);
         foreach ($new_pages as $page) {
             $page_class = false;
             if (strpos($page, "|") !== false) {
                 list($page_name, $page_class) = explode("|", trim($page));
             } else {
                 $page_name = trim($page);
             }
             $level = 1;
             while (preg_match("/^\\~/", $page_name)) {
                 $page_name = substr($page_name, 1);
                 $level++;
             }
             $level_sequence[$level] += 10;
             $parentID = 0;
             if ($level > 1 && $curr_level_page[$level - 1]) {
                 $parent = $curr_level_page[$level - 1];
                 $parentID = $parent->ID;
             }
             // see if the page exists
             if (!($new_page = DataObject::get_one('SiteTree', "Title = '" . Convert::raw2sql($page_name) . "' AND ParentID = " . $parentID))) {
                 if ($page_class && $page_class != "Page" && class_exists($page_class)) {
                     $new_page = new $page_class();
                 } else {
                     $new_page = new Page();
                 }
                 $new_page->Title = $page_name;
                 $new_page->Content = '<p>Donec tristique sagittis volutpat. Donec vitae fringilla enim. Vivamus ut velit consectetur, suscipit enim eu, vestibulum ipsum. Morbi tincidunt arcu et nunc consequat dictum. Donec venenatis dolor ac dolor malesuada, non fringilla diam tristique. Duis sit amet semper velit. Vivamus porttitor lectus sed erat interdum, at facilisis urna accumsan. Nunc sit amet sapien et nibh pharetra suscipit at ac urna. Praesent semper eros a mi adipiscing vehicula. Donec pharetra aliquet porta.</p>';
                 $new_page->Status = 'Published';
                 $new_page->Sort = $level_sequence[$level];
                 if ($parentID) {
                     $new_page->ParentID = $parentID;
                 }
                 $new_page->write();
                 $new_page->writeToStage('Stage');
                 $new_page->doPublish();
                 $new_page->flushCache();
             } else {
                 // update the position if the page already exists
                 if (class_exists($page_class) && $new_page->ClassName != $page_class) {
                     $new_page->ClassName = $page_class;
                 }
                 $new_page->Sort = $level_sequence[$level];
                 $new_page->write();
                 $new_page->writeToStage('Stage');
                 $new_page->doPublish();
                 $new_page->flushCache();
             }
             $curr_level_page[$level] = $new_page;
         }
         // update sequence on error pages
         foreach (DataObject::get('ErrorPage') as $error_page) {
             $error_page->Sort = 9999;
             $error_page->write();
             $error_page->writeToStage('Stage');
             $error_page->doPublish();
             $error_page->flushCache();
         }
     }
     $this->owner->PageStructure = "";
 }
 function testDuplicateSubsite()
 {
     // get subsite1 & create page
     $subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
     $subsite1->activate();
     $page1 = new Page();
     $page1->Title = 'MyAwesomePage';
     $page1->write();
     $page1->doPublish();
     $this->assertEquals($page1->SubsiteID, $subsite1->ID);
     // duplicate
     $subsite2 = $subsite1->duplicate();
     $subsite2->activate();
     // change content on dupe
     $page2 = DataObject::get_one('Page', "\"Title\" = 'MyAwesomePage'");
     $page2->Title = 'MyNewAwesomePage';
     $page2->write();
     $page2->doPublish();
     // check change & check change has not affected subiste1
     $subsite1->activate();
     $this->assertEquals('MyAwesomePage', DataObject::get_by_id('Page', $page1->ID)->Title);
     $subsite2->activate();
     $this->assertEquals('MyNewAwesomePage', DataObject::get_by_id('Page', $page2->ID)->Title);
 }
Example #14
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  *
  * @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
  * @param string $toStage Place to copy to. Must be a stage name.
  * @param boolean $createNewVersion Set this to true to create a new version number.  By default, the existing version number will be copied over.
  */
 public function doPublish()
 {
     parent::doPublish();
     // Run the page (reset the theme, it might've been disabled by LeftAndMain::init())
     $oldEnabled = Config::inst()->get('SSViewer', 'theme_enabled');
     Config::inst()->update('SSViewer', 'theme_enabled', true);
     $response = Director::test(Director::makeRelative($this->Link()));
     Config::inst()->update('SSViewer', 'theme_enabled', $oldEnabled);
     $errorContent = $response->getBody();
     // Make the base tag dynamic.
     // $errorContent = preg_replace('/<base[^>]+href="' . str_replace('/','\\/', Director::absoluteBaseURL()) . '"[^>]*>/i', '<base href="$BaseURL" />', $errorContent);
     // Check we have an assets base directory, creating if it we don't
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH, 02775);
     }
     // if the page is published in a language other than default language,
     // write a specific language version of the HTML page
     $filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
     if ($fh = fopen($filePath, "w")) {
         fwrite($fh, $errorContent);
         fclose($fh);
     } else {
         $fileErrorText = _t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"{filename}\" for writing. Please check file permissions.", array('filename' => $errorFile));
         $this->response->addHeader('X-Status', rawurlencode($fileErrorText));
         return $this->httpError(405);
     }
 }
 function testEmbargoExpiryWithVirtualPages()
 {
     $custompublisher = $this->objFromFixture('Member', 'custompublisher');
     $custompublisher->login();
     $sourcePage = new Page();
     $sourcePage->Content = '<p>Pre-embargo</p>';
     $sourcePage->write();
     $sourcePage->doPublish();
     $sourcePage->Content = '<p>Post-embargo</p>';
     $sourcePage->write();
     $request = $sourcePage->openOrNewWorkflowRequest('WorkflowPublicationRequest');
     $sourcePage->setEmbargo('01/06/2050', '3:00pm');
     $sourcePage->write();
     $request->approve('all good');
     $virtualPage = new VirtualPage();
     $virtualPage->CopyContentFromID = $sourcePage->ID;
     $virtualPage->write();
     $virtualPage->doPublish();
     $liveVirtualPage = Versioned::get_one_by_stage('VirtualPage', 'Live', '"SiteTree"."ID" = ' . $virtualPage->ID);
     $this->assertEquals($liveVirtualPage->Content, '<p>Pre-embargo</p>');
 }
	public function testVersionedSiteTreeDeleteWithImageTracking() {
		// Assume that file tracking works. (If it does not, other
		// tests will fail as well.)
		$file = new File();
		$file->Filename = 'test-file.pdf';
		$file->write();
		$fileID = $file->ID;
		
		$page = new Page();
		$page->Title = 'Page';
		$page->Content = '<a href="assets/test-file.pdf">File</a>';
		$page->write();
		$page->doPublish();
		$pageID = $page->ID;
		
		$page->deleteFromStage('Live');
		$page = DataObject::get_by_id('Page', $pageID);
		$page->delete();
		
		$this->assertFalse((bool)DB::query("SELECT \"ID\" FROM \"SiteTree_ImageTracking\" WHERE \"SiteTreeID\" = {$pageID}")->value(),
			"many_many table SiteTree_ImageTracking not cleaned properly");
	}
 public function testEditPermissionsOnDraftVsLive()
 {
     // Create an inherit-permission page
     $page = new Page();
     $page->write();
     $page->CanEditType = "Inherit";
     $page->doPublish();
     $pageID = $page->ID;
     // Lock down the site config
     $sc = $page->SiteConfig;
     $sc->CanEditType = 'OnlyTheseUsers';
     $sc->EditorGroups()->add($this->idFromFixture('Group', 'admins'));
     $sc->write();
     // Confirm that Member.editor can't edit the page
     $this->objFromFixture('Member', 'editor')->logIn();
     $this->assertFalse($page->canEdit());
     // Change the page to be editable by Group.editors, but do not publish
     $this->objFromFixture('Member', 'admin')->logIn();
     $page->CanEditType = 'OnlyTheseUsers';
     $page->EditorGroups()->add($this->idFromFixture('Group', 'editors'));
     $page->write();
     // Clear permission cache
     SiteTree::on_db_reset();
     // Confirm that Member.editor can now edit the page
     $this->objFromFixture('Member', 'editor')->logIn();
     $this->assertTrue($page->canEdit());
     // Publish the changes to the page
     $this->objFromFixture('Member', 'admin')->logIn();
     $page->doPublish();
     // Confirm that Member.editor can still edit the page
     $this->objFromFixture('Member', 'editor')->logIn();
     $this->assertTrue($page->canEdit());
 }
 function testCmsActionsLimited()
 {
     // For 2.3 and 2.4 compatibility
     $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
     $custompublisherspage = $this->objFromFixture('SiteTree', 'custompublisherpage');
     $custompublishersgroup = $this->objFromFixture('Group', 'custompublishergroup');
     $custompublisher = $this->objFromFixture('Member', 'custompublisher');
     $workflowadmin = $this->objFromFixture('Member', 'workflowadmin');
     $custompublisher->Groups()->add($custompublishersgroup);
     $customauthorsgroup = $this->objFromFixture('Group', 'customauthorsgroup');
     $customauthor = $this->objFromFixture('Member', 'customauthor');
     $customauthor->Groups()->add($customauthorsgroup);
     $unpublishedRecord = new Page();
     $unpublishedRecord->CanEditType = 'LoggedInUsers';
     $unpublishedRecord->write();
     $unpublishedRecord->PublisherGroups()->add($custompublishersgroup);
     $custompublisher->logIn();
     $publishedRecord = new Page();
     $publishedRecord->CanEditType = 'LoggedInUsers';
     $publishedRecord->write();
     $publishedRecord->doPublish();
     $publishedRecord->PublisherGroups()->add($custompublishersgroup);
     $deletedFromLiveRecord = new Page();
     $deletedFromLiveRecord->CanEditType = 'LoggedInUsers';
     $deletedFromLiveRecord->write();
     $deletedFromLiveRecord->doPublish();
     $deletedFromLiveRecord->deleteFromStage('Live');
     $deletedFromLiveRecord->PublisherGroups()->add($custompublishersgroup);
     $deletedFromStageRecord = new Page();
     $deletedFromStageRecord->CanEditType = 'LoggedInUsers';
     $deletedFromStageRecord->write();
     $deletedFromStageRecord->PublisherGroups()->add($custompublishersgroup);
     $deletedFromStageRecord->doPublish();
     $deletedFromStageRecordID = $deletedFromStageRecord->ID;
     $deletedFromStageRecord->deleteFromStage('Stage');
     $deletedFromStageRecord = Versioned::get_one_by_stage("SiteTree", "Live", "{$bt}SiteTree{$bt}.{$bt}ID{$bt} = {$deletedFromStageRecordID}");
     $changedOnStageRecord = new Page();
     $changedOnStageRecord->CanEditType = 'LoggedInUsers';
     $changedOnStageRecord->write();
     $changedOnStageRecord->publish('Stage', 'Live');
     $changedOnStageRecord->Content = 'Changed on Stage';
     $changedOnStageRecord->write();
     $changedOnStageRecord->PublisherGroups()->add($custompublishersgroup);
     // test "publish" action for author
     $this->session()->inst_set('loggedInAs', $customauthor->ID);
     $this->assertNotContains('action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button');
     $this->assertNotContains('action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button');
     $this->assertNotContains('action_publish', $deletedFromLiveRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button');
     $this->assertNotContains('action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button');
     // test "publish" action for publisher
     $this->session()->inst_set('loggedInAs', $custompublisher->ID);
     WorkflowRequest::set_force_publishers_to_use_workflow(false);
     $this->assertContains('action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button');
     $this->assertContains('action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button');
     $this->assertContains('action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button');
     WorkflowRequest::set_force_publishers_to_use_workflow(true);
     $this->assertFalse(in_array('action_publish', $unpublishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow');
     $this->assertFalse(in_array('action_publish', $publishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow');
     $this->assertFalse(in_array('action_publish', $changedOnStageRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow');
     // test "request publication" action for author
     $this->session()->inst_set('loggedInAs', $customauthor->ID);
     $this->assertContains('action_cms_requestpublication', $unpublishedRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page is not published');
     $this->assertNotContains('action_cms_requestpublication', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request publication button if page has been published but not altered on stage');
     $this->assertContains('action_cms_requestpublication', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page has been changed on stage');
     // test "request removal" action for author
     $this->session()->inst_set('loggedInAs', $customauthor->ID);
     $this->assertNotContains('action_cms_requestdeletefromlive', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page hasnt been altered');
     $this->assertNotContains('action_cms_requestdeletefromlive', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been published but not altered on stage');
     $this->assertNotContains('action_cms_requestdeletefromlive', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been changed on stage but not deleted from stage');
     // test "request removal" action for publisher
     $this->session()->inst_set('loggedInAs', $custompublisher->ID);
     // reset login
     $this->session()->inst_set('loggedInAs', null);
 }
 function testStaticPublisherTheme()
 {
     //This will be the name of the default theme of this particular project
     $default_theme = SSViewer::current_theme();
     $p1 = new Page();
     $p1->URLSegment = strtolower(__CLASS__) . '-page-1';
     $p1->HomepageForDomain = '';
     $p1->write();
     $p1->doPublish();
     $current_theme = SSViewer::current_custom_theme();
     $this->assertEquals($current_theme, $default_theme, 'After a standard publication, the theme is correct');
     //The CMS sometimes sets the theme to null.  Check that the $current_custom_theme is still the default
     SSViewer::set_theme(null);
     $current_theme = SSViewer::current_custom_theme();
     $this->assertEquals($current_theme, $default_theme, 'After a setting the theme to null, the default theme is correct');
     //We can set the static_publishing theme to something completely different:
     //Static publishing will use this one instead of the current_custom_theme if it is not false
     StaticPublisher::set_static_publisher_theme('otherTheme');
     $current_theme = StaticPublisher::static_publisher_theme();
     $this->assertNotEquals($current_theme, $default_theme, 'The static publisher theme overrides the custom theme');
 }
 public function doPublish()
 {
     if ($this->FaqSections()) {
         foreach ($this->FaqSections() as $field) {
             $field->publish('Stage', 'Live');
         }
         $this->deleteVersionedObjects($this->FaqSections(), 'FaqSection', 'Live', $this->ID);
     }
     if ($this->FaqTags()) {
         foreach ($this->FaqTags() as $field) {
             $field->publish('Stage', 'Live');
         }
         $this->deleteVersionedObjects($this->FaqTags(), 'FaqTag', 'Live', $this->ID);
     }
     if ($this->Faqs()) {
         foreach ($this->Faqs() as $field) {
             $field->publish('Stage', 'Live');
         }
         $this->deleteVersionedObjects($this->Faqs(), 'Faq', 'Live', $this->ID);
     }
     parent::doPublish();
 }
Example #21
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  *
  * @return void
  */
 public function doPublish()
 {
     parent::doPublish();
     return $this->writeStaticPage();
 }
	public function testWithOrphanedManyManyRelations() {
		DataObjectOnDeleteDecorator::set_disabled(true);
		//JanitorDebug::set_verbose(true);
		
		$page1 = new Page();
		$page1->write();
		$page1->doPublish();
		$page1ID = $page1->ID;
		
		$page2 = new Page();
		$page2->Content .= "<p><a href=\"[sitetree_link id={$page1->ID}]\">page1 link</a></p>";
		$page2->write();
		$page2->doPublish();
		$page2ID = $page2->ID;
		
		$query = "SELECT \"ID\" FROM \"SiteTree_LinkTracking\" WHERE \"SiteTreeID\" = $page2ID AND \"ChildID\" = $page1ID";
		
		$page2->deleteFromStage('Live');
		$page2 = DataObject::get_by_id('Page', $page2ID);
		$page2->delete();
		
		$this->assertTrue((bool)DB::query($query)->value(),
			"many_many table SiteTree_LinkTracking cleaned prematurely (possibly due to SilverStripe core changes)");
		
		DataObjectOnDeleteDecorator::set_disabled(false);
		$task = new DataObjectRetroactiveCleanerTask();
		$task->run(null);
		$task->deleteBackup();
		
		$this->assertFalse((bool)DB::query($query)->value(),
			"many_many table SiteTree_LinkTracking not cleaned properly (retroactively)");
		JanitorDebug::set_verbose(false);
	}