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;
 }
 /**
  * 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());
     }
 }
 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;
 }
 /**
  * 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;
 }
 /**
  * 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");
 }
 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');
     }
 }
 /**
  *	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);
 }
 /**
  * @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);
 }
Exemplo n.º 9
0
	function handleRequest(SS_HTTPRequest $request, DataModel $model) {
		$this->setModel($model);
		Versioned::reading_stage('Live');
		$restfulserver = new RestfulServer();
		$response = $restfulserver->handleRequest($request, $model);
		return $response;
	}
 function handleRequest($request)
 {
     Versioned::reading_stage('Live');
     $restfulserver = new RestfulServer();
     $response = $restfulserver->handleRequest($request);
     return $response;
 }
 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);
 }
 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);
     }
 }
 /**
  * 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;
 }
Exemplo n.º 14
0
 /**
  * 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);
 }
 /**
  * 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;
 }
Exemplo n.º 16
0
 protected function findOldPage($urlSegment)
 {
     // Build the query by  replacing `SiteTree` with `SiteTree_versions` in a regular query.
     // Note that this should *really* be handled by a more full-featured data mapper; as it stands
     // this is a bit of a hack.
     $origStage = Versioned::current_stage();
     Versioned::reading_stage('Stage');
     $versionedQuery = singleton('SiteTree')->extendedSQL('');
     Versioned::reading_stage($origStage);
     foreach ($versionedQuery->from as $k => $v) {
         $versionedQuery->renameTable($k, $k . '_versions');
     }
     $versionedQuery->select = array("`SiteTree_versions`.RecordID");
     $versionedQuery->where[] = "`SiteTree_versions`.`WasPublished` = 1 AND `URLSegment` = '{$urlSegment}'";
     $versionedQuery->orderby = '`LastEdited` DESC, `SiteTree_versions`.`WasPublished`';
     $versionedQuery->limit = 1;
     $result = $versionedQuery->execute();
     if ($result->numRecords() == 1 && ($redirectPage = $result->nextRecord())) {
         $redirectObj = DataObject::get_by_id('SiteTree', $redirectPage['RecordID']);
         if ($redirectObj) {
             // Double-check by querying this page in the same way that getNestedController() does.  This
             // will prevent query muck-ups from modules such as subsites
             $doubleCheck = SiteTree::get_by_url($redirectObj->URLSegment);
             if ($doubleCheck) {
                 return $redirectObj;
             }
         }
     }
     return false;
 }
Exemplo n.º 17
0
 /**
  * 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();
 }
 protected function importDataObject($item, $parentObject, $duplicateStrategy)
 {
     Versioned::reading_stage('Stage');
     $ignore = array('ClassName' => true, 'Status' => true, 'ID' => true);
     $cls = 'Page';
     if (strlen($item->ClassName) && ClassInfo::exists($item->ClassName)) {
         $cls = $item->ClassName;
     }
     if ($cls == 'SiteTree') {
         $cls = 'Page';
     }
     $obj = new $cls();
     $obj->Version = 1;
     if ($parentObject && $parentObject->hasExtension('Hierarchy') && $obj->hasExtension('Hierarchy')) {
         if ($cls == "SilverStripeContentItem" && $item->Title == "Files") {
             $fakeId = '0-File';
             $fakeFiles = new SilverStripeContentItem($item->source, $fakeId);
             $fakeFiles->Title = 'Files';
             $fakeFiles->ID = $item->ID . ExternalContent::ID_SEPARATOR . $fakeId;
             return $fakeFiles;
         }
         $filter = '"Title" = \'' . Convert::raw2sql($item->Title) . '\' AND "ParentID" = ' . (int) $parentObject->ID;
         $existing = DataObject::get_one($cls, $filter);
         if ($existing && $existing->exists()) {
             if ($duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) {
                 $obj = $existing;
                 $obj->ClassName = $cls;
             } else {
                 if ($duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
                     return $existing;
                 }
             }
         }
     }
     foreach ($item->getRemoteProperties() as $field => $value) {
         if (!isset($ignore[$field]) && $obj->hasField($field)) {
             $obj->{$field} = $value;
         }
     }
     $obj->RemoteNodeId = $item->getSS_ID();
     $obj->RemoteSystemId = $item->getSource()->ID;
     $obj->ParentID = $parentObject->ID;
     if ($parentObject->SubsiteID) {
         $obj->SubsiteID = $parentObject->SubsiteID;
     }
     $obj->write();
     // Adds proper support for 2.4 so everything doesn't get published since
     // the built in API will show unpublished pages. 3.x doesn't have this issue
     $itemPublished = false;
     if (isset($item->Status) && $item->Status == "Published") {
         $itemPublished = true;
     }
     // Changed here for $itemPublished OR $parentObject->isPublished to account for the 2.4 issue
     if ($parentObject->ClassName != "Folder" && $obj->hasExtension('Versioned') && ($itemPublished || $parentObject->isPublished())) {
         $obj->publish('Stage', 'Live');
     }
     return $obj;
 }
 /**
  * Reprocess any needed fields
  */
 public function process()
 {
     Versioned::reading_stage('Stage');
     $obj = $this->getObject();
     if ($obj) {
         $obj->rebuildVFI();
     }
     $this->isComplete = true;
 }
 function init()
 {
     parent::init();
     Versioned::reading_stage('live');
     $canAccess = Director::isDev() || Director::is_cli() || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this);
     }
 }
 public function init()
 {
     parent::init();
     //if versioned we need to tell ModelAdmin to read from stage
     if (Singleton($this->modelClass)->isVersioned) {
         Versioned::reading_stage('Stage');
     }
     //Styling for preview links and status
     Requirements::CSS(MOD_DOAP_DIR . '/css/dataobjectaspageadmin.css');
 }
 /**
  * Reprocess any needed fields
  */
 public function process()
 {
     Versioned::reading_stage('Stage');
     /** @var DataObject|VirtualFieldIndex $obj */
     $obj = $this->getObject();
     if ($obj) {
         $obj->rebuildVFI();
     }
     $this->isComplete = true;
 }
 public function up()
 {
     foreach (['Stage', 'Live'] as $stage) {
         Versioned::reading_stage($stage);
         $pages = SiteTree::get()->where("\n\t\t\t\tURLSegment LIKE '%-ja-jp' OR\n\t\t\t\tURLSegment LIKE '%-zh-cmn' OR\n\t\t\t\tURLSegment LIKE '%-de-DE' OR\n\t\t\t\tURLSegment LIKE '%-es-ES'\n\t\t\t");
         $count = $pages->count();
         $pages->removeAll();
         echo "Deleted {$count} pages from {$stage}.\n";
     }
 }
 /**
  * Migrate a versioned field in a single stage
  *
  * @param EditableFormField $field
  * @param stage $stage
  */
 protected function upgradeFieldInStage(EditableFormField $field, $stage)
 {
     Versioned::reading_stage($stage);
     // Migrate field rules
     $this->migrateRules($field, $stage);
     // Migrate custom settings
     $this->migrateCustomSettings($field, $stage);
     // Flag as migrated
     $field->Migrated = true;
     $field->write();
 }
 /**
  * @param array $params
  *
  * @return SS_List
  */
 public function sourceRecords($params = array())
 {
     Versioned::reading_stage("Stage");
     $records = SiteTree::get();
     $compatibility = ContentReviewCompatability::start();
     if (empty($params["ReviewDateBefore"]) && empty($params["ReviewDateAfter"])) {
         // If there's no review dates set, default to all pages due for review now
         $reviewDate = new Zend_Date(SS_Datetime::now()->Format("U"));
         $reviewDate->add(1, Zend_Date::DAY);
         $records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString("YYYY-MM-dd")));
     } else {
         // Review date before
         if (!empty($params['ReviewDateBefore'])) {
             // TODO Get value from DateField->dataValue() once we have access to form elements here
             $reviewDate = new Zend_Date($params["ReviewDateBefore"], Config::inst()->get("i18n", "date_format"));
             $reviewDate->add(1, Zend_Date::DAY);
             $records = $records->where(sprintf("\"NextReviewDate\" < '%s'", $reviewDate->toString("YYYY-MM-dd")));
         }
         // Review date after
         if (!empty($params["ReviewDateAfter"])) {
             // TODO Get value from DateField->dataValue() once we have access to form elements here
             $reviewDate = new Zend_Date($params["ReviewDateAfter"], Config::inst()->get("i18n", "date_format"));
             $records = $records->where(sprintf("\"NextReviewDate\" >= '%s'", $reviewDate->toString("YYYY-MM-dd")));
         }
     }
     // Show virtual pages?
     if (empty($params["ShowVirtualPages"])) {
         $virtualPageClasses = ClassInfo::subclassesFor("VirtualPage");
         $records = $records->where(sprintf("\"SiteTree\".\"ClassName\" NOT IN ('%s')", implode("','", array_values($virtualPageClasses))));
     }
     // Owner dropdown
     if (!empty($params["ContentReviewOwner"])) {
         $ownerNames = Convert::raw2sql($params["ContentReviewOwner"]);
         $records = $records->filter("OwnerNames:PartialMatch", $ownerNames);
     }
     // Only show pages assigned to the current user?
     // This come last because it transforms $records to an ArrayList.
     if (!empty($params["OnlyMyPages"])) {
         $currentUser = Member::currentUser();
         $records = $records->filterByCallback(function ($page) use($currentUser) {
             $options = $page->getOptions();
             foreach ($options->ContentReviewOwners() as $owner) {
                 if ($currentUser->ID == $owner->ID) {
                     return true;
                 }
             }
             return false;
         });
     }
     ContentReviewCompatability::done($compatibility);
     return $records;
 }
 public function onBeforeDelete()
 {
     if (Widget::has_extension('Versioned')) {
         $currentStage = Versioned::current_stage();
         Versioned::reading_stage('Stage');
         parent::onBeforeDelete();
         Versioned::reading_stage('Live');
         parent::onBeforeDelete();
         Versioned::reading_stage($currentStage);
     } else {
         parent::onBeforeDelete();
     }
 }
 function setUp()
 {
     parent::setUp();
     // Publish all but the embargoed content and switch view to Live
     $pages = array('home', 'about', 'staff', 'staffduplicate', 'products', 'product1', 'product2', 'contact', 'virtuals');
     Versioned::reading_stage('Stage');
     $this->logInWithPermission('ADMIN');
     foreach ($pages as $page) {
         $this->assertTrue($this->objFromFixture('Page', $page)->doPublish());
     }
     $this->get('Security/logout');
     Versioned::reading_stage('Live');
 }
Exemplo n.º 28
0
 /**
  * @return Form
  **/
 public function getEditForm($id = null, $fields = null)
 {
     Versioned::reading_stage('Stage');
     $form = parent::getEditForm($id, $fields);
     if ($blockGridField = $form->Fields()->fieldByName('Block')) {
         $blockGridField->setConfig(GridFieldConfig_BlockManager::create(true, true, false));
         $config = $blockGridField->getConfig();
         $dcols = $config->getComponentByType('GridFieldDataColumns');
         $dfields = $dcols->getDisplayFields($blockGridField);
         unset($dfields['BlockArea']);
         $dcols->setDisplayFields($dfields);
     }
     return $form;
 }
 /**
  * @return Form
  */
 public function ItemEditForm()
 {
     if (!$this->record->isPublished()) {
         Versioned::reading_stage('Stage');
     }
     if (!$this->record->ParentID) {
         // set a parent id for the record, even if it will change
         $parents = $this->record->getCatalogParents();
         if ($parents && $parents->count()) {
             $this->record->ParentID = $parents->first()->ID;
         }
     }
     return parent::ItemEditForm();
 }
Exemplo n.º 30
0
	/**
	 * Confirm that DataObject::get_one() gets records from SiteTree_Live
	 */
	function testGetOneFromLive() {
		$s = new SiteTree();
		$s->Title = "V1";
		$s->URLSegment = "get-one-test-page";
		$s->write();
		$s->publish("Stage", "Live");
		$s->Title = "V2";
		$s->write();
		
		$oldStage = Versioned::current_stage();
		Versioned::reading_stage('Live');
		
		$checkSiteTree = DataObject::get_one("SiteTree", "URLSegment = 'get-one-test-page'");
		$this->assertEquals("V1", $checkSiteTree->Title);
	}