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


PHP Versioned::get_latest_version方法代码示例

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


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

示例1: Form

 public function Form()
 {
     $fields = new FieldList();
     $source = array();
     $fields->push(new HeaderField('Header', _t('RemoveOrphanedPagesTask.HEADER', 'Remove all orphaned pages task')));
     $fields->push(new LiteralField('Description', $this->description));
     $orphans = $this->getOrphanedPages($this->orphanedSearchClass);
     if ($orphans) {
         foreach ($orphans as $orphan) {
             $latestVersion = Versioned::get_latest_version($this->orphanedSearchClass, $orphan->ID);
             $latestAuthor = DataObject::get_by_id('Member', $latestVersion->AuthorID);
             $stageRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Stage', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID));
             $liveRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Live', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID));
             $label = sprintf('<a href="admin/pages/edit/show/%d">%s</a> <small>(#%d, Last Modified Date: %s, Last Modifier: %s, %s)</small>', $orphan->ID, $orphan->Title, $orphan->ID, Date::create($orphan->LastEdited)->Nice(), $latestAuthor ? $latestAuthor->Title : 'unknown', $liveRecord ? 'is published' : 'not published');
             $source[$orphan->ID] = $label;
         }
     }
     if ($orphans && $orphans->Count()) {
         $fields->push(new CheckboxSetField('OrphanIDs', false, $source));
         $fields->push(new LiteralField('SelectAllLiteral', sprintf('<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a>&nbsp;', _t('RemoveOrphanedPagesTask.SELECTALL', 'select all'))));
         $fields->push(new LiteralField('UnselectAllLiteral', sprintf('<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>', _t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all'))));
         $fields->push(new OptionSetField('OrphanOperation', _t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'), array('rebase' => _t('RemoveOrphanedPagesTask.OPERATION_REBASE', sprintf('Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.', $this->rebaseHolderTitle())), 'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)')), 'rebase'));
         $fields->push(new LiteralField('Warning', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.DELETEWARNING', 'Warning: These operations are not reversible. Please handle with care.'))));
     } else {
         $fields->push(new LiteralField('NotFoundLabel', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.NONEFOUND', 'No orphans found'))));
     }
     $form = new Form($this, 'Form', $fields, new FieldList(new FormAction('doSubmit', _t('RemoveOrphanedPagesTask.BUTTONRUN', 'Run'))));
     if (!$orphans || !$orphans->Count()) {
         $form->makeReadonly();
     }
     return $form;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:32,代码来源:RemoveOrphanedPagesTask.php

示例2: link_shortcode_handler

 /**
  * Modify the content to include subsite links
  * @global array $subsiteDomainIDs
  * @param array $arguments
  * @param string $content
  * @param type $parser
  * @return string links
  */
 public static function link_shortcode_handler($arguments, $content = null, $parser = null)
 {
     if (!isset($arguments['id'])) {
         return;
     }
     $argumentarray = explode('-', $arguments['id']);
     if (count($argumentarray) != 2) {
         return;
     }
     $subsiteid = $argumentarray[0];
     $id = $argumentarray[1];
     $page = null;
     if ($id) {
         $page = DataObject::get_by_id('SiteTree', $id);
         // Get the current page by ID.
         if (!$page) {
             $page = Versioned::get_latest_version('SiteTree', $id);
             // Attempt link to old version.
         }
     } else {
         $page = DataObject::get_one('ErrorPage', '"ErrorPage"."ErrorCode" = \'404\'');
         // Link to 404 page.
     }
     if (!$page) {
         return;
         // There were no suitable matches at all.
     }
     $currentSubsite = Subsite::get()->byID((int) $subsiteid);
     $currenturl = null;
     if ($currentSubsite) {
         if (Director::isDev()) {
             $currenturl = $currentSubsite->DevDomainID ? $currentSubsite->DevDomain() : null;
         }
         if (Director::isTest()) {
             $currenturl = $currentSubsite->TestDomainID ? $currentSubsite->TestDomain() : null;
         }
         if (!$currenturl) {
             $currenturl = $currentSubsite->getPrimarySubsiteDomain();
         }
         $currenturl = $currenturl->getFullProtocol() . $currenturl->Domain;
         // override
         if (Director::isDev() || Director::isTest()) {
             if (defined('DEV_SUBSITE_' . (int) $subsiteid)) {
                 $subsiteurl = 'DEV_SUBSITE_' . (int) $subsiteid;
                 $currenturl = constant($subsiteurl);
             }
         }
     }
     $link = Convert::raw2att($page->Link());
     if ($content) {
         return sprintf('<a href="%s">%s</a>', $currenturl . $link, $parser->parse($content));
     } else {
         return $currenturl . $link;
     }
 }
开发者ID:otago,项目名称:subsites-domains,代码行数:63,代码来源:HtmlEditorField_ToolbarExtension.php

示例3: testCanEditOnPageDeletedFromStageAndLiveReturnsFalse

 function testCanEditOnPageDeletedFromStageAndLiveReturnsFalse()
 {
     // Find a page that exists and delete it from both stage and published
     $this->logInWithPermission("ADMIN");
     $page = $this->objFromFixture('Page', 'restrictedEditOnlySubadminGroup');
     $pageID = $page->ID;
     $page->doUnpublish();
     $page->delete();
     // We'll need to resurrect the page from the version cache to test this case
     $page = Versioned::get_latest_version('SiteTree', $pageID);
     // subadmin had edit rights on that page, but now it's gone
     $member = $this->objFromFixture('Member', 'subadmin');
     $member->logIn();
     $this->assertFalse($page->canEdit());
 }
开发者ID:Raiser,项目名称:Praktikum,代码行数:15,代码来源:SiteTreePermissionsTest.php

示例4: handleItem

 public function handleItem($gridField, $request)
 {
     $controller = $gridField->getForm()->Controller();
     if (is_numeric($request->param('ID')) && is_numeric($request->param('Version'))) {
         $record = Versioned::get_version($gridField->getModelClass(), $request->param('ID'), $request->param('Version'));
     } elseif (is_numeric($request->param('ID'))) {
         $record = Versioned::get_latest_version($gridField->getModelClass(), $request->param('ID'));
     } else {
         $record = Object::create($gridField->getModelClass());
     }
     $class = $this->getItemRequestClass();
     $handler = Object::create($class, $gridField, $this, $record, $controller, $this->name);
     $handler->setTemplate($this->template);
     return $handler->handleRequest($request, DataModel::inst());
 }
开发者ID:helpfulrobot,项目名称:studiobonito-silverstripe-publishable,代码行数:15,代码来源:PublishableGridFieldDetailForm.php

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

示例6: restore

 /**
  * Restore a completely deleted page from the SiteTree_versions table.
  */
 function restore($data, $form)
 {
     if (!isset($data['ID']) || !is_numeric($data['ID'])) {
         return new SS_HTTPResponse("Please pass an ID in the form content", 400);
     }
     $id = (int) $data['ID'];
     $restoredPage = Versioned::get_latest_version("SiteTree", $id);
     if (!$restoredPage) {
         return new SS_HTTPResponse("SiteTree #{$id} not found", 400);
     }
     $restoredPage = $restoredPage->doRestoreToStage();
     $this->response->addHeader('X-Status', sprintf(_t('CMSMain.RESTORED', "Restored '%s' successfully", PR_MEDIUM, 'Param %s is a title'), $restoredPage->TreeTitle));
     $form = $this->getEditForm($id);
     return $form->formHtmlContent();
 }
开发者ID:rodneyway,项目名称:silverstripe-cms,代码行数:18,代码来源:CMSMain.php

示例7: isParentArchived

 /**
  * Determine if this page references a parent which is archived, and not available in stage
  *
  * @return bool True if there is an archived parent
  */
 protected function isParentArchived()
 {
     if ($parentID = $this->ParentID) {
         $parentPage = Versioned::get_latest_version("SiteTree", $parentID);
         if (!$parentPage || $parentPage->IsDeletedFromStage) {
             return true;
         }
     }
     return false;
 }
开发者ID:riddler7,项目名称:silverstripe-cms,代码行数:15,代码来源:SiteTree.php

示例8: testLazyLoadedFieldsOnVersionedRecords

 public function testLazyLoadedFieldsOnVersionedRecords()
 {
     // Save another record, sanity check that we're getting the right one
     $obj2 = new VersionedTest_Subclass();
     $obj2->Name = "test2";
     $obj2->ExtraField = "foo2";
     $obj2->write();
     // Save the actual inspected record
     $obj1 = new VersionedTest_Subclass();
     $obj1->Name = "test";
     $obj1->ExtraField = "foo";
     $obj1->write();
     $version1 = $obj1->Version;
     $obj1->Name = "test2";
     $obj1->ExtraField = "baz";
     $obj1->write();
     $version2 = $obj1->Version;
     $reloaded = Versioned::get_version('VersionedTest_Subclass', $obj1->ID, $version1);
     $this->assertEquals($reloaded->Name, 'test');
     $this->assertEquals($reloaded->ExtraField, 'foo');
     $reloaded = Versioned::get_version('VersionedTest_Subclass', $obj1->ID, $version2);
     $this->assertEquals($reloaded->Name, 'test2');
     $this->assertEquals($reloaded->ExtraField, 'baz');
     $reloaded = Versioned::get_latest_version('VersionedTest_Subclass', $obj1->ID);
     $this->assertEquals($reloaded->Version, $version2);
     $this->assertEquals($reloaded->Name, 'test2');
     $this->assertEquals($reloaded->ExtraField, 'baz');
     $allVersions = Versioned::get_all_versions('VersionedTest_Subclass', $obj1->ID);
     $this->assertEquals(2, $allVersions->Count());
     $this->assertEquals($allVersions->First()->Version, $version1);
     $this->assertEquals($allVersions->First()->Name, 'test');
     $this->assertEquals($allVersions->First()->ExtraField, 'foo');
     $this->assertEquals($allVersions->Last()->Version, $version2);
     $this->assertEquals($allVersions->Last()->Name, 'test2');
     $this->assertEquals($allVersions->Last()->ExtraField, 'baz');
     $obj1->delete();
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:37,代码来源:DataObjectLazyLoadingTest.php

示例9: link_shortcode_handler

 /**
  * Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID.
  *
  * @return string
  */
 public static function link_shortcode_handler($arguments, $content = null, $parser = null)
 {
     if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
         return;
     }
     if (!($page = DataObject::get_by_id('SiteTree', $arguments['id'])) && !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) && !($page = DataObject::get_one('ErrorPage', '"ErrorCode" = \'404\''))) {
         return;
         // There were no suitable matches at all.
     }
     if ($content) {
         return sprintf('<a href="%s">%s</a>', $page->Link(), $parser->parse($content));
     } else {
         return $page->Link();
     }
 }
开发者ID:eLBirador,项目名称:AllAboutCity,代码行数:20,代码来源:SiteTree.php

示例10: getRecord

 /**
  * Return a dataobject based on the `id` and `tree_class`.
  *
  * @param  int $id
  * @return DataObject
  */
 public function getRecord($id)
 {
     $treeClass = $this->stat('tree_class');
     $record = DataObject::get_one($treeClass, "\"{$treeClass}\".\"ID\" = {$id}");
     // Then, try getting a record from the live site
     if (!$record) {
         Versioned::reading_stage('Live');
         singleton($treeClass)->flushCache();
         $record = DataObject::get_one($treeClass, "\"{$treeClass}\".\"ID\" = {$id}");
         if ($record) {
             Versioned::set_reading_mode('');
         }
     }
     // Then, try getting a deleted record
     if (!$record) {
         $record = Versioned::get_latest_version($treeClass, $id);
     }
     return $record;
 }
开发者ID:silverstripe-supervillains,项目名称:silverstripe-origami,代码行数:25,代码来源:OrigamiApi.php

示例11: restorepage

 function restorepage()
 {
     if ($id = $this->urlParams['ID']) {
         $restoredPage = Versioned::get_latest_version("SiteTree", $id);
         $restoredPage->ID = $restoredPage->RecordID;
         if (!DB::query("SELECT ID FROM SiteTree WHERE ID = {$restoredPage->ID}")->value()) {
             DB::query("INSERT INTO SiteTree SET ID = {$restoredPage->ID}");
         }
         $restoredPage->forceChange();
         $restoredPage->writeWithoutVersion();
         Debug::show($restoredPage);
     } else {
         echo _t('CMSMain.VISITRESTORE', "visit restorepage/(ID)", PR_LOW, 'restorepage/(ID) should not be translated (is an URL)');
     }
 }
开发者ID:ramziammar,项目名称:websites,代码行数:15,代码来源:CMSMain.php

示例12: getUnusedThumbnails

 /**
  * Creates array containg all unused thumbnails.
  * 
  * Array is created in three steps:
  *     1. Scan assets folder and retrieve all thumbnails
  *     2. Scan all HTMLField in system and retrieve thumbnails from them.
  *     3. Count difference between two sets (array_diff)
  *
  * @return array 
  */
 private function getUnusedThumbnails()
 {
     $allThumbnails = array();
     $usedThumbnails = array();
     $dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ASSETS_PATH));
     $classes = ClassInfo::subclassesFor('SiteTree');
     if ($dirIterator) {
         foreach ($dirIterator as $file) {
             if ($file->isFile()) {
                 if (strpos($file->getPathname(), '_resampled') !== false) {
                     $pathInfo = pathinfo($file->getPathname());
                     if (in_array(strtolower($pathInfo['extension']), array('jpeg', 'jpg', 'jpe', 'png', 'gif'))) {
                         $path = str_replace('\\', '/', $file->getPathname());
                         $allThumbnails[] = substr($path, strpos($path, '/assets/') + 8);
                     }
                 }
             }
         }
     }
     if ($classes) {
         foreach ($classes as $className) {
             $SNG_class = singleton($className);
             $objects = DataObject::get($className);
             if ($objects !== NULL) {
                 foreach ($objects as $object) {
                     foreach ($SNG_class->db() as $fieldName => $fieldType) {
                         if ($fieldType == 'HTMLText') {
                             $url1 = HTTP::findByTagAndAttribute($object->{$fieldName}, array('img' => 'src'));
                             if ($url1 != NULL) {
                                 $usedThumbnails[] = substr($url1[0], strpos($url1[0], '/assets/') + 8);
                             }
                             if ($object->latestPublished > 0) {
                                 $object = Versioned::get_latest_version($className, $object->ID);
                                 $url2 = HTTP::findByTagAndAttribute($object->{$fieldName}, array('img' => 'src'));
                                 if ($url2 != NULL) {
                                     $usedThumbnails[] = substr($url2[0], strpos($url2[0], '/assets/') + 8);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return array_diff($allThumbnails, $usedThumbnails);
 }
开发者ID:comperio,项目名称:silverstripe-cms,代码行数:56,代码来源:AssetAdmin.php

示例13: isEnabled

 /**
  * If current variation is enabled, checks lastest version of variation because status is saved
  * in versions. So a variation can be saved as enabled, the version can be added to cart, then
  * the variation is disabled but the previous version stays enabled.
  * 
  * @return Boolean
  */
 public function isEnabled()
 {
     $latestVersion = Versioned::get_latest_version('Variation', $this->ID);
     $enabled = $latestVersion->Status == 'Enabled';
     $this->extend('isEnabled', $enabled);
     return $enabled;
 }
开发者ID:vinstah,项目名称:body,代码行数:14,代码来源:Variation.php

示例14: restore

 /**
  * Restore a completely deleted page from the SiteTree_versions table.
  */
 function restore($data, $form)
 {
     if (($id = $_REQUEST['ID']) && is_numeric($id)) {
         $restoredPage = Versioned::get_latest_version("SiteTree", $id);
         if ($restoredPage) {
             $restoredPage = $restoredPage->doRestoreToStage();
             FormResponse::get_page($id);
             $title = Convert::raw2js($restoredPage->TreeTitle());
             FormResponse::add("\$('sitetree').setNodeTitle({$id}, '{$title}');");
             FormResponse::status_message(sprintf(_t('CMSMain.RESTORED', "Restored '%s' successfully", PR_MEDIUM, 'Param %s is a title'), $title), 'good');
             return FormResponse::respond();
         } else {
             return new SS_HTTPResponse("SiteTree #{$id} not found", 400);
         }
     } else {
         return new SS_HTTPResponse("Please pass an ID in the form content", 400);
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:21,代码来源:CMSMain.php

示例15: testGetVersionWhenClassnameChanged

 public function testGetVersionWhenClassnameChanged()
 {
     $obj = new VersionedTest_DataObject();
     $obj->Name = "test";
     $obj->write();
     $obj->Name = "test2";
     $obj->ClassName = "VersionedTest_Subclass";
     $obj->write();
     $subclassVersion = $obj->Version;
     $obj->Name = "test3";
     $obj->ClassName = "VersionedTest_DataObject";
     $obj->write();
     // We should be able to pass the subclass and still get the correct class back
     $obj2 = Versioned::get_version("VersionedTest_Subclass", $obj->ID, $subclassVersion);
     $this->assertInstanceOf("VersionedTest_Subclass", $obj2);
     $this->assertEquals("test2", $obj2->Name);
     $obj3 = Versioned::get_latest_version("VersionedTest_Subclass", $obj->ID);
     $this->assertEquals("test3", $obj3->Name);
     $this->assertInstanceOf("VersionedTest_DataObject", $obj3);
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:20,代码来源:VersionedTest.php


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