本文整理汇总了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> ', _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;
}
示例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;
}
}
示例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());
}
示例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();
}
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
}
示例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;
}
示例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)');
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}