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 #2
0
 /**
  * Add default records to database.
  *
  * This function is called whenever the database is built, after the
  * database tables have all been created. Overload this to add default
  * records when the database is built, but make sure you call
  * parent::requireDefaultRecords().
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     // default pages
     if ($this->class == 'SiteTree' && self::$create_default_pages) {
         if (!SiteTree::get_by_link('home')) {
             $homepage = new Page();
             $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');
             $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.org">developer documentation</a>, or begin <a href="http://doc.silverstripe.org/doku.php?id=tutorials">the tutorials.</a></p>');
             $homepage->URLSegment = 'home';
             $homepage->Status = 'Published';
             $homepage->Sort = 1;
             $homepage->write();
             $homepage->publish('Stage', 'Live');
             $homepage->flushCache();
             DB::alteration_message('Home page created', 'created');
         }
         if (DB::query("SELECT COUNT(*) FROM \"SiteTree\"")->value() == 1) {
             $aboutus = new Page();
             $aboutus->Title = _t('SiteTree.DEFAULTABOUTTITLE', 'About Us');
             $aboutus->Content = _t('SiteTree.DEFAULTABOUTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>');
             $aboutus->Status = 'Published';
             $aboutus->Sort = 2;
             $aboutus->write();
             $aboutus->publish('Stage', 'Live');
             $aboutus->flushCache();
             DB::alteration_message('About Us page created', 'created');
             $contactus = new Page();
             $contactus->Title = _t('SiteTree.DEFAULTCONTACTTITLE', 'Contact Us');
             $contactus->Content = _t('SiteTree.DEFAULTCONTACTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>');
             $contactus->Status = 'Published';
             $contactus->Sort = 3;
             $contactus->write();
             $contactus->publish('Stage', 'Live');
             $contactus->flushCache();
             DB::alteration_message('Contact Us page created', 'created');
         }
     }
     // schema migration
     // @todo Move to migration task once infrastructure is implemented
     if ($this->class == 'SiteTree') {
         $conn = DB::getConn();
         // only execute command if fields haven't been renamed to _obsolete_<fieldname> already by the task
         if (array_key_exists('Viewers', $conn->fieldList('SiteTree'))) {
             $task = new UpgradeSiteTreePermissionSchemaTask();
             $task->run(new SS_HTTPRequest('GET', '/'));
         }
     }
 }
	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'));
	}
Example #4
0
 /**
  * Add default records to database.
  *
  * This function is called whenever the database is built, after the
  * database tables have all been created. Overload this to add default
  * records when the database is built, but make sure you call
  * parent::requireDefaultRecords().
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if ($this->class == 'SiteTree') {
         if (!DataObject::get_one("SiteTree", "URLSegment = 'home'")) {
             $homepage = new Page();
             $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');
             $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.com">developer documentation</a>, or begin <a href="http://doc.silverstripe.com/doku.php?id=tutorials">the tutorials.</a></p>');
             $homepage->URLSegment = "home";
             $homepage->Status = "Published";
             $homepage->write();
             $homepage->publish("Stage", "Live");
             $homepage->flushCache();
             Database::alteration_message("Home page created", "created");
         }
         if (DB::query("SELECT COUNT(*) FROM SiteTree")->value() == 1) {
             $aboutus = new Page();
             $aboutus->Title = _t('SiteTree.DEFAULTABOUTTITLE', 'About Us');
             $aboutus->Content = _t('SiteTree.DEFAULTABOUTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>');
             $aboutus->URLSegment = "about-us";
             $aboutus->Status = "Published";
             $aboutus->write();
             $aboutus->publish("Stage", "Live");
             Database::alteration_message("About Us created", "created");
             $contactus = new Page();
             $contactus->Title = _t('SiteTree.DEFAULTCONTACTTITLE', 'Contact Us');
             $contactus->Content = _t('SiteTree.DEFAULTCONTACTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>');
             $contactus->URLSegment = "contact-us";
             $contactus->Status = "Published";
             $contactus->write();
             $contactus->publish("Stage", "Live");
             $contactus->flushCache();
         }
     }
 }
Example #5
0
 public function flushCache($persistant = true)
 {
     parent::flushCache($persistant);
     $this->newsAggregateCache = array();
 }
 function flushCache($persistent = true)
 {
     parent::flushCache();
     unset($this->_cachedVideos);
 }
 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 flushCache()
 {
     parent::flushCache();
     unset($this->_cachedVideos);
 }