/**
  * Perform migration
  *
  * @param string $base Absolute base path (parent of assets folder). Will default to BASE_PATH
  * @return int Number of files successfully migrated
  */
 public function run($base = null)
 {
     if (empty($base)) {
         $base = BASE_PATH;
     }
     // Check if the File dataobject has a "Filename" field.
     // If not, cannot migrate
     if (!DB::get_schema()->hasField('File', 'Filename')) {
         return 0;
     }
     // Set max time and memory limit
     increase_time_limit_to();
     increase_memory_limit_to();
     // Loop over all files
     $count = 0;
     $originalState = \Versioned::get_reading_mode();
     \Versioned::reading_stage('Stage');
     $filenameMap = $this->getFilenameArray();
     foreach ($this->getFileQuery() as $file) {
         // Get the name of the file to import
         $filename = $filenameMap[$file->ID];
         $success = $this->migrateFile($base, $file, $filename);
         if ($success) {
             $count++;
         }
     }
     \Versioned::set_reading_mode($originalState);
     return $count;
 }
 /**
  * Create a new report
  *
  * @param array  $data
  * @param Form $form
  */
 public function createreport($data, $form)
 {
     // assume a user's okay if they can edit the reportholder
     // @TODO have a new create permission here?
     if ($this->data()->canEdit()) {
         $type = $data['ReportType'];
         $classes = ClassInfo::subclassesFor('AdvancedReport');
         if (!in_array($type, $classes)) {
             throw new Exception("Invalid report type");
         }
         $report = new ReportPage();
         $report->Title = $data['ReportName'];
         $report->MetaDescription = isset($data['ReportDescription']) ? $data['ReportDescription'] : '';
         $report->ReportType = $type;
         $report->ParentID = $this->data()->ID;
         $oldMode = Versioned::get_reading_mode();
         Versioned::reading_stage('Stage');
         $report->write();
         $report->doPublish();
         Versioned::reading_stage('Live');
         $this->redirect($report->Link());
     } else {
         $form->sessionMessage(_t('ReporHolder.NO_PERMISSION', 'You do not have permission to do that'), 'warning');
         $this->redirect($this->data()->Link());
     }
 }
 /**
  *	Instantiate a search page, should one not exist.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $mode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // Determine whether pages should be created.
     if (self::config()->create_default_pages) {
         // Determine whether an extensible search page already exists.
         if (!ExtensibleSearchPage::get()->first()) {
             // Instantiate an extensible search page.
             $page = ExtensibleSearchPage::create();
             $page->Title = 'Search Page';
             $page->write();
             DB::alteration_message('"Default" Extensible Search Page', 'created');
         }
     } else {
         if (ClassInfo::exists('Multisites')) {
             foreach (Site::get() as $site) {
                 // Determine whether an extensible search page already exists.
                 if (!ExtensibleSearchPage::get()->filter('SiteID', $site->ID)->first()) {
                     // Instantiate an extensible search page.
                     $page = ExtensibleSearchPage::create();
                     $page->ParentID = $site->ID;
                     $page->Title = 'Search Page';
                     $page->write();
                     DB::alteration_message("\"{$site->Title}\" Extensible Search Page", 'created');
                 }
             }
         }
     }
     Versioned::set_reading_mode($mode);
 }
 /**
  * Return the currently viewed future datetime
  */
 static function get_future_datetime()
 {
     $parts = explode('.', Versioned::get_reading_mode());
     if ($parts[0] == 'FutureState') {
         return $parts[1];
     }
 }
 /**
  * To process this job, we need to get the next page whose ID is the next greater than the last
  * processed. This way we don't need to remember a bunch of data about what we've processed
  */
 public function process()
 {
     if (ClassInfo::exists('Subsite')) {
         Subsite::disable_subsite_filter();
     }
     $class = $this->reindexType;
     $pages = $class::get();
     $pages = $pages->filter(array('ID:GreaterThan' => $this->lastIndexedID));
     $pages = $pages->limit(Config::inst()->get(__CLASS__, 'at_a_time'));
     $pages = $pages->sort('ID ASC');
     if (ClassInfo::exists('Subsite')) {
         Subsite::$disable_subsite_filter = false;
     }
     if (!$pages || !$pages->count()) {
         $this->isComplete = true;
         return;
     }
     $mode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // index away
     $service = singleton('SolrSearchService');
     $live = array();
     $stage = array();
     $all = array();
     foreach ($pages as $page) {
         // Make sure the current page is not orphaned.
         if ($page->ParentID > 0) {
             $parent = $page->getParent();
             if (is_null($parent) || $parent === false) {
                 continue;
             }
         }
         // Appropriately index the current page, taking versioning into account.
         if ($page->hasExtension('Versioned')) {
             $stage[] = $page;
             $base = $page->baseTable();
             $idField = '"' . $base . '_Live"."ID"';
             $livePage = Versioned::get_one_by_stage($page->ClassName, 'Live', $idField . ' = ' . $page->ID);
             if ($livePage) {
                 $live[] = $livePage;
             }
         } else {
             $all[] = $page;
         }
         $this->lastIndexedID = $page->ID;
     }
     if (count($all)) {
         $service->indexMultiple($all);
     }
     if (count($stage)) {
         $service->indexMultiple($stage, 'Stage');
     }
     if (count($live)) {
         $service->indexMultiple($live, 'Live');
     }
     Versioned::set_reading_mode($mode);
     $this->lastIndexedID = $page->ID;
     $this->currentStep += $pages->count();
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (empty($this->byPass)) {
         $this->readmode = Versioned::get_reading_mode();
         Versioned::set_reading_mode('Stage.Stage');
     }
 }
Exemple #7
0
 public function getGroupedGames()
 {
     // show all if in draft mode
     $mode = Versioned::get_reading_mode();
     if ($mode == 'Stage.Stage') {
         $items = GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID))->sort('Session'));
     } else {
         $items = GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID, 'Status' => true))->sort('Session'));
     }
     return $items;
 }
 /**
  * Returns an array with 2 elements, one with a list of Page on the site (and all subsites if
  * applicable) and another with files.
  *
  * @return array
  */
 public function sourceRecords()
 {
     if (class_exists('Subsite') && Subsite::get()->count() > 0) {
         $origMode = Versioned::get_reading_mode();
         Versioned::set_reading_mode('Stage.Stage');
         $items = array('Pages' => Subsite::get_from_all_subsites('SiteTree'), 'Files' => Subsite::get_from_all_subsites('File'));
         Versioned::set_reading_mode($origMode);
         return $items;
     } else {
         return array('Pages' => Versioned::get_by_stage('SiteTree', 'Stage'), 'Files' => File::get());
     }
 }
 /**
  * @inheritdoc
  *
  * @return array
  */
 function check()
 {
     $origStage = Versioned::get_reading_mode();
     Versioned::set_reading_mode('Live');
     $files = $this->getFiles();
     if ($files) {
         $fileTypeValidateFunc = $this->fileTypeValidateFunc;
         if (method_exists($this, $fileTypeValidateFunc)) {
             $invalidFiles = array();
             $validFiles = array();
             foreach ($files as $file) {
                 if ($this->{$fileTypeValidateFunc}($file)) {
                     $validFiles[] = $file;
                 } else {
                     $invalidFiles[] = $file;
                 }
             }
             // If at least one file was valid, count as passed
             if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
                 $validFileList = "\n";
                 foreach ($validFiles as $vf) {
                     $validFileList .= $vf . "\n";
                 }
                 if ($fileTypeValidateFunc == 'noVidation') {
                     $checkReturn = array(EnvironmentCheck::OK, sprintf('At least these file(s) accessible: %s', $validFileList));
                 } else {
                     $checkReturn = array(EnvironmentCheck::OK, sprintf('At least these file(s) passed file type validate function "%s": %s', $fileTypeValidateFunc, $validFileList));
                 }
             } else {
                 if (count($invalidFiles) == 0) {
                     $checkReturn = array(EnvironmentCheck::OK, 'All files valideted');
                 } else {
                     $invalidFileList = "\n";
                     foreach ($invalidFiles as $vf) {
                         $invalidFileList .= $vf . "\n";
                     }
                     if ($fileTypeValidateFunc == 'noVidation') {
                         $checkReturn = array(EnvironmentCheck::ERROR, sprintf('File(s) not accessible: %s', $invalidFileList));
                     } else {
                         $checkReturn = array(EnvironmentCheck::ERROR, sprintf('File(s) not passing the file type validate function "%s": %s', $fileTypeValidateFunc, $invalidFileList));
                     }
                 }
             }
         } else {
             $checkReturn = array(EnvironmentCheck::ERROR, sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc));
         }
     } else {
         $checkReturn = array(EnvironmentCheck::ERROR, sprintf("No files accessible at path %s", $this->path));
     }
     Versioned::set_reading_mode($origStage);
     return $checkReturn;
 }
 public function __construct(Index $index, Query $query, LoggerInterface $logger = null)
 {
     //Optimise the query by just getting back the ids and types
     $query->setFields(array('_id', '_type'));
     //If we are in live reading mode, only return published documents
     if (\Versioned::get_reading_mode() == \Versioned::DEFAULT_MODE) {
         $publishedFilter = new Query\BoolQuery();
         $publishedFilter->addMust(new Query\Term([Searchable::$published_field => 'true']));
         $query->setPostFilter($publishedFilter);
     }
     $this->index = $index;
     $this->query = $query;
     $this->logger = $logger;
 }
 /**
  * 
  * @return DataList
  */
 protected function getAllLivePages($subsiteID = 0)
 {
     ini_set('memory_limit', '200M');
     $oldMode = Versioned::get_reading_mode();
     if (class_exists('Subsite')) {
         Subsite::disable_subsite_filter(true);
     }
     Versioned::reading_stage('Live');
     $pages = DataObject::get("SiteTree");
     Versioned::set_reading_mode($oldMode);
     if (class_exists('Subsite')) {
         return $pages->filter(array('SubsiteID' => $subsiteID));
     }
     return $pages;
 }
 /**
  * @param SS_HTTPRequest $request
  *
  * @return string|HTMLText
  */
 public function preview(SS_HTTPRequest $request)
 {
     $key = $request->param('Key');
     $token = $request->param('Token');
     /**
      * @var ShareToken $shareToken
      */
     $shareToken = ShareToken::get()->filter('token', $token)->first();
     if (!$shareToken) {
         return $this->errorPage();
     }
     $page = Versioned::get_one_by_stage('SiteTree', 'Stage', sprintf('"SiteTree"."ID" = \'%d\'', $shareToken->PageID));
     $latest = Versioned::get_latest_version('SiteTree', $shareToken->PageID);
     $controller = $this->getControllerFor($page);
     if (!$shareToken->isExpired() && $page->generateKey($shareToken->Token) === $key) {
         Requirements::css(SHAREDRAFTCONTENT_DIR . '/css/top-bar.css');
         // Temporarily un-secure the draft site and switch to draft
         $oldSecured = Session::get('unsecuredDraftSite');
         $oldMode = Versioned::get_reading_mode();
         $restore = function () use($oldSecured, $oldMode) {
             Session::set('unsecuredDraftSite', $oldSecured);
             Versioned::set_reading_mode($oldMode);
         };
         // Process page inside an unsecured draft container
         try {
             Session::set('unsecuredDraftSite', true);
             Versioned::reading_stage('Stage');
             // Create mock request; Simplify request to single top level reqest
             $pageRequest = new SS_HTTPRequest('GET', $page->URLSegment);
             $pageRequest->match('$URLSegment//$Action/$ID/$OtherID', true);
             $rendered = $controller->handleRequest($pageRequest, $this->model);
             // Render draft heading
             $data = new ArrayData(array('Page' => $page, 'Latest' => $latest));
             $include = (string) $data->renderWith('Includes/TopBar');
         } catch (Exception $ex) {
             $restore();
             throw $ex;
         }
         $restore();
         return str_replace('</body>', $include . '</body>', (string) $rendered->getBody());
     } else {
         return $this->errorPage();
     }
 }
 public function doSavePost($data, $form)
 {
     $post = false;
     if (isset($data['ID']) && $data['ID']) {
         $post = BlogPost::get()->byID($data['ID']);
     }
     if (!$post) {
         $post = BlogPost::create();
     }
     $form->saveInto($post);
     $post->ParentID = $this->owner->ID;
     $this->owner->extend("onBeforeSavePost", $blogentry);
     $oldMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     $post->write();
     $post->publish("Stage", "Live");
     Versioned::set_reading_mode($oldMode);
     $this->owner->extend("onAfterSavePost", $post);
     $this->owner->redirect($this->owner->Link());
 }
 public function setUp()
 {
     parent::setUp();
     if (!class_exists('Phockito')) {
         $this->skipTest = true;
         return $this->markTestSkipped("These tests need the Phockito module installed to run");
     }
     // Check versioned available
     if (!class_exists('Versioned')) {
         $this->skipTest = true;
         return $this->markTestSkipped('The versioned decorator is not installed');
     }
     if (self::$index === null) {
         self::$index = singleton('SolrVersionedTest_Index');
     }
     SearchUpdater::bind_manipulation_capture();
     Config::nest();
     Config::inst()->update('Injector', 'SearchUpdateProcessor', array('class' => 'SearchUpdateImmediateProcessor'));
     FullTextSearch::force_index_list(self::$index);
     SearchUpdater::clear_dirty_indexes();
     $this->oldMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
 }
 /**
  *	Update the searchable content tagging for a specific fusion tag.
  *
  *	@parameter <{FUSION_TAG_ID}> integer
  */
 public function updateTagging($fusionID)
 {
     // Determine any data objects with the tagging extension.
     $classes = ClassInfo::subclassesFor('DataObject');
     unset($classes['DataObject']);
     $configuration = Config::inst();
     foreach ($classes as $class) {
         // Determine the specific data object extensions.
         $extensions = $configuration->get($class, 'extensions', Config::UNINHERITED);
         if (is_array($extensions) && in_array('TaggingExtension', $extensions)) {
             // Determine whether this fusion tag is being used.
             $mode = Versioned::get_reading_mode();
             Versioned::reading_stage('Stage');
             $objects = $class::get()->filter('FusionTags.ID', $fusionID);
             // Update the searchable content tagging for these data objects.
             if ($class::has_extension($class, 'Versioned')) {
                 // These data objects are versioned.
                 foreach ($objects as $object) {
                     // Update the staging version.
                     $object->writeWithoutVersion();
                 }
                 Versioned::reading_stage('Live');
                 $objects = $class::get()->filter('FusionTags.ID', $fusionID);
                 foreach ($objects as $object) {
                     // Update the live version.
                     $object->writeWithoutVersion();
                 }
             } else {
                 // These data objects are not versioned.
                 foreach ($objects as $object) {
                     $object->write();
                 }
             }
             Versioned::set_reading_mode($mode);
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->loginWithPermission('ADMIN');
     // Save versioned state
     $this->oldReadingMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // Set backend root to /UploadFieldTest
     AssetStoreTest_SpyStore::activate('UploadFieldTest');
     // Create a test folders for each of the fixture references
     foreach (Folder::get() as $folder) {
         $path = AssetStoreTest_SpyStore::getLocalPath($folder);
         Filesystem::makeFolder($path);
     }
     // Create a test files for each of the fixture references
     $files = File::get()->exclude('ClassName', 'Folder');
     foreach ($files as $file) {
         $path = AssetStoreTest_SpyStore::getLocalPath($file);
         Filesystem::makeFolder(dirname($path));
         $fh = fopen($path, "w+");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
     }
 }
 /**
  * Example: Given the "page" "Page 1" is not published 
  * 
  * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is (?<state>[^"]*)$/
  */
 public function stepUpdateRecordState($type, $id, $state)
 {
     $class = $this->convertTypeToClass($type);
     $obj = $this->fixtureFactory->get($class, $id);
     if (!$obj) {
         throw new \InvalidArgumentException(sprintf('Can not find record "%s" with identifier "%s"', $type, $id));
     }
     switch ($state) {
         case 'published':
             $obj->publish('Stage', 'Live');
             break;
         case 'not published':
         case 'unpublished':
             $oldMode = \Versioned::get_reading_mode();
             \Versioned::reading_stage('Live');
             $clone = clone $obj;
             $clone->delete();
             \Versioned::reading_stage($oldMode);
             break;
         case 'deleted':
             $obj->delete();
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid state: "%s"', $state));
     }
 }
 /**
  * @return DataObject
  */
 static function get_version($class, $id, $version)
 {
     $oldMode = Versioned::get_reading_mode();
     Versioned::set_reading_mode('');
     $baseTable = ClassInfo::baseDataClass($class);
     $query = singleton($class)->buildVersionSQL("\"{$baseTable}\".\"RecordID\" = {$id} AND \"{$baseTable}\".\"Version\" = {$version}");
     $record = $query->execute()->record();
     $className = $record['ClassName'];
     if (!$className) {
         Debug::show($query->sql());
         Debug::show($record);
         user_error("Versioned::get_version: Couldn't get {$class}.{$id}, version {$version}", E_USER_ERROR);
     }
     Versioned::set_reading_mode($oldMode);
     return new $className($record);
 }
 public function testUnpublishedPage()
 {
     if (!class_exists('SiteTree')) {
         $this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
     }
     $orphanedPage = new SiteTree();
     $orphanedPage->ParentID = 999999;
     // missing parent id
     $orphanedPage->write();
     $orphanedPage->publish("Stage", "Live");
     $rootPage = new SiteTree();
     $rootPage->ParentID = 0;
     $rootPage->write();
     $rootPage->publish("Stage", "Live");
     $oldMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Live');
     try {
         $this->assertEmpty($orphanedPage->hasPublishedParent());
         $this->assertEmpty($orphanedPage->canIncludeInGoogleSitemap());
         $this->assertNotEmpty($rootPage->hasPublishedParent());
         $this->assertNotEmpty($rootPage->canIncludeInGoogleSitemap());
     } catch (Exception $ex) {
         Versioned::set_reading_mode($oldMode);
         throw $ex;
     }
     // finally {
     Versioned::set_reading_mode($oldMode);
     // }
 }
 public function Inspect()
 {
     return $this->entropy . ' ' . Versioned::get_reading_mode();
 }
 public function run($request)
 {
     increase_time_limit_to();
     $type = Convert::raw2sql($request->getVar('type'));
     if ($type) {
         $this->types[] = $type;
     } elseif (!$this->types) {
         foreach (ClassInfo::subclassesFor('DataObject') as $class) {
             if ($class::has_extension('SolrIndexable')) {
                 $this->types[] = $class;
             }
         }
     }
     $search = singleton('SolrSearchService');
     if (isset($_GET['delete_all'])) {
         $search->getSolr()->deleteByQuery('*:*');
         $search->getSolr()->commit();
     }
     $count = 0;
     foreach ($this->types as $type) {
         $search->getSolr()->deleteByQuery('ClassNameHierarchy_ms:' . $type);
         $search->getSolr()->commit();
         if (ClassInfo::exists('QueuedJob') && !isset($_GET['direct'])) {
             $job = new SolrReindexJob($type);
             $svc = singleton('QueuedJobService');
             $svc->queueJob($job);
             $this->log("Reindexing job for {$type} has been queued");
         } else {
             $mode = Versioned::get_reading_mode();
             Versioned::reading_stage('Stage');
             // get the holders first, see if we have any that AREN'T in the root (ie we've already partitioned everything...)
             $pages = $type::get();
             $pages = $pages->filter(array('ClassName' => $type));
             /* @var $search SolrSearchService */
             $this->log("------------------------------");
             $this->log("Start reindexing job for {$type} (Count: " . $pages->count() . "):");
             $this->log("------------------------------");
             foreach ($pages as $page) {
                 // Make sure the current page is not orphaned.
                 if ($page->ParentID > 0) {
                     $parent = $page->getParent();
                     if (is_null($parent) || $parent === false) {
                         continue;
                     }
                 }
                 // Appropriately index the current page, taking versioning into account.
                 if ($page->hasExtension('Versioned')) {
                     $search->index($page, 'Stage');
                     $baseTable = $page->baseTable();
                     $live = Versioned::get_one_by_stage($page->ClassName, 'Live', "\"{$baseTable}\".\"ID\" = {$page->ID}");
                     if ($live) {
                         $search->index($live, 'Live');
                         $this->log("Reindexed Live version of {$live->Title}");
                     }
                     $this->log("Reindexed (#{$page->ID}) {$page->Title}");
                     $count++;
                 } else {
                     $search->index($page);
                     $this->log("Reindexed {$type} ID#{$page->ID}");
                     $count++;
                 }
             }
             Versioned::set_reading_mode($mode);
         }
     }
     $this->log("------------------------------");
     $this->log("Reindex complete, {$count} objects re-indexed");
     $this->log("------------------------------");
 }
 /**
  * 
  * @return DataList
  */
 protected function getAllLivePages()
 {
     ini_set('memory_limit', '512M');
     $oldMode = Versioned::get_reading_mode();
     if (class_exists('Subsite')) {
         Subsite::disable_subsite_filter(true);
     }
     if (class_exists('Translatable')) {
         Translatable::disable_locale_filter();
     }
     Versioned::reading_stage('Live');
     $pages = DataObject::get("SiteTree");
     Versioned::set_reading_mode($oldMode);
     return $pages;
 }
Exemple #23
0
 /**
  * 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;
 }
Exemple #24
0
 function writeToStage($stage, $forceInsert = false)
 {
     $oldMode = Versioned::get_reading_mode();
     Versioned::reading_stage($stage);
     $result = $this->owner->write(false, $forceInsert);
     Versioned::set_reading_mode($oldMode);
     return $result;
 }
 /**
  * Confirm that DataObject::get_one() gets records from SiteTree_Live
  */
 function testGetOneFromLive()
 {
     $s = new SiteTree();
     $s->Title = "V1";
     $s->URLSegment = "get-one-test-page";
     $s->write();
     $s->publish("Stage", "Live");
     $s->Title = "V2";
     $s->write();
     $oldMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Live');
     $checkSiteTree = DataObject::get_one("SiteTree", "\"URLSegment\" = 'get-one-test-page'");
     $this->assertEquals("V1", $checkSiteTree->Title);
     Versioned::set_reading_mode($oldMode);
 }
 /**
  * Test that orphaned pages are handled correctly
  */
 public function testOrphanedPages()
 {
     $origStage = Versioned::get_reading_mode();
     // Setup user who can view draft content, but lacks cms permission.
     // To users such as this, orphaned pages should be inaccessible. canView for these pages is only
     // necessary for admin / cms users, who require this permission to edit / rearrange these pages.
     $permission = new Permission();
     $permission->Code = 'VIEW_DRAFT_CONTENT';
     $group = new Group(array('Title' => 'Staging Users'));
     $group->write();
     $group->Permissions()->add($permission);
     $member = new Member();
     $member->Email = '*****@*****.**';
     $member->write();
     $member->Groups()->add($group);
     // both pages are viewable in stage
     Versioned::reading_stage('Stage');
     $about = $this->objFromFixture('Page', 'about');
     $staff = $this->objFromFixture('Page', 'staff');
     $this->assertFalse($about->isOrphaned());
     $this->assertFalse($staff->isOrphaned());
     $this->assertTrue($about->canView($member));
     $this->assertTrue($staff->canView($member));
     // Publishing only the child page to live should orphan the live record, but not the staging one
     $staff->publish('Stage', 'Live');
     $this->assertFalse($staff->isOrphaned());
     $this->assertTrue($staff->canView($member));
     Versioned::reading_stage('Live');
     $staff = $this->objFromFixture('Page', 'staff');
     // Live copy of page
     $this->assertTrue($staff->isOrphaned());
     // because parent isn't published
     $this->assertFalse($staff->canView($member));
     // Publishing the parent page should restore visibility
     Versioned::reading_stage('Stage');
     $about = $this->objFromFixture('Page', 'about');
     $about->publish('Stage', 'Live');
     Versioned::reading_stage('Live');
     $staff = $this->objFromFixture('Page', 'staff');
     $this->assertFalse($staff->isOrphaned());
     $this->assertTrue($staff->canView($member));
     // Removing staging page should not prevent live page being visible
     $about->deleteFromStage('Stage');
     $staff->deleteFromStage('Stage');
     $staff = $this->objFromFixture('Page', 'staff');
     $this->assertFalse($staff->isOrphaned());
     $this->assertTrue($staff->canView($member));
     // Cleanup
     Versioned::set_reading_mode($origStage);
 }
Exemple #27
0
 /**
  * Publish this page.
  * 
  * @uses SiteTreeExtension->onBeforePublish()
  * @uses SiteTreeExtension->onAfterPublish()
  */
 public 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 extensions
     $this->invokeWithExtensions('onBeforePublish', $original);
     //$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);
     // Handle activities undertaken by extensions
     $this->invokeWithExtensions('onAfterPublish', $original);
     return true;
 }
 public function run($request)
 {
     increase_time_limit_to();
     $readingMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // Make sure that we have something to migrate.
     if (!ClassInfo::hasTable('SolrSearchPage')) {
         echo "Nothing to Migrate!";
         die;
     }
     // Retrieve the search tree relationships to migrate.
     $relationships = array();
     if (DB::getConn()->hasTable('SolrSearchPage_SearchTrees')) {
         foreach (DB::query('SELECT * FROM SolrSearchPage_SearchTrees') as $relationship) {
             $relationships[$relationship['SolrSearchPageID']] = $relationship['PageID'];
         }
     }
     // Store the current live page migration state to avoid duplicates.
     $created = array();
     // Migrate any live pages to begin with.
     $query = DB::query('SELECT * FROM SiteTree_Live st, SolrSearchPage_Live ssp WHERE st.ID = ssp.ID');
     $queryCount = $query->numRecords();
     $writeCount = 0;
     foreach ($query as $results) {
         $searchPage = ExtensibleSearchPage::create();
         $searchPage->SearchEngine = 'SolrSearch';
         // Migrate the key site tree and solr search fields across.
         $fields = array('ParentID', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'ShowInMenus', 'ShowInSearch', 'Sort', 'ResultsPerPage', 'SortBy', 'BoostFieldsValue', 'SearchOnFieldsValue', 'SearchTypeValue', 'StartWithListing', 'QueryType', 'ListingTemplateID', 'FilterFieldsValue', 'MinFacetCount', 'FacetQueriesValue', 'FacetMappingValue', 'CustomFacetFieldsValue', 'FacetFieldsValue', 'BoostMatchFieldsValue');
         foreach ($fields as $fname) {
             if (isset($results[$fname])) {
                 $searchPage->{$fname} = $results[$fname];
             }
         }
         // This field name no longer matches the original.
         if ($results['SortDir']) {
             $searchPage->SortDirection = $results['SortDir'];
         }
         if (isset($relationships[$results['ID']])) {
             $searchPage->SearchTrees()->add($relationships[$results['ID']]);
         }
         // Attempt to publish these new pages.
         $searchPage->doPublish();
         if ($searchPage->ID) {
             echo "<strong>{$results['ID']}</strong> Published<br>";
             $writeCount++;
         }
         $created[] = $results['ID'];
     }
     // Confirm that the current user had permission to publish these new pages.
     $this->checkPermissions($queryCount, $writeCount);
     // Migrate any remaining draft pages.
     $query = DB::query('SELECT * FROM SiteTree st, SolrSearchPage ssp WHERE st.ID = ssp.ID');
     $queryCount = $query->numRecords();
     $writeCount = 0;
     foreach ($query as $results) {
         // Make sure this search page doesn't already exist.
         if (!in_array($results['ID'], $created)) {
             $searchPage = ExtensibleSearchPage::create();
             $searchPage->SearchEngine = 'SolrSearch';
             // Migrate the key site tree and solr search fields across.
             $searchPage->ParentID = $results['ParentID'];
             $searchPage->URLSegment = $results['URLSegment'];
             $searchPage->Title = $results['Title'];
             $searchPage->MenuTitle = $results['MenuTitle'];
             $searchPage->Content = $results['Content'];
             $searchPage->ShowInMenus = $results['ShowInMenus'];
             $searchPage->ShowInSearch = $results['ShowInSearch'];
             $searchPage->Sort = $results['Sort'];
             $searchPage->ResultsPerPage = $results['ResultsPerPage'];
             $searchPage->SortBy = $results['SortBy'];
             $searchPage->SortDirection = $results['SortDir'];
             $searchPage->QueryType = $results['QueryType'];
             $searchPage->StartWithListing = $results['StartWithListing'];
             $searchPage->SearchTypeValue = $results['SearchTypeValue'];
             $searchPage->SearchOnFieldsValue = $results['SearchOnFieldsValue'];
             $searchPage->BoostFieldsValue = $results['BoostFieldsValue'];
             $searchPage->BoostMatchFieldsValue = $results['BoostMatchFieldsValue'];
             $searchPage->FacetFieldsValue = $results['FacetFieldsValue'];
             $searchPage->CustomFacetFieldsValue = $results['CustomFacetFieldsValue'];
             $searchPage->FacetMappingValue = $results['FacetMappingValue'];
             $searchPage->FacetQueriesValue = $results['FacetQueriesValue'];
             $searchPage->MinFacetCount = $results['MinFacetCount'];
             $searchPage->FilterFieldsValue = $results['FilterFieldsValue'];
             $searchPage->ListingTemplateID = $results['ListingTemplateID'];
             if (isset($relationships[$results['ID']])) {
                 $searchPage->SearchTrees()->add($relationships[$results['ID']]);
             }
             $searchPage->write();
             if ($searchPage->ID) {
                 echo "<strong>{$results['ID']}</strong> Saved<br>";
                 $writeCount++;
             }
         } else {
             $writeCount++;
         }
     }
     // Confirm that the current user had permission to write these new pages.
     $this->checkPermissions($queryCount, $writeCount);
     // Remove the previous search page tables, as they are now obsolete (and may not be marked as such).
     $remove = array('SiteTree', 'SiteTree_Live', 'Page', 'Page_Live');
     foreach ($remove as $table) {
         foreach ($created as $ID) {
             DB::query("DELETE FROM {$table} WHERE ID = {$ID}");
         }
     }
     $remove = array('SolrSearchPage', 'SolrSearchPage_Live', 'SolrSearchPage_SearchTrees', 'SolrSearchPage_versions');
     foreach ($remove as $table) {
         DB::query("DROP TABLE {$table}");
     }
     Versioned::set_reading_mode($readingMode);
     echo 'Migration Complete!';
 }
 /**
  * Tests that reading mode persists between requests
  */
 public function testReadingPersistent()
 {
     $session = Injector::inst()->create('Session', array());
     // Set to stage
     Director::test('/?stage=Stage', null, $session);
     $this->assertEquals('Stage.Stage', $session->inst_get('readingMode'), 'Check querystring changes reading mode to Stage');
     Director::test('/', null, $session);
     $this->assertEquals('Stage.Stage', $session->inst_get('readingMode'), 'Check that subsequent requests in the same session remain in Stage mode');
     // Test live persists
     Director::test('/?stage=Live', null, $session);
     $this->assertEquals('Stage.Live', $session->inst_get('readingMode'), 'Check querystring changes reading mode to Live');
     Director::test('/', null, $session);
     $this->assertEquals('Stage.Live', $session->inst_get('readingMode'), 'Check that subsequent requests in the same session remain in Live mode');
     // Test that session doesn't redundantly store the default stage if it doesn't need to
     $session2 = Injector::inst()->create('Session', array());
     Director::test('/', null, $session2);
     $this->assertEmpty($session2->inst_changedData());
     Director::test('/?stage=Live', null, $session2);
     $this->assertEmpty($session2->inst_changedData());
     // Test choose_site_stage
     Session::set('readingMode', 'Stage.Stage');
     Versioned::choose_site_stage();
     $this->assertEquals('Stage.Stage', Versioned::get_reading_mode());
     Session::set('readingMode', 'Archive.2014-01-01');
     Versioned::choose_site_stage();
     $this->assertEquals('Archive.2014-01-01', Versioned::get_reading_mode());
     Session::clear('readingMode');
     Versioned::choose_site_stage();
     $this->assertEquals('Stage.Live', Versioned::get_reading_mode());
 }
 /**
  * Returns if this is Document is embargoed or expired.
  * Also, returns if the document should be displayed on the front-end. Respecting the current reading mode
  * of the site and the embargo status.
  * I.e. if a document is embargoed until published, then it should still show up in draft mode.
  * @return bool True or False depending on whether this document is embargoed
  */
 function isHidden()
 {
     $hidden = $this->isEmbargoed() || $this->isExpired();
     $readingMode = Versioned::get_reading_mode();
     if ($readingMode == "Stage.Stage" && $this->EmbargoedUntilPublished == true) {
         $hidden = false;
     }
     return $hidden;
 }