本文整理汇总了PHP中Versioned::get_version方法的典型用法代码示例。如果您正苦于以下问题:PHP Versioned::get_version方法的具体用法?PHP Versioned::get_version怎么用?PHP Versioned::get_version使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Versioned
的用法示例。
在下文中一共展示了Versioned::get_version方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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')));
}
示例2: testHasOnes
public function testHasOnes()
{
/** @var DataDifferencerTest_Object $obj1 */
$obj1 = $this->objFromFixture('DataDifferencerTest_Object', 'obj1');
$image1 = $this->objFromFixture('Image', 'image1');
$image2 = $this->objFromFixture('Image', 'image2');
$relobj1 = $this->objFromFixture('DataDifferencerTest_HasOneRelationObject', 'relobj1');
$relobj2 = $this->objFromFixture('DataDifferencerTest_HasOneRelationObject', 'relobj2');
// create a new version
$beforeVersion = $obj1->Version;
$obj1->ImageID = $image2->ID;
$obj1->HasOneRelationID = $relobj2->ID;
$obj1->write();
$afterVersion = $obj1->Version;
$this->assertNotEquals($beforeVersion, $afterVersion);
/** @var DataDifferencerTest_Object $obj1v1 */
$obj1v1 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, $beforeVersion);
/** @var DataDifferencerTest_Object $obj1v2 */
$obj1v2 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, $afterVersion);
$differ = new DataDifferencer($obj1v1, $obj1v2);
$obj1Diff = $differ->diffedData();
$this->assertContains($image1->Name, $obj1Diff->getField('Image'));
$this->assertContains($image2->Name, $obj1Diff->getField('Image'));
$this->assertContains('<ins>obj2</ins><del>obj1</del>', str_replace(' ', '', $obj1Diff->getField('HasOneRelationID')));
}
示例3: 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
示例4: ProductVariation
public function ProductVariation($current = false)
{
if ($current) {
return DataObject::get_by_id('ProductVariation', $this->_productVariationID);
} else {
return Versioned::get_version('ProductVariation', $this->_productVariationID, $this->_productVariationVersion);
}
}
示例5: Product
/**
* Get related product
* - live version if in cart, or
* - historical version if order is placed
*
* @param boolean $forcecurrent - force getting latest version of the product.
* @return Product
*/
public function Product($forcecurrent = false)
{
//TODO: this might need some unit testing to make sure it compliles with comment description
//ie use live if in cart (however I see no logic for checking cart status)
if ($this->ProductID && $this->ProductVersion && !$forcecurrent) {
return Versioned::get_version('Product', $this->ProductID, $this->ProductVersion);
} elseif ($this->ProductID && ($product = Versioned::get_one_by_stage("Product", "Live", "\"Product\".\"ID\" = " . $this->ProductID))) {
return $product;
}
return false;
}
示例6: addVersionViewer
public function addVersionViewer(FieldList $fields)
{
if ($this->owner->hasExtension('Versioned') || $this->owner->hasExtension('VersionedDataObject')) {
// Get the object where this function was called for reference purposes
$object = $this->owner;
// Get all tabs in the current model admin and prepart to put within a tabset called "Current"
$current_tabs = $fields->find('Name', 'Root')->Tabs();
$fields = FieldList::create(TabSet::create("Root", $currenttab = TabSet::create("Current"), $historytab = TabSet::create("History")->addExtraClass("vertical-tabs")));
// Add all existing tabs to "Current" tabset
$first = true;
foreach ($current_tabs as $tab) {
// If we have the getVersionedState function,
// add a notice regarding the versioned state to the first tab
// TODO incorporate VersionedDataObjectState extension into this module
if ($first && $object->hasMethod('getVersionedState')) {
$fields->addFieldToTab("Root.Current." . $tab->title, LiteralField::create('VersionedState', '<div class="message notice"><p>' . $object->getVersionedState() . '</p></div>'));
$first = false;
}
$fields->addFieldsToTab("Root.Current." . $tab->title, $tab->Fields());
}
// Remove any fields that have VersionViewerVisibility turned off
foreach ($current_tabs as &$tab) {
foreach ($tab->Fields() as $field) {
// echo '<pre>'.$field->Name.' Viewable? '; print_r($field->versionViewerVisibility);
if (!$field->versionViewerVisibility && $tab->fieldByName($field->Name)) {
$tab->removeByName($field->Name);
}
}
}
// die();
// Also, as of now, Versioned does not track has_many or many_many relationships
// So find fields relating to those relationships, remove them,
// and add a message regarding this
$untracked_msg = "";
foreach ($current_tabs as &$tab) {
foreach ($tab->Fields() as $field) {
$rel_class = $object->getRelationClass($field->Name);
if ($rel_class) {
if (in_array($rel_class, $object->has_many()) || in_array($rel_class, $object->many_many())) {
if ($tab->fieldByName($field->Name)) {
$tab->removeByName($field->Name);
if (!$untracked_msg) {
// $untracked_msg = '<div class="message notice"><p>Note: the following relationships are not tracked by versioning because they involve multiple records:<br />';
$untracked_msg = '<p>' . $field->Title();
} else {
$untracked_msg .= "<br />" . $field->Title();
}
}
}
}
}
}
if ($untracked_msg) {
$untracked_msg .= '</p>';
}
// Get all past versions of this data object and put the relevant data in a set of tabs
// within a tabset called "History"
$versions = $object->allVersions();
foreach ($versions as $version) {
// Get a record of this version of the object
$record = Versioned::get_version($object->ClassName, $object->ID, $version->Version);
// Make a set of read-only fields for use in assembling the History tabs
$read_fields = $current_tabs->makeReadonly();
// Make a form using the relevant fields and load it with data from this record
$form = new Form($object, "old_version", $read_fields, $object->getCMSActions());
$form->loadDataFrom($record);
// Add the version number to each field name so we don't have duplicate field names
if ($form->fields->dataFields()) {
foreach ($form->fields->dataFields() as $field) {
$field->Name = $field->Name . "version" . $version->Version;
}
}
// Generate some heading strings describing this version
$was_published = $version->WasPublished ? "P" : "D";
$was_published_full = $version->WasPublished ? "Published" : "Saved as draft";
$publishedby = Member::get()->byId($version->PublisherID);
$authoredby = Member::get()->byId($version->AuthorID);
$publisher_heading = "";
$author_heading = "";
if ($publishedby) {
$publisher_heading = " by " . $publishedby->getName();
}
if ($authoredby) {
$author_heading = " (Authored by " . $authoredby->getName() . ")";
}
$up_date = new SS_Datetime('update');
$up_date->setValue($version->LastEdited);
$nice_date = $up_date->FormatFromSettings();
$tab_title = $version->Version . " - " . $nice_date . " (" . $was_published . ")";
$latest_version_notice = "";
if ($version->isLatestVersion()) {
$latest_version_notice = " (latest version)";
}
$tab_heading = "<div class='message notice'><p><strong>Viewing version " . $version->Version . $latest_version_notice . ".</strong><br>" . $was_published_full . $publisher_heading . " on " . $nice_date . $author_heading . "</p></div>";
// Add fields to a tab headed with a description of this version
$fields->addFieldsToTab('Root.History.' . $tab_title, LiteralField::create('versionHeader' . $version->Version, $tab_heading));
$fields->addFieldsToTab('Root.History.' . $tab_title, $form->fields);
// Add notice regarding untracked relationships
if ($untracked_msg) {
$fields->addFieldsToTab('Root.History.' . $tab_title, HeaderField::create('untrackedMessageHeader' . $version->Version, 'Note: the relationships listed below are not tracked by versioning because they involve multiple records', 4));
//.........这里部分代码省略.........
开发者ID:bluehousegroup,项目名称:silverstripe-data-object-version-viewer,代码行数:101,代码来源:VersionViewerDataObject.php
示例7: compareVersions
/**
* Compare two version, and return the diff between them.
* @param string $from The version to compare from.
* @param string $to The version to compare to.
* @return DataObject
*/
function compareVersions($from, $to)
{
$fromRecord = Versioned::get_version($this->owner->class, $this->owner->ID, $from);
$toRecord = Versioned::get_version($this->owner->class, $this->owner->ID, $to);
$diff = new DataDifferencer($fromRecord, $toRecord);
return $diff->diffedData();
}
示例8: CompareVersionsForm
/**
* @return Form
*/
function CompareVersionsForm($versionID, $otherVersionID)
{
if ($versionID > $otherVersionID) {
$toVersion = $versionID;
$fromVersion = $otherVersionID;
} else {
$toVersion = $otherVersionID;
$fromVersion = $versionID;
}
if (!$toVersion || !$toVersion) {
return false;
}
$id = $this->currentPageID();
$page = DataObject::get_by_id("SiteTree", $id);
if ($page && !$page->canView()) {
return Security::permissionFailure($this);
}
$record = $page->compareVersions($fromVersion, $toVersion);
$fromVersionRecord = Versioned::get_version('SiteTree', $id, $fromVersion);
$toVersionRecord = Versioned::get_version('SiteTree', $id, $toVersion);
if (!$fromVersionRecord) {
user_error("Can't find version {$fromVersion} of page {$id}", E_USER_ERROR);
}
if (!$toVersionRecord) {
user_error("Can't find version {$toVersion} of page {$id}", E_USER_ERROR);
}
if ($record) {
$form = $this->getEditForm($id, null, null, true);
$form->setActions(new FieldList());
$form->addExtraClass('compare');
// Comparison views shouldn't be editable.
// Its important to convert fields *before* loading data,
// as the comparison output is HTML and not valid values for the various field types
$readonlyFields = $form->Fields()->makeReadonly();
$form->setFields($readonlyFields);
$form->loadDataFrom($record);
$form->loadDataFrom(array("ID" => $id, "Version" => $fromVersion));
foreach ($form->Fields()->dataFields() as $field) {
$field->dontEscape = true;
}
return $form;
}
}
示例9: pushChangeset
/**
* Push a content changeset to a syncro node
*
* @param ContentChangeset $changeset
* @param RemoteSyncroNode $node
*
*/
public function pushChangeset($changeset, $node)
{
$cs = $changeset->ChangesetItems();
$update = array('changes' => array(), 'deletes' => array(), 'rels' => array());
foreach ($cs as $changesetItem) {
$record = null;
// if it's a delete, we create a syncro delete, otherwise get the versioned item
if ($changesetItem->ChangeType == 'Draft Deleted') {
// find the syncrodelete record
$record = DataList::create('SyncroDelete')->filter(array('ContentID' => $changesetItem->OtherContentID))->first();
$del = array('SYNCRODELETE' => 'DELETE', 'ContentID' => $record->ContentID, 'Type' => $record->Type, 'MasterNode' => SiteConfig::current_site_config()->SystemID, 'Deleted' => $record->Created);
$update['deletes'][] = $del;
} else {
$record = Versioned::get_version($changesetItem->OtherClass, $changesetItem->OtherID, $changesetItem->ContentVersion);
$syncd = $this->syncroObject($record);
$syncd['ClassName'] = $record->ClassName;
if (count($syncd['has_one']) || count($syncd['many_many'])) {
$relInfo = new stdClass();
$relInfo->SYNCROREL = true;
$relInfo->Type = $record->ClassName;
$relInfo->ContentID = $record->ContentID;
$relInfo->MasterNode = SiteConfig::current_site_config()->SystemID;
$relInfo->has_one = $syncd['has_one'];
$relInfo->many_many = $syncd['many_many'];
$update['rels'][] = $relInfo;
}
unset($syncd['has_one']);
unset($syncd['many_many']);
$update['changes'][] = $syncd;
}
}
if ($update && $node) {
$url = $node->NodeURL;
$service = new RestfulService($url, -1);
$params = array('changes' => $update['changes'], 'deletes' => $update['deletes'], 'rels' => $update['rels']);
$headers = array('X-Auth-Token: ' . $node->APIToken, 'Content-Type: application/json');
$body = json_encode($params);
$response = $service->request(self::PUSH_URL, 'POST', $body, $headers);
//, $headers, $curlOptions);
if ($response && $response->isError()) {
$body = $response->getBody();
if ($body) {
$this->log->logError($body);
}
return array(false, "Deployment failed to {$url}: status {$response->getStatusCode()}");
}
$body = $response->getBody();
if ($body) {
return array(true, 'Deployment successful');
}
}
}
示例10: Product
/**
* Get the product for the item
*
* @return Mixed Product if it exists, otherwise null
*/
function Product()
{
return Versioned::get_version('Product', $this->ProductID, $this->ProductVersion);
}
示例11: compareversions
function compareversions()
{
$id = $this->request->param('ID') ? $this->request->param('ID') : $this->request->requestVar('ID');
$versions = $this->request->requestVar('Versions');
$version1 = $versions && isset($versions[0]) ? $versions[0] : $this->request->getVar('From');
$version2 = $versions && isset($versions[1]) ? $versions[1] : $this->request->getVar('To');
if ($version1 > $version2) {
$toVersion = $version1;
$fromVersion = $version2;
} else {
$toVersion = $version2;
$fromVersion = $version1;
}
if (!$toVersion || !$toVersion) {
return false;
}
$page = DataObject::get_by_id("SiteTree", $id);
if ($page && !$page->canView()) {
return Security::permissionFailure($this);
}
$record = $page->compareVersions($fromVersion, $toVersion);
$fromVersionRecord = Versioned::get_version('SiteTree', $id, $fromVersion);
$toVersionRecord = Versioned::get_version('SiteTree', $id, $toVersion);
if (!$fromVersionRecord) {
user_error("Can't find version {$fromVersion} of page {$id}", E_USER_ERROR);
}
if (!$toVersionRecord) {
user_error("Can't find version {$toVersion} of page {$id}", E_USER_ERROR);
}
if ($record) {
$fromDateNice = $fromVersionRecord->obj('LastEdited')->Ago();
$toDateNice = $toVersionRecord->obj('LastEdited')->Ago();
$fromAuthor = DataObject::get_by_id('Member', $fromVersionRecord->AuthorID);
if (!$fromAuthor) {
$fromAuthor = new ArrayData(array('Title' => 'Unknown author'));
}
$toAuthor = DataObject::get_by_id('Member', $toVersionRecord->AuthorID);
if (!$toAuthor) {
$toAuthor = new ArrayData(array('Title' => 'Unknown author'));
}
$fields = $record->getCMSFields($this);
$fields->push(new HiddenField("ID"));
$fields->push(new HiddenField("Version"));
$fields->insertBefore(new LiteralField('YouAreComparingHeader', '<p class="message notice">' . sprintf(_t('CMSMain.COMPARINGV', "Comparing versions %s and %s"), "<a href=\"admin/getversion/{$id}/{$fromVersionRecord->Version}\" title=\"{$fromAuthor->Title}\">{$fromVersionRecord->Version}</a> <small>({$fromDateNice})</small>", "<a href=\"admin/getversion/{$id}/{$toVersionRecord->Version}\" title=\"{$toAuthor->Title}\">{$toVersionRecord->Version}</a> <small>({$toDateNice})</small>") . '</p>'), "Root");
$actions = new FieldSet();
$form = new Form($this, "EditForm", $fields, $actions);
$form->loadDataFrom($record);
$form->loadDataFrom(array("ID" => $id, "Version" => $fromVersion));
$form->addExtraClass('compare');
// comparison views shouldn't be editable
$readonlyFields = $form->Fields()->makeReadonly();
$form->setFields($readonlyFields);
foreach ($form->Fields()->dataFields() as $field) {
$field->dontEscape = true;
}
if ($this->isAjax()) {
return $form->formHtmlContent();
} else {
$templateData = $this->customise(array("EditForm" => $form));
return $templateData->renderWith('LeftAndMain');
}
}
}
示例12: get_version
/**
* HACK: Versioned is BROKEN this method helps in fixing it.
* Basically, in Versioned, you get a hard-coded error
* when you retrieve an older version of a DataObject.
* This method returns null if it does not exist.
*
* Idea is from Jeremy: https://github.com/burnbright/silverstripe-shop/blob/master/code/products/FixVersioned.php
* @param String $class
* @param Int $id
* @param Int $version
* @return DataObject | Null
*/
public static function get_version($class, $id, $version)
{
$oldMode = Versioned::get_reading_mode();
Versioned::set_reading_mode('');
$versionedObject = Versioned::get_version($class, $id, $version);
Versioned::set_reading_mode($oldMode);
return $versionedObject;
}
示例13: onAfterRollback
/**
* @see Versioned::doRollBackTo
* @param string $version Either the string 'Live' or a version number
*
* @return null
*/
public function onAfterRollback($version)
{
// get the owner data for this version
if (is_numeric($version)) {
$page = Versioned::get_version($this->owner->ClassName, $this->owner->ID, $version);
} else {
$this->owner->flushCache();
$baseTable = $this->owner->baseTable();
$page = Versioned::get_one_by_stage($this->owner->ClassName, $version, "\"{$baseTable}\".\"ID\"={$this->owner->ID}");
}
$date = $page->LastEdited;
$oldMode = Versioned::get_reading_mode();
// get the current items
Versioned::set_reading_mode('Stage.Stage');
$current_items = array();
foreach ($this->getItemsToPublish() as $field) {
$current_items[] = $field;
}
// Get items in the version that we want by setting reading mode to date of version
if (is_numeric($version)) {
Versioned::set_reading_mode('Archive.' . $date);
} else {
Versioned::set_reading_mode('Stage.Live');
}
$version_items = array();
$version_ids = array();
foreach ($this->getItemsToPublish() as $field) {
$version_items[] = $field;
$version_ids[] = $field->ClassName . '_' . $field->ID;
}
Versioned::set_reading_mode($oldMode);
// rollback version items
foreach ($version_items as $field) {
$fieldVersion = is_numeric($version) ? $field->Version : 'Live';
if ($field->hasMethod('doDoRollBackTo')) {
$field->doDoRollBackTo($fieldVersion);
} else {
$field->doRollBackTo($fieldVersion);
}
}
// delete items not in version
foreach ($current_items as $field) {
if (!in_array($field->ClassName . '_' . $field->ID, $version_ids)) {
$clone = clone $field;
if ($clone->hasMethod('doDeleteFromStage')) {
$clone->doDeleteFromStage('Stage');
} else {
$clone->deleteFromStage('Stage');
}
}
}
}
示例14: compareVersions
/**
* Compare two version, and return the diff between them.
* @param string $from The version to compare from.
* @param string $to The version to compare to.
* @return DataObject
*/
function compareVersions($from, $to)
{
$fromRecord = Versioned::get_version($this->owner->class, $this->owner->ID, $from);
$toRecord = Versioned::get_version($this->owner->class, $this->owner->ID, $to);
$fields = array_keys($fromRecord->getAllFields());
foreach ($fields as $field) {
if (in_array($field, array("ID", "Version", "RecordID", "AuthorID", "ParentID"))) {
continue;
}
$fromRecord->{$field} = Diff::compareHTML($fromRecord->{$field}, $toRecord->{$field});
}
return $fromRecord;
}
示例15: Object
/**
* Retrieve the object this item represents, usually a {@link Variation}.
* Uses the object version so that the correct object details such as price are
* retrieved.
*
* @return DataObject
*/
function Object()
{
return Versioned::get_version($this->ObjectClass, $this->ObjectID, $this->ObjectVersion);
}