public function getCDNWriter() { $stores = $this->contentService->getStoreTypes(); if ($stores && isset($stores[$this->getCDNStore()])) { return $this->contentService->getWriter($this->getCDNStore()); } }
/** * Store the contents of a folder on a CDN. * * If processReferences is set, relative URL references are attempted to be * detected and stored remotely as well, with the file to be stored rewritten * to refer to the CDN value. This really is only useful for CSS * * @param string $folder * @param boolean $processReferences */ public function storeThemeFile($toCdn, $file, $forceUpdate = false, $processReferences = false) { $mtime = @filemtime($file); $relativeName = self::CDN_THEME_PREFIX . '/' . $mtime . '/' . trim(str_replace(Director::baseFolder(), '', $file), '/'); if (!$forceUpdate) { // see if the file already exists, if not we do NOT do an update $reader = $this->contentService->findReaderFor($toCdn, $relativeName); if ($reader && $reader->exists()) { return $reader->getURL(); } } $clear = false; if ($processReferences) { $clear = true; $file = $this->processFileReferences($toCdn, $file, $forceUpdate); } // otherwise, lets get a content writer $writer = $this->contentService->getWriter($toCdn); try { $writer->write($file, $relativeName); } catch (Exception $e) { SS_Log::log($e, SS_Log::WARN); } if ($clear && strpos($file, '.cdn') > 0) { @unlink($file); } $id = $writer->getContentId(); return $writer->getReader()->getURL(); }
/** * @return ContentWriter */ protected function getWriter() { $current = $this->currentThemeCdn(); $writer = $this->contentService->getWriter($current->StoreIn); if (!$writer) { throw new Exception("Invalid writer type " . $current->StoreIn); } return $writer; }
/** * @return ContentWriter */ public function writer() { if ($reader = $this->reader()) { return $reader->getWriter(); } $writer = null; if ($this->owner->ParentID) { $writer = $this->owner->Parent()->getCDNWriter(); } else { //get default writer $writer = $this->contentService->getWriter(); } return $writer; }