本文整理汇总了PHP中Versioned::reading_stage方法的典型用法代码示例。如果您正苦于以下问题:PHP Versioned::reading_stage方法的具体用法?PHP Versioned::reading_stage怎么用?PHP Versioned::reading_stage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Versioned
的用法示例。
在下文中一共展示了Versioned::reading_stage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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());
}
}
示例3: check
public function check(Discount $discount)
{
$products = $discount->Products();
// if no products in the discount even
if (!$products->exists()) {
$curr = Versioned::current_stage();
Versioned::reading_stage('Stage');
$products = $discount->Products();
if (!$products->exists()) {
return true;
}
$constraintproductids = $products->map('ID', 'ID')->toArray();
Versioned::reading_stage($curr);
} else {
$constraintproductids = $products->map('ID', 'ID')->toArray();
}
// uses 'DiscountedProductID' so that subclasses of projects (say a custom nested set of products) can define the
// underlying DiscountedProductID.
$cartproductids = $this->order->Items()->map('ProductID', 'DiscountedProductID')->toArray();
$intersection = array_intersect($constraintproductids, $cartproductids);
$incart = $discount->ExactProducts ? array_values($constraintproductids) === array_values($intersection) : count($intersection) > 0;
if (!$incart) {
$this->error(_t('ProductsDiscountConstraint.MISSINGPRODUCT', "The required products are not in the cart."));
}
return $incart;
}
示例4: 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;
}
示例5: testPublishingSourcePagePublishesAlreadyPublishedVirtualPages
/**
* Test that, after you publish the source page of a virtual page, all the already published
* virtual pages are published
*/
public function testPublishingSourcePagePublishesAlreadyPublishedVirtualPages()
{
$this->logInWithPermission('ADMIN');
$master = $this->objFromFixture('Page', 'master');
$master->doPublish();
$master->Title = "New title";
$master->MenuTitle = "New menutitle";
$master->Content = "<p>New content</p>";
$master->write();
$vp1 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp1'));
$vp2 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp2'));
$this->assertTrue($vp1->doPublish());
$this->assertTrue($vp2->doPublish());
$master->doPublish();
Versioned::reading_stage("Live");
$vp1 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp1'));
$vp2 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp2'));
$this->assertNotNull($vp1);
$this->assertNotNull($vp2);
$this->assertEquals("New title", $vp1->Title);
$this->assertEquals("New title", $vp2->Title);
$this->assertEquals("New menutitle", $vp1->MenuTitle);
$this->assertEquals("New menutitle", $vp2->MenuTitle);
$this->assertEquals("<p>New content</p>", $vp1->Content);
$this->assertEquals("<p>New content</p>", $vp2->Content);
Versioned::reading_stage("Stage");
}
示例6: setUp
public function setUp()
{
parent::setUp();
$this->logInWithPermission('ADMIN');
Versioned::reading_stage('Stage');
// Set backend root to /ImageTest
AssetStoreTest_SpyStore::activate('FileTest');
// Create a test folders for each of the fixture references
$folderIDs = $this->allFixtureIDs('Folder');
foreach ($folderIDs as $folderID) {
$folder = DataObject::get_by_id('Folder', $folderID);
$filePath = ASSETS_PATH . '/FileTest/' . $folder->getFilename();
SS_Filesystem::makeFolder($filePath);
}
// Create a test files for each of the fixture references
$fileIDs = $this->allFixtureIDs('File');
foreach ($fileIDs as $fileID) {
$file = DataObject::get_by_id('File', $fileID);
$root = ASSETS_PATH . '/FileTest/';
if ($folder = $file->Parent()) {
$root .= $folder->getFilename();
}
$path = $root . substr($file->getHash(), 0, 10) . '/' . basename($file->getFilename());
SS_Filesystem::makeFolder(dirname($path));
$fh = fopen($path, "w+");
fwrite($fh, str_repeat('x', 1000000));
fclose($fh);
}
// Conditional fixture creation in case the 'cms' module is installed
if (class_exists('ErrorPage')) {
$page = new ErrorPage(array('Title' => 'Page not Found', 'ErrorCode' => 404));
$page->write();
$page->publish('Stage', 'Live');
}
}
示例7: 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);
}
示例8: run
/**
* @param SS_HTTPRequest $request
* @return SS_HTTPResponse
*/
public function run($request)
{
parent::run($request);
// Disable filters
if (class_exists('ContentNotifierExtension')) {
ContentNotifierExtension::disable_filtering();
}
if (class_exists('Post')) {
Config::inst()->update('Post', 'allow_reading_spam', true);
}
// Init tasks
$taskGroup = $request->getVar('tasks') ?: 'tasks';
$this->message("Beginning import tasks {$taskGroup}");
$this->connectToRemoteSite();
Versioned::reading_stage('Stage');
// Check if we only want to do a single step
if ($pass = $request->requestVar('pass')) {
$this->message("Resuming at {$pass} pass");
switch ($pass) {
case 'identify':
$this->identifyPass($taskGroup);
return;
case 'import':
$this->importPass($taskGroup);
return;
case 'link':
$this->linkPass($taskGroup);
return;
}
}
$this->identifyPass($taskGroup);
$this->importPass($taskGroup);
$this->linkPass($taskGroup);
}
示例9: 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;
}
示例10: handleRequest
function handleRequest($request)
{
Versioned::reading_stage('Live');
$restfulserver = new RestfulServer();
$response = $restfulserver->handleRequest($request);
return $response;
}
示例11: updateDynamicListCMSFields
public function updateDynamicListCMSFields($fields)
{
// Make sure the draft records are being looked at.
$stage = Versioned::current_stage();
Versioned::reading_stage('Stage');
$used = EditableFormField::get()->filter(array('ClassName:PartialMatch' => 'DynamicList'));
// Determine whether this dynamic list is being used anywhere.
$found = array();
foreach ($used as $field) {
// This information is stored using a serialised list, therefore we need to iterate through.
if ($field->getSetting('ListTitle') === $this->owner->Title) {
// Make sure there are no duplicates recorded.
if (!isset($found[$field->ParentID]) && ($form = UserDefinedForm::get()->byID($field->ParentID))) {
$found[$field->ParentID] = "<a href='{$form->CMSEditLink()}'>{$form->Title}</a>";
}
}
}
// Display whether there were any dynamic lists found on user defined forms.
if (count($found)) {
$fields->removeByName('UsedOnHeader');
$fields->addFieldToTab('Root.Main', HeaderField::create('UsedOnHeader', 'Used On', 5));
}
$display = count($found) ? implode('<br>', $found) : 'This dynamic list is <strong>not</strong> used.';
$fields->removeByName('UsedOn');
$fields->addFieldToTab('Root.Main', LiteralField::create('UsedOn', '<div>' . $display . '</div>'));
Versioned::reading_stage($stage);
}
示例12: setUp
public function setUp()
{
parent::setUp();
$this->logInWithPermission('ADMIN');
Versioned::reading_stage('Stage');
// Set backend root to /AssetFieldTest
AssetStoreTest_SpyStore::activate('AssetFieldTest');
$create = function ($path) {
Filesystem::makeFolder(dirname($path));
$fh = fopen($path, "w+");
fwrite($fh, str_repeat('x', 1000000));
fclose($fh);
};
// Write all DBFile references
foreach (AssetFieldTest_Object::get() as $object) {
$path = AssetStoreTest_SpyStore::getLocalPath($object->File);
$create($path);
}
// Create a test files for each of the fixture references
$files = File::get()->exclude('ClassName', 'Folder');
foreach ($files as $file) {
$path = AssetStoreTest_SpyStore::getLocalPath($file);
$create($path);
}
}
示例13: sourceRecords
/**
* This returns the workflow requests outstanding for this user.
* It does one query against draft for change requests, and another
* request against live for the deletion requests (which are not in draft
* any more), and merges the result sets together.
*/
function sourceRecords($params)
{
increase_time_limit_to(120);
$currentStage = Versioned::current_stage();
$changes = WorkflowTwoStepRequest::get_by_author('WorkflowPublicationRequest', Member::currentUser(), array('AwaitingApproval'));
if ($changes) {
foreach ($changes as $change) {
$change->RequestType = "Publish";
}
}
Versioned::reading_stage(Versioned::get_live_stage());
$deletions = WorkflowTwoStepRequest::get_by_author('WorkflowDeletionRequest', Member::currentUser(), array('AwaitingApproval'));
if ($deletions) {
foreach ($deletions as $deletion) {
$deletion->RequestType = "Deletion";
}
}
if ($changes && $deletions) {
$changes->merge($deletions);
} else {
if ($deletions) {
$changes = $deletions;
}
}
return $changes;
}
示例14: publish
/**
* When an error page is published, create a static HTML page with its
* content, so the page can be shown even when SilverStripe is not
* functioning correctly before publishing this page normally.
* @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
* @param string $toStage Place to copy to. Must be a stage name.
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
*/
function publish($fromStage, $toStage, $createNewVersion = false)
{
// Temporarily log out when producing this page
$loggedInMember = Member::currentUser();
Session::clear("loggedInAs");
$alc_enc = isset($_COOKIE['alc_enc']) ? $_COOKIE['alc_enc'] : null;
Cookie::set('alc_enc', null);
$oldStage = Versioned::current_stage();
// Run the page
Requirements::clear();
$controller = new ErrorPage_Controller($this);
$errorContent = $controller->run(array())->getBody();
if (!file_exists("../assets")) {
mkdir("../assets", 02775);
}
if ($fh = fopen("../assets/error-{$this->ErrorCode}.html", "w")) {
fwrite($fh, $errorContent);
fclose($fh);
}
// Restore the version we're currently connected to.
Versioned::reading_stage($oldStage);
// Log back in
if ($loggedInMember) {
Session::set("loggedInAs", $loggedInMember->ID);
}
if (isset($alc_enc)) {
Cookie::set('alc_enc', $alc_enc);
}
return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
}
示例15: 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;
}