本文整理汇总了PHP中Versioned::get_reading_mode方法的典型用法代码示例。如果您正苦于以下问题:PHP Versioned::get_reading_mode方法的具体用法?PHP Versioned::get_reading_mode怎么用?PHP Versioned::get_reading_mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Versioned
的用法示例。
在下文中一共展示了Versioned::get_reading_mode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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: 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);
}
示例4: get_future_datetime
/**
* Return the currently viewed future datetime
*/
static function get_future_datetime()
{
$parts = explode('.', Versioned::get_reading_mode());
if ($parts[0] == 'FutureState') {
return $parts[1];
}
}
示例5: 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();
}
示例6: onBeforeWrite
public function onBeforeWrite()
{
parent::onBeforeWrite();
if (empty($this->byPass)) {
$this->readmode = Versioned::get_reading_mode();
Versioned::set_reading_mode('Stage.Stage');
}
}
示例7: getGroupedGames
public function getGroupedGames()
{
// show all if in draft mode
$mode = Versioned::get_reading_mode();
if ($mode == 'Stage.Stage') {
$items = GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID))->sort('Session'));
} else {
$items = GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID, 'Status' => true))->sort('Session'));
}
return $items;
}
示例8: sourceRecords
/**
* Returns an array with 2 elements, one with a list of Page on the site (and all subsites if
* applicable) and another with files.
*
* @return array
*/
public function sourceRecords()
{
if (class_exists('Subsite') && Subsite::get()->count() > 0) {
$origMode = Versioned::get_reading_mode();
Versioned::set_reading_mode('Stage.Stage');
$items = array('Pages' => Subsite::get_from_all_subsites('SiteTree'), 'Files' => Subsite::get_from_all_subsites('File'));
Versioned::set_reading_mode($origMode);
return $items;
} else {
return array('Pages' => Versioned::get_by_stage('SiteTree', 'Stage'), 'Files' => File::get());
}
}
示例9: check
/**
* @inheritdoc
*
* @return array
*/
function check()
{
$origStage = Versioned::get_reading_mode();
Versioned::set_reading_mode('Live');
$files = $this->getFiles();
if ($files) {
$fileTypeValidateFunc = $this->fileTypeValidateFunc;
if (method_exists($this, $fileTypeValidateFunc)) {
$invalidFiles = array();
$validFiles = array();
foreach ($files as $file) {
if ($this->{$fileTypeValidateFunc}($file)) {
$validFiles[] = $file;
} else {
$invalidFiles[] = $file;
}
}
// If at least one file was valid, count as passed
if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
$validFileList = "\n";
foreach ($validFiles as $vf) {
$validFileList .= $vf . "\n";
}
if ($fileTypeValidateFunc == 'noVidation') {
$checkReturn = array(EnvironmentCheck::OK, sprintf('At least these file(s) accessible: %s', $validFileList));
} else {
$checkReturn = array(EnvironmentCheck::OK, sprintf('At least these file(s) passed file type validate function "%s": %s', $fileTypeValidateFunc, $validFileList));
}
} else {
if (count($invalidFiles) == 0) {
$checkReturn = array(EnvironmentCheck::OK, 'All files valideted');
} else {
$invalidFileList = "\n";
foreach ($invalidFiles as $vf) {
$invalidFileList .= $vf . "\n";
}
if ($fileTypeValidateFunc == 'noVidation') {
$checkReturn = array(EnvironmentCheck::ERROR, sprintf('File(s) not accessible: %s', $invalidFileList));
} else {
$checkReturn = array(EnvironmentCheck::ERROR, sprintf('File(s) not passing the file type validate function "%s": %s', $fileTypeValidateFunc, $invalidFileList));
}
}
}
} else {
$checkReturn = array(EnvironmentCheck::ERROR, sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc));
}
} else {
$checkReturn = array(EnvironmentCheck::ERROR, sprintf("No files accessible at path %s", $this->path));
}
Versioned::set_reading_mode($origStage);
return $checkReturn;
}
开发者ID:helpfulrobot,项目名称:silverstripe-environmentcheck,代码行数:57,代码来源:FileAccessibilityAndValidationCheck.php
示例10: __construct
public function __construct(Index $index, Query $query, LoggerInterface $logger = null)
{
//Optimise the query by just getting back the ids and types
$query->setFields(array('_id', '_type'));
//If we are in live reading mode, only return published documents
if (\Versioned::get_reading_mode() == \Versioned::DEFAULT_MODE) {
$publishedFilter = new Query\BoolQuery();
$publishedFilter->addMust(new Query\Term([Searchable::$published_field => 'true']));
$query->setPostFilter($publishedFilter);
}
$this->index = $index;
$this->query = $query;
$this->logger = $logger;
}
示例11: getAllLivePages
/**
*
* @return DataList
*/
protected function getAllLivePages($subsiteID = 0)
{
ini_set('memory_limit', '200M');
$oldMode = Versioned::get_reading_mode();
if (class_exists('Subsite')) {
Subsite::disable_subsite_filter(true);
}
Versioned::reading_stage('Live');
$pages = DataObject::get("SiteTree");
Versioned::set_reading_mode($oldMode);
if (class_exists('Subsite')) {
return $pages->filter(array('SubsiteID' => $subsiteID));
}
return $pages;
}
示例12: 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();
}
}
示例13: doSavePost
public function doSavePost($data, $form)
{
$post = false;
if (isset($data['ID']) && $data['ID']) {
$post = BlogPost::get()->byID($data['ID']);
}
if (!$post) {
$post = BlogPost::create();
}
$form->saveInto($post);
$post->ParentID = $this->owner->ID;
$this->owner->extend("onBeforeSavePost", $blogentry);
$oldMode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
$post->write();
$post->publish("Stage", "Live");
Versioned::set_reading_mode($oldMode);
$this->owner->extend("onAfterSavePost", $post);
$this->owner->redirect($this->owner->Link());
}
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-blog-frontend,代码行数:20,代码来源:BlogFrontEndForm_BlogController.php
示例14: setUp
public function setUp()
{
parent::setUp();
if (!class_exists('Phockito')) {
$this->skipTest = true;
return $this->markTestSkipped("These tests need the Phockito module installed to run");
}
// Check versioned available
if (!class_exists('Versioned')) {
$this->skipTest = true;
return $this->markTestSkipped('The versioned decorator is not installed');
}
if (self::$index === null) {
self::$index = singleton('SolrVersionedTest_Index');
}
SearchUpdater::bind_manipulation_capture();
Config::nest();
Config::inst()->update('Injector', 'SearchUpdateProcessor', array('class' => 'SearchUpdateImmediateProcessor'));
FullTextSearch::force_index_list(self::$index);
SearchUpdater::clear_dirty_indexes();
$this->oldMode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
}
示例15: updateTagging
/**
* Update the searchable content tagging for a specific fusion tag.
*
* @parameter <{FUSION_TAG_ID}> integer
*/
public function updateTagging($fusionID)
{
// Determine any data objects with the tagging extension.
$classes = ClassInfo::subclassesFor('DataObject');
unset($classes['DataObject']);
$configuration = Config::inst();
foreach ($classes as $class) {
// Determine the specific data object extensions.
$extensions = $configuration->get($class, 'extensions', Config::UNINHERITED);
if (is_array($extensions) && in_array('TaggingExtension', $extensions)) {
// Determine whether this fusion tag is being used.
$mode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
$objects = $class::get()->filter('FusionTags.ID', $fusionID);
// Update the searchable content tagging for these data objects.
if ($class::has_extension($class, 'Versioned')) {
// These data objects are versioned.
foreach ($objects as $object) {
// Update the staging version.
$object->writeWithoutVersion();
}
Versioned::reading_stage('Live');
$objects = $class::get()->filter('FusionTags.ID', $fusionID);
foreach ($objects as $object) {
// Update the live version.
$object->writeWithoutVersion();
}
} else {
// These data objects are not versioned.
foreach ($objects as $object) {
$object->write();
}
}
Versioned::set_reading_mode($mode);
}
}
}