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


PHP Versioned::get_one_by_stage方法代码示例

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


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

示例1: doPublish

 /**
  * Modified version of the SiteTree publish method.
  *
  * @return <type>
  */
 public function doPublish()
 {
     if (!$this->owner->canPublish()) {
         return false;
     }
     $class = $this->owner->class;
     $ownerId = $this->owner->ID;
     $dataClasses = ClassInfo::dataClassesFor($class);
     $dataClasses = array_values($dataClasses);
     $class = $dataClasses[count($dataClasses) - 1];
     $original = Versioned::get_one_by_stage("{$class}", "Live", "\"{$class}\".\"ID\" = {$ownerId}");
     if (!$original) {
         $original = new $class();
     }
     $this->owner->invokeWithExtensions('onBeforePublish', $original);
     // Handle activities undertaken by decorators
     $this->owner->Status = "Published";
     //$this->PublishedByID = Member::currentUser()->ID;
     $this->owner->write();
     $this->owner->publish("Stage", "Live");
     if ($this->owner->hasField('Sort')) {
         // find the table that actually defines the sortable field
         $class = get_class($this->owner);
         if ($this->owner->hasMethod('findClassDefiningSortField')) {
             $class = $this->owner->findClassDefiningSortField();
         }
         DB::query("UPDATE \"{$class}_Live\"\n\t\t\t\tSET \"Sort\" = (SELECT \"{$class}\".\"Sort\" FROM \"{$class}\" WHERE \"{$class}_Live\".\"ID\" = \"{$class}\".\"ID\")");
     }
     // Handle activities undertaken by decorators
     $this->owner->invokeWithExtensions('onAfterPublish', $original);
     return true;
 }
开发者ID:nyeholt,项目名称:silverstripe-publishableobjects,代码行数:37,代码来源:PublishableObject.php

示例2: update_cms_actions

 /**
  * @param FieldSet $actions
  * @parma SiteTree $page
  */
 public static function update_cms_actions(&$actions, $page)
 {
     $openRequest = $page->OpenWorkflowRequest();
     // if user doesn't have publish rights
     if (!$page->canPublish() || $openRequest) {
         // authors shouldn't be able to revert, as this republishes the page.
         // they should rather change the page and re-request publication
         $actions->removeByName('action_revert');
     }
     // Remove the one click publish if they are not an admin/workflow admin.
     if (self::$force_publishers_to_use_workflow && !Permission::checkMember(Member::currentUser(), 'IS_WORKFLOW_ADMIN')) {
         $actions->removeByName('action_publish');
     }
     // Remove the save & publish button if you don't have edit rights
     if (!$page->canEdit()) {
         $actions->removeByName('action_publish');
     }
     $liveVersion = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree_Live\".\"ID\" = {$page->ID}");
     if ($liveVersion && $liveVersion->ExpiryDate != null && $liveVersion->ExpiryDate != '0000-00-00 00:00:00') {
         if ($page->canApprove()) {
             $actions->push(new FormAction('cms_cancelexpiry', _t('WorkflowPublicationRequest.BUTTONCANCELEXPIRY', 'Cancel expiry')));
         }
     }
     // Optional method
     $isPublishable = $page->hasMethod('isPublishable') ? $page->isPublishable() : true;
     if (!$openRequest && $page->canEdit() && $isPublishable && $page->stagesDiffer('Stage', 'Live') && ($page->Version > 1 || $page->Title != "New Page") && !$page->IsDeletedFromStage && (!$page->canPublish() || self::$publisher_can_create_wf_requests)) {
         $actions->push($requestPublicationAction = new FormAction('cms_requestpublication', _t('SiteTreeCMSWorkflow.BUTTONREQUESTPUBLICATION', 'Request Publication')));
         // don't allow creation of a second request by another author
         if (!self::can_create(null, $page)) {
             $actions->makeFieldReadonly($requestPublicationAction->Name());
         }
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-cmsworkflow,代码行数:37,代码来源:WorkflowPublicationRequest.php

示例3: ItemEditForm

 function ItemEditForm()
 {
     $form = parent::ItemEditForm();
     $actions = $form->Actions();
     $majorActions = CompositeField::create()->setName('MajorActions')->setTag('fieldset')->addExtraClass('ss-ui-buttonset');
     $rootTabSet = new TabSet('ActionMenus');
     $moreOptions = new Tab('MoreOptions', _t('SiteTree.MoreOptions', 'More options', 'Expands a view for more buttons'));
     $rootTabSet->push($moreOptions);
     $rootTabSet->addExtraClass('ss-ui-action-tabset action-menus');
     // Render page information into the "more-options" drop-up, on the top.
     $baseClass = ClassInfo::baseDataClass($this->record->class);
     $live = Versioned::get_one_by_stage($this->record->class, 'Live', "\"{$baseClass}\".\"ID\"='{$this->record->ID}'");
     $existsOnLive = $this->record->getExistsOnLive();
     $published = $this->record->isPublished();
     $moreOptions->push(new LiteralField('Information', $this->record->customise(array('Live' => $live, 'ExistsOnLive' => $existsOnLive))->renderWith('SiteTree_Information')));
     $actions->removeByName('action_doSave');
     $actions->removeByName('action_doDelete');
     if ($this->record->canEdit()) {
         if ($this->record->IsDeletedFromStage) {
             if ($existsOnLive) {
                 $majorActions->push(FormAction::create('revert', _t('CMSMain.RESTORE', 'Restore')));
                 if ($this->record->canDelete() && $this->record->canDeleteFromLive()) {
                     $majorActions->push(FormAction::create('unpublish', _t('CMSMain.DELETEFP', 'Delete'))->addExtraClass('ss-ui-action-destructive'));
                 }
             } else {
                 if (!$this->record->isNew()) {
                     $majorActions->push(FormAction::create('restore', _t('CMSMain.RESTORE', 'Restore'))->setAttribute('data-icon', 'decline'));
                 } else {
                     $majorActions->push(FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))->addExtraClass('ss-ui-alternate ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'addpage')->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))->setUseButtonTag(true));
                     $majorActions->push(FormAction::create('publish', _t('SiteTree.BUTTONPUBLISHED', 'Published'))->addExtraClass('ss-ui-alternate ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'disk')->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setUseButtonTag(true));
                 }
             }
         } else {
             if ($this->record->canDelete() && !$published) {
                 $moreOptions->push(FormAction::create('delete', _t('SiteTree.BUTTONDELETE', 'Delete draft'))->addExtraClass('ss-ui-action-destructive')->setUseButtonTag(true));
             }
             $majorActions->push(FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'addpage')->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))->setUseButtonTag(true));
         }
     }
     $publish = FormAction::create('publish', $published ? _t('SiteTree.BUTTONPUBLISHED', 'Published') : _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'disk')->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setUseButtonTag(true);
     if (!$published || $this->record->stagesDiffer('Stage', 'Live') && $published) {
         $publish->addExtraClass('ss-ui-alternate');
     }
     if ($this->record->canPublish() && !$this->record->IsDeletedFromStage) {
         $majorActions->push($publish);
     }
     if ($published && $this->record->canPublish() && !$this->record->IsDeletedFromStage && $this->record->canDeleteFromLive()) {
         $moreOptions->push(FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete')->addExtraClass('ss-ui-action-destructive')->setUseButtonTag(true));
     }
     if ($this->record->stagesDiffer('Stage', 'Live') && !$this->record->IsDeletedFromStage && $this->record->isPublished() && $this->record->canEdit()) {
         $moreOptions->push(FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'))->setDescription(_t('SiteTree.BUTTONCANCELDRAFTDESC', 'Delete your draft and revert to the currently published page'))->setUseButtonTag(true));
     }
     $actions->push($majorActions);
     $actions->push($rootTabSet);
     if ($this->record->hasMethod('getCMSValidator')) {
         $form->setValidator($this->record->getCMSValidator());
     }
     return $form;
 }
开发者ID:helpfulrobot,项目名称:studiobonito-silverstripe-publishable,代码行数:59,代码来源:PublishableGridFieldDetailForm.php

示例4: process

 /**
  * To process this job, we need to get the next page whose ID is the next greater than the last
  * processed. This way we don't need to remember a bunch of data about what we've processed
  */
 public function process()
 {
     if (ClassInfo::exists('Subsite')) {
         Subsite::disable_subsite_filter();
     }
     $class = $this->reindexType;
     $pages = $class::get();
     $pages = $pages->filter(array('ID:GreaterThan' => $this->lastIndexedID));
     $pages = $pages->limit(Config::inst()->get(__CLASS__, 'at_a_time'));
     $pages = $pages->sort('ID ASC');
     if (ClassInfo::exists('Subsite')) {
         Subsite::$disable_subsite_filter = false;
     }
     if (!$pages || !$pages->count()) {
         $this->isComplete = true;
         return;
     }
     $mode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // index away
     $service = singleton('SolrSearchService');
     $live = array();
     $stage = array();
     $all = array();
     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')) {
             $stage[] = $page;
             $base = $page->baseTable();
             $idField = '"' . $base . '_Live"."ID"';
             $livePage = Versioned::get_one_by_stage($page->ClassName, 'Live', $idField . ' = ' . $page->ID);
             if ($livePage) {
                 $live[] = $livePage;
             }
         } else {
             $all[] = $page;
         }
         $this->lastIndexedID = $page->ID;
     }
     if (count($all)) {
         $service->indexMultiple($all);
     }
     if (count($stage)) {
         $service->indexMultiple($stage, 'Stage');
     }
     if (count($live)) {
         $service->indexMultiple($live, 'Live');
     }
     Versioned::set_reading_mode($mode);
     $this->lastIndexedID = $page->ID;
     $this->currentStep += $pages->count();
 }
开发者ID:nyeholt,项目名称:silverstripe-solr,代码行数:63,代码来源:SolrReindexJob.php

示例5: testVersionedObjects

 /**
  * Test version support. If an object has versioned then both the live and
  * staging tables should be updated. Other live records should be removed
  * as well.
  */
 public function testVersionedObjects()
 {
     $versioned = $this->objFromFixture('PopulateFactoryTest_TestVersionedObject', 'objV1');
     $versioned->publish('Stage', 'Live');
     $obj = $this->factory->createObject('PopulateFactoryTest_TestVersionedObject', 'test', array('Content' => 'Updated Version Foo', 'PopulateMergeWhen' => "Title = 'Version Foo'"));
     $this->assertEquals($versioned->ID, $obj->ID);
     $this->assertEquals('Updated Version Foo', $obj->Content);
     $check = Versioned::get_one_by_stage('PopulateFactoryTest_TestVersionedObject', 'Live', "Title = 'Version Foo'");
     $this->assertEquals('Updated Version Foo', $check->Content);
 }
开发者ID:helpfulrobot,项目名称:dnadesign-silverstripe-populate,代码行数:15,代码来源:PopulateFactoryTest.php

示例6: testFileDelete

 public function testFileDelete()
 {
     \Versioned::reading_stage('Stage');
     /** @var AssetControlExtensionTest_VersionedObject $object1 */
     $object1 = AssetControlExtensionTest_VersionedObject::get()->filter('Title', 'My object')->first();
     /** @var AssetControlExtensionTest_Object $object2 */
     $object2 = AssetControlExtensionTest_Object::get()->filter('Title', 'Unversioned')->first();
     /** @var AssetControlExtensionTest_ArchivedObject $object3 */
     $object3 = AssetControlExtensionTest_ArchivedObject::get()->filter('Title', 'Archived')->first();
     $this->assertTrue($object1->Download->exists());
     $this->assertTrue($object1->Header->exists());
     $this->assertTrue($object2->Image->exists());
     $this->assertTrue($object3->Header->exists());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object1->Download->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object1->Header->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object2->Image->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object3->Header->getVisibility());
     // Check live stage for versioned objects
     $object1Live = Versioned::get_one_by_stage('AssetControlExtensionTest_VersionedObject', 'Live', array('"ID"' => $object1->ID));
     $object3Live = Versioned::get_one_by_stage('AssetControlExtensionTest_ArchivedObject', 'Live', array('"ID"' => $object3->ID));
     $this->assertTrue($object1Live->Download->exists());
     $this->assertTrue($object1Live->Header->exists());
     $this->assertTrue($object3Live->Header->exists());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object1Live->Download->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object1Live->Header->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object3Live->Header->getVisibility());
     // Delete live records; Should cause versioned records to be protected
     $object1Live->deleteFromStage('Live');
     $object3Live->deleteFromStage('Live');
     $this->assertTrue($object1->Download->exists());
     $this->assertTrue($object1->Header->exists());
     $this->assertTrue($object3->Header->exists());
     $this->assertTrue($object1Live->Download->exists());
     $this->assertTrue($object1Live->Header->exists());
     $this->assertTrue($object3Live->Header->exists());
     $this->assertEquals(AssetStore::VISIBILITY_PROTECTED, $object1->Download->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PROTECTED, $object1->Header->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PROTECTED, $object3->Header->getVisibility());
     // Delete draft record; Should remove all records
     // Archived assets only should remain
     $object1->delete();
     $object2->delete();
     $object3->delete();
     $this->assertFalse($object1->Download->exists());
     $this->assertFalse($object1->Header->exists());
     $this->assertFalse($object2->Image->exists());
     $this->assertTrue($object3->Header->exists());
     $this->assertFalse($object1Live->Download->exists());
     $this->assertFalse($object1Live->Header->exists());
     $this->assertTrue($object3Live->Header->exists());
     $this->assertNull($object1->Download->getVisibility());
     $this->assertNull($object1->Header->getVisibility());
     $this->assertNull($object2->Image->getVisibility());
     $this->assertEquals(AssetStore::VISIBILITY_PROTECTED, $object3->Header->getVisibility());
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:55,代码来源:AssetControlExtensionTest.php

示例7: testUnpublishing

 function testUnpublishing()
 {
     $id = $this->form->ID;
     $this->form->Fields()->removeAll();
     $this->form->Fields()->add(new EditableFormField());
     $this->form->doUnPublish();
     $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = {$id}");
     $stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = {$id}");
     $this->assertEquals($live, false);
     $this->assertEquals($stage->Fields()->Count(), 1);
 }
开发者ID:nicmart,项目名称:comperio-site,代码行数:11,代码来源:UserDefinedFormEditorTest.php

示例8: testDeletedPagesFilter

 function testDeletedPagesFilter()
 {
     $deletedPage = $this->objFromFixture('Page', 'page2');
     $deletedPage->publish('Stage', 'Live');
     $deletedPageID = $deletedPage->ID;
     $deletedPage->delete();
     $deletedPage = Versioned::get_one_by_stage('SiteTree', 'Live', sprintf('"SiteTree_Live"."ID" = %d', $deletedPageID));
     $f = new CMSSiteTreeFilter_DeletedPages();
     $results = $f->pagesIncluded();
     $this->assertTrue($f->isPageIncluded($deletedPage));
 }
开发者ID:rodneyway,项目名称:silverstripe-cms,代码行数:11,代码来源:CMSSiteTreeFilterTest.php

示例9: onBeforeDelete

 function onBeforeDelete()
 {
     // check if Page still exists in live mode
     $className = $this->ClassName;
     $livePage = Versioned::get_one_by_stage($className, "Live", "\"{$className}_Live\".\"ID\" = {$this->ID}");
     // check if Page still exists in stage mode
     $stagePage = Versioned::get_one_by_stage($className, "Stage", "\"{$className}\".\"ID\" = {$this->ID}");
     // if Page only exists in Live OR Stage mode -> Page will be deleted completely
     if (!($livePage && $stagePage)) {
         // delete existing Albums
         $this->Albums()->removeAll();
     }
     parent::onBeforeDelete();
 }
开发者ID:helpfulrobot,项目名称:tractorcow-silverstripe-imagegallery,代码行数:14,代码来源:ImageGalleryPage.php

示例10: upgradeField

 /**
  * Migrate a versioned field in all stages
  *
  * @param EditableFormField $field
  */
 protected function upgradeField(EditableFormField $field)
 {
     $this->log("Upgrading formfield ID = " . $field->ID);
     // Check versions this field exists on
     $filter = sprintf('"EditableFormField"."ID" = \'%d\' AND "Migrated" = 0', $field->ID);
     $stageField = Versioned::get_one_by_stage('EditableFormField', 'Stage', $filter);
     $liveField = Versioned::get_one_by_stage('EditableFormField', 'Live', $filter);
     if ($stageField) {
         $this->upgradeFieldInStage($stageField, 'Stage');
     }
     if ($liveField) {
         $this->upgradeFieldInStage($liveField, 'Live');
     }
 }
开发者ID:camfindlay,项目名称:silverstripe-userforms,代码行数:19,代码来源:UserFormsUpgradeService.php

示例11: doPublish

	public function doPublish() {
		if ($this->owner->hasMethod('canPublish') &&
				!$this->owner->canPublish())
			return false;
		
		$original = Versioned::get_one_by_stage($this->owner->ClassName, 'Live',
			"\"{$this->owner->ClassName}\".\"ID\" = {$this->owner->ID}");
		$original = $original? $original: new $this->owner->ClassName;
		$this->owner->invokeWithExtensions('onBeforePublish', $original);
		$this->owner->publish('Stage', 'Live');
		$this->owner->invokeWithExtensions('onAfterPublish', $original);
		
		return true;
	}
开发者ID:redema,项目名称:silverstripe-handyman,代码行数:14,代码来源:DataObjectVersionedMethodDecorator.php

示例12: testRollbackTo

 function testRollbackTo()
 {
     $page1 = $this->objFromFixture('Page', 'page1');
     $page1->Content = 'orig';
     $page1->write();
     $page1->publish('Stage', 'Live');
     $origVersion = $page1->Version;
     $page1->Content = 'changed';
     $page1->write();
     $page1->publish('Stage', 'Live');
     $changedVersion = $page1->Version;
     $page1->doRollbackTo($origVersion);
     $page1 = Versioned::get_one_by_stage('Page', 'Stage', sprintf('"SiteTree"."ID" = %d', $page1->ID));
     $this->assertTrue($page1->Version > $changedVersion, 'Create a new higher version number');
     $this->assertEquals('orig', $page1->Content, 'Copies the content from the old version');
 }
开发者ID:Raiser,项目名称:Praktikum,代码行数:16,代码来源:VersionedTest.php

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

示例14: testImportPublishAll

    function testImportPublishAll()
    {
        $data = <<<YML
Parent1
Parent2
\tChild2_1
\t\tGrandchild2_1_1
\tChild2_2
Parent3
YML;
        $this->import($data, array('PublishAll' => 1));
        $parent1 = Versioned::get_one_by_stage('Page', 'Live', "\"Title\" = 'Parent1'");
        $parent2 = Versioned::get_one_by_stage('Page', 'Live', "\"Title\" = 'Parent2'");
        $parent3 = Versioned::get_one_by_stage('Page', 'Live', "\"Title\" = 'Parent3'");
        $child2_1 = Versioned::get_one_by_stage('Page', 'Live', "\"Title\" = 'Child2_1'");
        $child2_2 = Versioned::get_one_by_stage('Page', 'Live', "\"Title\" = 'Child2_2'");
        $grandchild2_1_1 = Versioned::get_one_by_stage('Page', 'Live', "\"Title\" = 'Grandchild2_1_1'");
        $this->assertInstanceOf('Page', $parent1);
        $this->assertInstanceOf('Page', $parent2);
        $this->assertInstanceOf('Page', $parent3);
        $this->assertInstanceOf('Page', $child2_1);
        $this->assertInstanceOf('Page', $child2_2);
        $this->assertInstanceOf('Page', $grandchild2_1_1);
    }
开发者ID:helpfulrobot,项目名称:silverstripe-sitetreeimporter,代码行数:24,代码来源:SiteTreeImporterTest.php

示例15: run

 function run($request)
 {
     $ids = array();
     echo "#################################\n";
     echo "# Adding translation groups to existing records" . "\n";
     echo "#################################\n";
     $allSiteTreeIDs = DB::query('SELECT `ID` FROM `SiteTree`')->column();
     if ($allSiteTreeIDs) {
         foreach ($allSiteTreeIDs as $id) {
             $original = DataObject::get_by_id('SiteTree', $id);
             $existingGroupID = $original->getTranslationGroup();
             if (!$existingGroupID) {
                 $original->addTranslationGroup($original->ID);
             }
             $original->destroy();
             unset($original);
         }
     }
     DataObject::flush_and_destroy_cache();
     echo sprintf("Created translation groups for %d records\n", count($allSiteTreeIDs));
     foreach (array('Stage', 'Live') as $stage) {
         echo "\n\n#################################\n";
         echo "# Migrating stage {$stage}" . "\n";
         echo "#################################\n";
         $suffix = $stage == 'Live' ? '_Live' : '';
         // First get all entries in SiteTree_lang
         // This should be all translated pages
         $trans = DB::query(sprintf('SELECT * FROM `_obsolete_SiteTree_lang%s`', $suffix));
         // Iterate over each translated pages
         foreach ($trans as $oldtrans) {
             $newLocale = i18n::get_locale_from_lang($oldtrans['Lang']);
             echo sprintf("Migrating from %s to %s translation of '%s' (#%d)\n", $oldtrans['Lang'], $newLocale, Convert::raw2xml($oldtrans['Title']), $oldtrans['OriginalLangID']);
             // Get the untranslated page
             $original = Versioned::get_one_by_stage($oldtrans['ClassName'], $stage, '`SiteTree`.`ID` = ' . $oldtrans['OriginalLangID']);
             if (!$original) {
                 echo sprintf("Couldn't find original for #%d", $oldtrans['OriginalLangID']);
                 continue;
             }
             // write locale to $original
             $original->Locale = i18n::get_locale_from_lang(Translatable::default_lang());
             $original->writeToStage($stage);
             // Clone the original, and set it up as a translation
             $existingTrans = $original->getTranslation($newLocale, $stage);
             if ($existingTrans) {
                 echo sprintf("Found existing new-style translation for #%d. Already merged? Skipping.\n", $oldtrans['OriginalLangID']);
                 continue;
             }
             // Doesn't work with stage/live split
             //$newtrans = $original->createTranslation($newLocale);
             $newtrans = $original->duplicate(false);
             $newtrans->OriginalID = $original->ID;
             // we have to "guess" a locale based on the language
             $newtrans->Locale = $newLocale;
             if ($stage == 'Live' && array_key_exists($original->ID, $ids)) {
                 $newtrans->ID = $ids[$original->ID];
             }
             // Look at each class in the ancestry, and see if there is a _lang table for it
             foreach (ClassInfo::ancestry($oldtrans['ClassName']) as $classname) {
                 $oldtransitem = false;
                 // If the class is SiteTree, we already have the DB record, else check for the table and get the record
                 if ($classname == 'SiteTree') {
                     $oldtransitem = $oldtrans;
                 } elseif (in_array(strtolower($classname) . '_lang', DB::tableList())) {
                     $oldtransitem = DB::query(sprintf('SELECT * FROM `_obsolete_%s_lang%s` WHERE `OriginalLangID` = %d AND `Lang` = \'%s\'', $classname, $suffix, $original->ID, $oldtrans['Lang']))->first();
                 }
                 // Copy each translated field into the new translation
                 if ($oldtransitem) {
                     foreach ($oldtransitem as $key => $value) {
                         if (!in_array($key, array('ID', 'OriginalLangID'))) {
                             $newtrans->{$key} = $value;
                         }
                     }
                 }
             }
             // Write the new translation to the database
             $sitelang = Translatable::get_current_locale();
             Translatable::set_current_locale($newtrans->Locale);
             $newtrans->writeToStage($stage);
             Translatable::set_current_locale($sitelang);
             $newtrans->addTranslationGroup($original->getTranslationGroup(), true);
             if ($stage == 'Stage') {
                 $ids[$original->ID] = $newtrans->ID;
             }
         }
     }
     echo "\n\n#################################\n";
     echo "Done!\n";
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:88,代码来源:MigrateTranslatableTask.php


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