当前位置: 首页>>代码示例>>PHP>>正文


PHP Versioned::set_reading_mode方法代码示例

本文整理汇总了PHP中Versioned::set_reading_mode方法的典型用法代码示例。如果您正苦于以下问题:PHP Versioned::set_reading_mode方法的具体用法?PHP Versioned::set_reading_mode怎么用?PHP Versioned::set_reading_mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Versioned的用法示例。


在下文中一共展示了Versioned::set_reading_mode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: requireDefaultRecords

 /**
  *	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);
 }
开发者ID:nglasl,项目名称:silverstripe-extensible-search,代码行数:35,代码来源:ExtensibleSearchPage.php

示例2: run

 /**
  * 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;
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:35,代码来源:FileMigrationHelper.php

示例3: tearDown

 public function tearDown()
 {
     AssetStoreTest_SpyStore::reset();
     if ($this->oldReadingMode) {
         Versioned::set_reading_mode($this->oldReadingMode);
     }
     parent::tearDown();
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:8,代码来源:UploadFieldTest.php

示例4: provideGridSheetData

 public function provideGridSheetData($modelClass)
 {
     if (self::ModelClass == $modelClass) {
         $mode = static::own_config('products_reading_mode');
         Versioned::set_reading_mode($mode);
         $products = Product::get();
         return $products;
     }
 }
开发者ID:swipestreak,项目名称:swipestreak,代码行数:9,代码来源:Product.php

示例5: sourceRecords

 /**
  * 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());
     }
 }
开发者ID:silverstripe,项目名称:sitewidecontent-report,代码行数:18,代码来源:SitewideContentReport.php

示例6: getAllLivePages

 /**
  * 
  * @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;
 }
开发者ID:helpfulrobot,项目名称:adrexia-staticsearch,代码行数:19,代码来源:BuildStaticSearchIndexTask.php

示例7: preview

 /**
  * @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();
     }
 }
开发者ID:muskie9,项目名称:silverstripe-sharedraftcontent,代码行数:49,代码来源:ShareDraftController.php

示例8: doSavePost

 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());
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-blog-frontend,代码行数:20,代码来源:BlogFrontEndForm_BlogController.php

示例9: updateTagging

 /**
  *	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);
         }
     }
 }
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-fusion,代码行数:42,代码来源:FusionService.php

示例10: get_version

 /**
  * @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);
 }
开发者ID:comperio,项目名称:silverstripe-framework,代码行数:19,代码来源:Versioned.php

示例11: requireDefaultRecords

 /**
  * Build the database with default records, see {@link DataObject->requireDefaultRecords()}.
  */
 public function requireDefaultRecords()
 {
     $dbAdmin = new DatabaseAdmin();
     Versioned::set_reading_mode('');
     $dbAdmin->doBuild(true, true);
 }
开发者ID:jeffreyguo,项目名称:silverstripe-testsession,代码行数:9,代码来源:TestSessionEnvironment.php

示例12: run

 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("------------------------------");
 }
开发者ID:nyeholt,项目名称:silverstripe-solr,代码行数:69,代码来源:SolrReindexTask.php

示例13: doPublish

 /**
  * 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;
 }
开发者ID:eLBirador,项目名称:AllAboutCity,代码行数:62,代码来源:SiteTree.php

示例14: testArchiveVersion

 public function testArchiveVersion()
 {
     // In 2005 this file was created
     SS_Datetime::set_mock_now('2005-01-01 00:00:00');
     $testPage = new VersionedTest_Subclass();
     $testPage->Title = 'Archived page';
     $testPage->Content = 'This is the content from 2005';
     $testPage->ExtraField = '2005';
     $testPage->write();
     // In 2007 we updated it
     SS_Datetime::set_mock_now('2007-01-01 00:00:00');
     $testPage->Content = "It's 2007 already!";
     $testPage->ExtraField = '2007';
     $testPage->write();
     // In 2009 we updated it again
     SS_Datetime::set_mock_now('2009-01-01 00:00:00');
     $testPage->Content = "I'm enjoying 2009";
     $testPage->ExtraField = '2009';
     $testPage->write();
     // End mock, back to the present day:)
     SS_Datetime::clear_mock_now();
     // Test 1 - 2006 Content
     singleton('VersionedTest_Subclass')->flushCache(true);
     Versioned::set_reading_mode('Archive.2006-01-01 00:00:00');
     $testPage2006 = DataObject::get('VersionedTest_Subclass')->filter(array('Title' => 'Archived page'))->first();
     $this->assertInstanceOf("VersionedTest_Subclass", $testPage2006);
     $this->assertEquals("2005", $testPage2006->ExtraField);
     $this->assertEquals("This is the content from 2005", $testPage2006->Content);
     // Test 2 - 2008 Content
     singleton('VersionedTest_Subclass')->flushCache(true);
     Versioned::set_reading_mode('Archive.2008-01-01 00:00:00');
     $testPage2008 = DataObject::get('VersionedTest_Subclass')->filter(array('Title' => 'Archived page'))->first();
     $this->assertInstanceOf("VersionedTest_Subclass", $testPage2008);
     $this->assertEquals("2007", $testPage2008->ExtraField);
     $this->assertEquals("It's 2007 already!", $testPage2008->Content);
     // Test 3 - Today
     singleton('VersionedTest_Subclass')->flushCache(true);
     Versioned::set_reading_mode('Stage.Stage');
     $testPageCurrent = DataObject::get('VersionedTest_Subclass')->filter(array('Title' => 'Archived page'))->first();
     $this->assertInstanceOf("VersionedTest_Subclass", $testPageCurrent);
     $this->assertEquals("2009", $testPageCurrent->ExtraField);
     $this->assertEquals("I'm enjoying 2009", $testPageCurrent->Content);
 }
开发者ID:normann,项目名称:sapphire,代码行数:43,代码来源:VersionedTest.php

示例15: getAllLivePages

 /**
  * 
  * @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;
 }
开发者ID:spark-green,项目名称:silverstripe-staticpublishqueue,代码行数:19,代码来源:SiteTreeFullBuildEngine.php


注:本文中的Versioned::set_reading_mode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。