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


PHP Versioned类代码示例

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


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

示例1: onBeforeInit

 public function onBeforeInit()
 {
     // Determine if this page is of a non-cacheable type
     $ignoredClasses = DynamicCache::config()->ignoredPages;
     $ignoredByClass = false;
     if ($ignoredClasses) {
         foreach ($ignoredClasses as $ignoredClass) {
             if (is_a($this->owner->data(), $ignoredClass, true)) {
                 $ignoredByClass = true;
                 break;
             }
         }
     }
     $isStage = ($stage = Versioned::current_stage()) && $stage !== 'Live';
     // Set header disabling caching if
     // - current page is an ignored page type
     // - current_stage is not live
     if ($ignoredByClass || $isStage) {
         $header = DynamicCache::config()->optOutHeaderString;
         header($header);
     }
     // Flush cache if requested
     if (isset($_GET['flush']) || isset($_GET['cache']) && $_GET['cache'] === 'flush' && Permission::check('ADMIN')) {
         DynamicCache::inst()->clear();
     }
 }
开发者ID:chillu,项目名称:silverstripe-dynamiccache,代码行数:26,代码来源:DynamicCacheControllerExtension.php

示例2: republish

 function republish($original)
 {
     if (self::$disable_realtime) {
         return;
     }
     $urls = array();
     if ($this->owner->hasMethod('pagesAffectedByChanges')) {
         $urls = $this->owner->pagesAffectedByChanges($original);
     } else {
         $pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10);
         if ($pages) {
             foreach ($pages as $page) {
                 $urls[] = $page->AbsoluteLink();
             }
         }
     }
     // Note: Similiar to RebuildStaticCacheTask->rebuildCache()
     foreach ($urls as $i => $url) {
         if (!is_string($url)) {
             user_error("Bad URL: " . var_export($url, true), E_USER_WARNING);
             continue;
         }
         // Remove leading slashes from all URLs (apart from the homepage)
         if (substr($url, -1) == '/' && $url != '/') {
             $url = substr($url, 0, -1);
         }
         $urls[$i] = $url;
     }
     $urls = array_unique($urls);
     $this->publishPages($urls);
 }
开发者ID:rixrix,项目名称:silverstripe-cms,代码行数:31,代码来源:StaticPublisher.php

示例3: Dates

 function Dates()
 {
     Requirements::themedCSS('archivewidget');
     $results = new DataObjectSet();
     $container = BlogTree::current();
     $ids = $container->BlogHolderIDs();
     $stage = Versioned::current_stage();
     $suffix = !$stage || $stage == 'Stage' ? "" : "_{$stage}";
     $monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")';
     $yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")';
     if ($this->DisplayMode == 'month') {
         $sqlResults = DB::query("\n\t\t\t\tSELECT DISTINCT CAST({$monthclause} AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", {$yearclause} AS \"Year\"\n\t\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\t\tORDER BY \"Year\" DESC, \"Month\" DESC;");
     } else {
         $sqlResults = DB::query("\n\t\t\t\tSELECT DISTINCT {$yearclause} AS \"Year\" \n\t\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\t\tORDER BY \"Year\" DESC");
     }
     if ($sqlResults) {
         foreach ($sqlResults as $sqlResult) {
             $isMonthDisplay = $this->DisplayMode == 'month';
             $monthVal = isset($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1;
             $month = $isMonthDisplay ? $monthVal : 1;
             $year = $sqlResult['Year'] ? (int) $sqlResult['Year'] : date('Y');
             $date = DBField::create('Date', array('Day' => 1, 'Month' => $month, 'Year' => $year));
             if ($isMonthDisplay) {
                 $link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal);
             } else {
                 $link = $container->Link('date') . '/' . $sqlResult['Year'];
             }
             $results->push(new ArrayData(array('Date' => $date, 'Link' => $link)));
         }
     }
     return $results;
 }
开发者ID:nicmart,项目名称:comperio-site,代码行数:32,代码来源:ArchiveWidget.php

示例4: testHasOnes

 public function testHasOnes()
 {
     $obj1 = $this->objFromFixture('DataDifferencerTest_Object', 'obj1');
     $image1 = $this->objFromFixture('DataDifferencerTest_MockImage', 'image1');
     $image2 = $this->objFromFixture('DataDifferencerTest_MockImage', 'image2');
     $relobj1 = $this->objFromFixture('DataDifferencerTest_HasOneRelationObject', 'relobj1');
     $relobj2 = $this->objFromFixture('DataDifferencerTest_HasOneRelationObject', 'relobj2');
     // in order to ensure the Filename path is correct, append the correct FRAMEWORK_DIR to the start
     // this is only really necessary to make the test pass when FRAMEWORK_DIR is not "framework"
     $image1->Filename = FRAMEWORK_DIR . substr($image1->Filename, 9);
     $image2->Filename = FRAMEWORK_DIR . substr($image2->Filename, 9);
     $origUpdateFilesystem = Config::inst()->get('File', 'update_filesystem');
     // we don't want the filesystem being updated on write, as we're only dealing with mock files
     Config::inst()->update('File', 'update_filesystem', false);
     $image1->write();
     $image2->write();
     Config::inst()->update('File', 'update_filesystem', $origUpdateFilesystem);
     // create a new version
     $obj1->ImageID = $image2->ID;
     $obj1->HasOneRelationID = $relobj2->ID;
     $obj1->write();
     $obj1v1 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, $obj1->Version - 1);
     $obj1v2 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, $obj1->Version);
     $differ = new DataDifferencer($obj1v1, $obj1v2);
     $obj1Diff = $differ->diffedData();
     $this->assertContains($image1->Filename, $obj1Diff->getField('Image'));
     $this->assertContains($image2->Filename, $obj1Diff->getField('Image'));
     $this->assertContains('<ins>obj2</ins><del>obj1</del>', str_replace(' ', '', $obj1Diff->getField('HasOneRelationID')));
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:29,代码来源:DataDifferencerTest.php

示例5: multipleNewsHolderPages

 /**
  * If there are multiple @link NewsHolderPage available, add the field for multiples.
  * This includes translation options
  */
 private function multipleNewsHolderPages()
 {
     $enabled = false;
     // If we have translations, disable translation filter to get all pages.
     if (class_exists('Translatable')) {
         $enabled = Translatable::disable_locale_filter();
     }
     $pages = Versioned::get_by_stage('NewsHolderPage', 'Live');
     // Only add the page-selection if there are multiple. Otherwise handled by onBeforeWrite();
     if ($pages->count() > 1) {
         $pagelist = array();
         if (class_exists('Translatable')) {
             foreach ($pages as $page) {
                 $pagelist['Root.Main'][$page->ID] = $page->Title . ' ' . $page->Locale;
             }
         } else {
             $pagelist = $pages->map('ID', 'Title')->toArray();
         }
         $this->field_list['Root.Main'][1] = ListboxField::create('NewsHolderPages', $this->owner->fieldLabel('NewsHolderPages'), $pagelist);
         $this->field_list['Root.Main'][1]->setMultiple(true);
     }
     if ($enabled) {
         Translatable::enable_locale_filter();
     }
 }
开发者ID:MilesSummers,项目名称:silverstripe-newsmodule,代码行数:29,代码来源:NewsCMSExtension.php

示例6: 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

示例7: handleRequest

	function handleRequest(SS_HTTPRequest $request, DataModel $model) {
		$this->setModel($model);
		Versioned::reading_stage('Live');
		$restfulserver = new RestfulServer();
		$response = $restfulserver->handleRequest($request, $model);
		return $response;
	}
开发者ID:redema,项目名称:sapphire,代码行数:7,代码来源:VersionedRestfulServer.php

示例8: onAfterWrite

 public function onAfterWrite()
 {
     parent::onAfterWrite();
     if (in_array('Searchable', class_implements($this->owner->class))) {
         if ($this->owner->IncludeInSearch()) {
             if ($this->owner->hasExtension('Versioned')) {
                 $filterID = array('ID' => $this->owner->ID);
                 $filter = $filterID + $this->owner->getSearchFilter();
                 $do = Versioned::get_by_stage($this->owner->class, 'Live')->filter($filter)->first();
             } else {
                 $filterID = "`{$this->owner->class}`.`ID`={$this->owner->ID}";
                 $do = DataObject::get($this->owner->class, $filterID, false)->filter($this->owner->getSearchFilter())->first();
             }
             if ($do) {
                 PopulateSearch::insert($do);
             } else {
                 $this->deleteDo($this->owner);
             }
         } else {
             $this->deleteDo($this->owner);
         }
     } else {
         if ($this->owner instanceof SiteTree) {
             if ($this->owner->ShowInSearch) {
                 PopulateSearch::insertPage($this->owner);
             } else {
                 $this->deleteDo($this->owner);
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:zirak-searchable-dataobjects,代码行数:31,代码来源:SearchableDataObject.php

示例9: getOwnerPage

 /**
  * Return an ArrayList of pages with the Element Page Extension
  *
  * @return ArrayList
  */
 public function getOwnerPage()
 {
     $originalMode = Versioned::current_stage();
     Versioned::reading_stage('Stage');
     foreach (get_declared_classes() as $class) {
         if (is_subclass_of($class, 'SiteTree')) {
             $object = singleton($class);
             $classes = ClassInfo::subclassesFor('ElementPageExtension');
             $isElemental = false;
             foreach ($classes as $extension) {
                 if ($object->hasExtension($extension)) {
                     $isElemental = true;
                 }
             }
             if ($isElemental) {
                 $page = $class::get()->filter('ElementAreaID', $this->ID);
                 if ($page && $page->exists()) {
                     Versioned::reading_stage($originalMode);
                     return $page->first();
                 }
             }
         }
     }
     Versioned::reading_stage($originalMode);
     return false;
 }
开发者ID:dnadesign,项目名称:silverstripe-elemental,代码行数:31,代码来源:ElementalArea.php

示例10: get_navbar_html

 public static function get_navbar_html($page = null)
 {
     // remove the protocol from the URL, otherwise we run into https/http issues
     $url = self::remove_protocol_from_url(self::get_toolbar_hostname());
     $static = true;
     if (!$page instanceof SiteTree) {
         $page = Director::get_current_page();
         $static = false;
     }
     // In some cases, controllers are bound to "mock" pages, like Security. In that case,
     // throw the "default section" as the current controller.
     if (!$page instanceof SiteTree || !$page->isInDB()) {
         $controller = ModelAsController::controller_for($page = SiteTree::get_by_link(Config::inst()->get('GlobalNav', 'default_section')));
     } else {
         // Use controller_for to negotiate sub controllers, e.g. /showcase/listing/slug
         // (Controller::curr() would return the nested RequestHandler)
         $controller = ModelAsController::controller_for($page);
     }
     // Ensure staging links are not exported to the nav
     $origStage = Versioned::current_stage();
     Versioned::reading_stage('Live');
     $html = ViewableData::create()->customise(array('ToolbarHostname' => $url, 'Scope' => $controller, 'ActivePage' => $page, 'ActiveParent' => $page instanceof SiteTree && $page->Parent()->exists() ? $page->Parent() : $page, 'StaticRender' => $static, 'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')))->renderWith('GlobalNavbar');
     Versioned::reading_stage($origStage);
     return $html;
 }
开发者ID:newleeland,项目名称:silverstripe-globaltoolbar,代码行数:25,代码来源:GlobalNavSiteTreeExtension.php

示例11: createreport

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

示例12: augmentSQL

 /**
  * Augment queries so that we don't fetch unpublished articles.
  **/
 public function augmentSQL(SQLQuery &$query)
 {
     $stage = Versioned::current_stage();
     if ($stage == 'Live' || !Permission::check("VIEW_DRAFT_CONTENT")) {
         $query->addWhere("PublishDate < '" . Convert::raw2sql(SS_Datetime::now()) . "'");
     }
 }
开发者ID:helpfulrobot,项目名称:micmania1-silverstripe-blog,代码行数:10,代码来源:BlogPostFilter.php

示例13: ConvertObjectForm

 /**
  * Form used for defining the conversion form
  * @return {Form} Form to be used for configuring the conversion
  */
 public function ConvertObjectForm()
 {
     //Reset the reading stage
     Versioned::reset();
     $fields = new FieldList(CompositeField::create($convertModeField = new OptionsetField('ConvertMode', '', array('ReplacePage' => _t('KapostAdmin.REPLACES_AN_EXISTING_PAGE', '_This replaces an existing page'), 'NewPage' => _t('KapostAdmin.IS_NEW_PAGE', '_This is a new page')), 'NewPage'))->addExtraClass('kapostConvertLeftSide'), CompositeField::create($replacePageField = TreeDropdownField::create('ReplacePageID', _t('KapostAdmin.REPLACE_PAGE', '_Replace this page'), 'SiteTree')->addExtraClass('replace-page-id'), TreeDropdownField::create('ParentPageID', _t('KapostAdmin.USE_AS_PARENT', '_Use this page as the parent for the new page, leave empty for a top level page'), 'SiteTree')->addExtraClass('parent-page-id'))->addExtraClass('kapostConvertRightSide'));
     $actions = new FieldList(FormAction::create('doConvertObject', _t('KapostAdmin.CONTINUE_CONVERT', '_Continue'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'kapost-convert'));
     $validator = new RequiredFields('ConvertMode');
     $form = new Form($this, 'ConvertObjectForm', $fields, $actions, $validator);
     $form->addExtraClass('KapostAdmin center')->setAttribute('data-layout-type', 'border')->setTemplate('KapostAdmin_ConvertForm');
     //Handle pages to see if the page exists
     $convertToClass = $this->getDestinationClass();
     if ($convertToClass !== false && ($convertToClass == 'SiteTree' || is_subclass_of($convertToClass, 'SiteTree'))) {
         $obj = SiteTree::get()->filter('KapostRefID', Convert::raw2sql($this->record->KapostRefID))->first();
         if (!empty($obj) && $obj !== false && $obj->ID > 0) {
             $convertModeField->setValue('ReplacePage');
             $replacePageField->setValue($obj->ID);
             $recordTitle = $this->record->Title;
             if (!empty($recordTitle) && $recordTitle != $obj->Title) {
                 $urlFieldLabel = _t('KapostAdmin.TITLE_CHANGE_DETECT', '_The title differs from the page being replaced, it was "{wastitle}" and will be changed to "{newtitle}". Do you want to update the URL Segment?', array('wastitle' => $obj->Title, 'newtitle' => $recordTitle));
                 $fields->push(CheckboxField::create('UpdateURLSegment', $urlFieldLabel)->addExtraClass('urlsegmentcheck')->setAttribute('data-replace-id', $obj->ID)->setForm($form)->setDescription(_t('KapostAdmin.NEW_URL_SEGMENT', '_The new URL Segment will be or will be close to "{newsegment}"', array('newsegment' => $obj->generateURLSegment($recordTitle)))));
             }
         }
     }
     Requirements::css(KAPOST_DIR . '/css/KapostAdmin.css');
     Requirements::add_i18n_javascript(KAPOST_DIR . '/javascript/lang/');
     Requirements::javascript(KAPOST_DIR . '/javascript/KapostAdmin_convertPopup.js');
     //Allow extensions to adjust the form
     $this->extend('updateConvertObjectForm', $form, $this->record);
     return $form;
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-kapost-bridge,代码行数:34,代码来源:KapostGridFieldDetailForm_ItemRequest.php

示例14: BlogTags

    public function BlogTags()
    {
        if ($newsIndex = $this->NewsIndex()) {
            $alRet = new ArrayList();
            $arrTags = array();
            $strTable = Versioned::current_stage() == 'Stage' ? 'NewsPost' : 'NewsPost_Live';
            $results = DB::query('SELECT `Tags` AS Tags, COUNT(1) AS Items
				FROM ' . $strTable . '
				WHERE `Tags` IS NOT NULL
				GROUP BY Tags');
            while ($row = $results->nextRecord()) {
                $arrCurrentItems = explode(',', $row['Tags']);
                foreach ($arrCurrentItems as $strItem) {
                    $strItem = trim($strItem);
                    $strLower = strtolower($strItem);
                    if (!array_key_exists($strLower, $arrTags)) {
                        $arrTags[$strLower] = new ArrayData(array('Tag' => $strItem, 'Count' => $row['Items'], 'Link' => $newsIndex->Link('tag/' . urlencode($strItem))));
                    } else {
                        $arrayData = $arrTags[$strLower];
                        $arrayData->Count += $row['Items'];
                    }
                }
            }
            foreach ($arrTags as $arrTag) {
                $alRet->push($arrTag);
            }
            return $alRet->sort('Count')->limit(SiteConfig::current_site_config()->NumberOfTags ?: PHP_INT_MAX);
        }
    }
开发者ID:silverstripers,项目名称:silverstripe-news,代码行数:29,代码来源:NewsPageExtension.php

示例15: 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


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