/** * Checks all stages other than the current stage, and check the visibility * of assets attached to those records. * * @param AssetManipulationList $manipulation Set of manipulations to add assets to */ protected function addAssetsFromOtherStages(AssetManipulationList $manipulation) { // Skip unversioned or unsaved assets if (!$this->isVersioned() || !$this->owner->isInDB()) { return; } // Unauthenticated member to use for checking visibility $baseClass = $this->owner->baseClass(); $baseTable = $this->owner->baseTable(); $filter = array("\"{$baseTable}\".\"ID\"" => $this->owner->ID); $stages = $this->owner->getVersionedStages(); // {@see Versioned::getVersionedStages} foreach ($stages as $stage) { // Skip current stage; These should be handled explicitly if ($stage === Versioned::get_stage()) { continue; } // Check if record exists in this stage $record = Versioned::get_one_by_stage($baseClass, $stage, $filter); if (!$record) { continue; } // Check visibility of this record, and record all attached assets $state = $this->getRecordState($record); $this->addAssetsFromRecord($manipulation, $record, $state); } }
/** * Update filesystem of all children */ public function updateChildFilesystem() { // Don't synchronise on live (rely on publishing instead) if (Versioned::get_stage() === Versioned::LIVE) { return; } $this->flushCache(); // Writing this record should trigger a write (and potential updateFilesystem) on each child foreach ($this->AllChildren() as $child) { $child->write(); } }
/** * This will check if the parent record and/or name do not match the name on the underlying * DBFile record, and if so, copy this file to the new location, and update the record to * point to this new file. * * This method will update the File {@see DBFile} field value on success, so it must be called * before writing to the database * * @return bool True if changed */ public function updateFilesystem() { if (!$this->config()->update_filesystem) { return false; } // Check the file exists if (!$this->File->exists()) { return false; } // Avoid moving files on live; Rely on this being done on stage prior to publish. if (Versioned::get_stage() !== Versioned::DRAFT) { return false; } // Check path updated record will point to // If no changes necessary, skip $pathBefore = $this->File->getFilename(); $pathAfter = $this->generateFilename(); if ($pathAfter === $pathBefore) { return false; } // Copy record to new location via stream $stream = $this->File->getStream(); $this->File->setFromStream($stream, $pathAfter); return true; }
/** * Choose the stage the site is currently on. * * If $_GET['stage'] is set, then it will use that stage, and store it in * the session. * * if $_GET['archiveDate'] is set, it will use that date, and store it in * the session. * * If neither of these are set, it checks the session, otherwise the stage * is set to 'Live'. */ public static function choose_site_stage() { // Check any pre-existing session mode $preexistingMode = Session::get('readingMode'); // Determine the reading mode if (isset($_GET['stage'])) { $stage = ucfirst(strtolower($_GET['stage'])); if (!in_array($stage, array(static::DRAFT, static::LIVE))) { $stage = static::LIVE; } $mode = 'Stage.' . $stage; } elseif (isset($_GET['archiveDate']) && strtotime($_GET['archiveDate'])) { $mode = 'Archive.' . $_GET['archiveDate']; } elseif ($preexistingMode) { $mode = $preexistingMode; } else { $mode = static::DEFAULT_MODE; } // Save reading mode Versioned::set_reading_mode($mode); // Try not to store the mode in the session if not needed if ($preexistingMode && $preexistingMode !== $mode || !$preexistingMode && $mode !== static::DEFAULT_MODE) { Session::set('readingMode', $mode); } if (!headers_sent() && !Director::is_cli()) { if (Versioned::get_stage() == 'Live') { // clear the cookie if it's set if (Cookie::get('bypassStaticCache')) { Cookie::force_expiry('bypassStaticCache', null, null, false, true); } } else { // set the cookie if it's cleared if (!Cookie::get('bypassStaticCache')) { Cookie::set('bypassStaticCache', '1', 0, null, null, false, true); } } } }