/** * Initializes this resource publishing target * * @return void * @throws Exception */ public function initializeObject() { foreach ($this->options as $key => $value) { $isOptionSet = $this->setOption($key, $value); if (!$isOptionSet) { throw new Exception(sprintf('An unknown option "%s" was specified in the configuration of a resource FileSystemTarget. Please check your settings.', $key), 1436962549); } } if (!is_writable($this->path)) { @Files::createDirectoryRecursively($this->path); } if (!is_dir($this->path) && !is_link($this->path)) { throw new Exception('The directory "' . $this->path . '" which was configured as a publishing target does not exist and could not be created.', 1436962550); } if (!is_writable($this->path)) { throw new Exception('The directory "' . $this->path . '" which was configured as a publishing target is not writable.', 1436962551); } }
/** * Publishes the specified directory to this target, with the given relative path. * * @param string $sourcePath Absolute path to the source directory * @param string $relativeTargetPathAndFilename relative path and filename in the target directory * @throws Exception * @return void */ protected function publishDirectory($sourcePath, $relativeTargetPathAndFilename) { $targetPathAndFilename = $this->path . $relativeTargetPathAndFilename; if (@stat($sourcePath) === FALSE) { throw new Exception(sprintf('Could not publish directory "%s" into resource publishing target "%s" because the source is not accessible (file stat failed).', $sourcePath, $this->name), 1436962555); } if (!file_exists(dirname($targetPathAndFilename))) { Files::createDirectoryRecursively(dirname($targetPathAndFilename)); } try { if ($this->relativeSymlinks) { $result = Files::createRelativeSymlink($sourcePath, $targetPathAndFilename); } else { $temporaryTargetPathAndFilename = uniqid($targetPathAndFilename . '.') . '.tmp'; symlink($sourcePath, $temporaryTargetPathAndFilename); $result = rename($temporaryTargetPathAndFilename, $targetPathAndFilename); } } catch (\Exception $exception) { $result = FALSE; } if ($result === FALSE) { throw new Exception(sprintf('Could not publish "%s" into resource publishing target "%s" because the source directory could not be symlinked at target location.', $sourcePath, $this->name), 1436962556, isset($exception) ? $exception : NULL); } $this->systemLogger->log(sprintf('FileSystemSymlinkTarget: Published directory. (target: %s, file: %s)', $this->name, $relativeTargetPathAndFilename), LOG_DEBUG); }