/** * @param Thumbnail $thumbnail * @return void * @throws Exception\NoThumbnailAvailableException */ public function refresh(Thumbnail $thumbnail) { $temporaryPathAndFilename = null; try { $filename = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME); $temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy(); $temporaryPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('ProcessedFontThumbnail-') . '.' . $filename . '.jpg'; $width = 1000; $height = 1000; $im = imagecreate($width, $height); $red = imagecolorallocate($im, 0xff, 0xff, 0xff); $black = imagecolorallocate($im, 0x0, 0x0, 0x0); imagefilledrectangle($im, 0, 0, $width, $height, $red); imagefttext($im, 48, 0, 80, 150, $black, $temporaryLocalCopyFilename, 'Neos Font Preview'); imagefttext($im, 32, 0, 80, 280, $black, $temporaryLocalCopyFilename, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); imagefttext($im, 32, 0, 80, 360, $black, $temporaryLocalCopyFilename, 'abcdefghijklmopqrstuvwxyz'); imagefttext($im, 32, 0, 80, 440, $black, $temporaryLocalCopyFilename, '1234567890'); imagefttext($im, 32, 0, 80, 560, $black, $temporaryLocalCopyFilename, '+ " * ç % & / ( ) = ? @ €'); imagejpeg($im, $temporaryPathAndFilename); $resource = $this->resourceManager->importResource($temporaryPathAndFilename); $processedImageInfo = $this->resize($thumbnail, $resource); $thumbnail->setResource($processedImageInfo['resource']); $thumbnail->setWidth($processedImageInfo['width']); $thumbnail->setHeight($processedImageInfo['height']); Files::unlink($temporaryPathAndFilename); } catch (\Exception $exception) { Files::unlink($temporaryPathAndFilename); $filename = $thumbnail->getOriginalAsset()->getResource()->getFilename(); $sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1(); $message = sprintf('Unable to generate thumbnail for the given font (filename: %s, SHA1: %s)', $filename, $sha1); throw new Exception\NoThumbnailAvailableException($message, 1433109653, $exception); } }
/** * Removes the specified target file from the public directory * * This method fails silently if the given file could not be unpublished or already didn't exist anymore. * * @param string $relativeTargetPathAndFilename relative path and filename in the target directory * @return void */ protected function unpublishFile($relativeTargetPathAndFilename) { $targetPathAndFilename = $this->path . $relativeTargetPathAndFilename; if (!file_exists($targetPathAndFilename)) { return; } if (!Files::unlink($targetPathAndFilename)) { return; } Files::removeEmptyDirectoriesOnPath(dirname($targetPathAndFilename)); }
/** * Flushes all registered caches * * @param boolean $flushPersistentCaches If set to TRUE, even those caches which are flagged as "persistent" will be flushed * @return void * @api */ public function flushCaches($flushPersistentCaches = false) { $this->createAllCaches(); /** @var FrontendInterface $cache */ foreach ($this->caches as $identifier => $cache) { if (!$flushPersistentCaches && $this->isCachePersistent($identifier)) { continue; } $cache->flush(); } $this->configurationManager->flushConfigurationCache(); $dataTemporaryPath = $this->environment->getPathToTemporaryDirectory(); Files::unlink($dataTemporaryPath . 'AvailableProxyClasses.php'); }
/** * 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 TargetException * @return void */ protected function publishDirectory($sourcePath, $relativeTargetPathAndFilename) { $targetPathAndFilename = $this->path . $relativeTargetPathAndFilename; if (@stat($sourcePath) === false) { throw new TargetException(sprintf('Could not publish directory "%s" into resource publishing target "%s" because the source is not accessible (file stat failed).', $sourcePath, $this->name), 1416244512); } if (!file_exists(dirname($targetPathAndFilename))) { Files::createDirectoryRecursively(dirname($targetPathAndFilename)); } try { if (Files::is_link($targetPathAndFilename)) { Files::unlink($targetPathAndFilename); } 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 TargetException(sprintf('Could not publish "%s" into resource publishing target "%s" because the source directory could not be symlinked at target location.', $sourcePath, $this->name), 1416244515, isset($exception) ? $exception : null); } $this->systemLogger->log(sprintf('FileSystemSymlinkTarget: Published directory. (target: %s, file: %s)', $this->name, $relativeTargetPathAndFilename), LOG_DEBUG); }
/** * @test * @outputBuffering enabled * ... because the chmod call in ResourceManager emits a warning making this fail in strict mode */ public function unlinkReturnsTrueIfSpecifiedPathDoesNotExist() { $this->assertTrue(Files::unlink('NonExistingPath')); }