/**
  * @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, 1000, 1000, $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);
     }
 }
 /**
  * Gets the patch as zip package from gerrit
  *
  * @param int $patchId
  * @return bool|string
  * @throws \TYPO3\Flow\Utility\Exception
  */
 public function getPatchFromGerrit($patchId)
 {
     $uri = sprintf($this->gerritApiPattern, $patchId, 'revisions/current/patch?zip');
     $outputDirectory = Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'GerritPatches'));
     Files::createDirectoryRecursively($outputDirectory);
     $outputZipFilePath = Files::concatenatePaths(array($outputDirectory, $patchId . '.zip'));
     $httpClient = new Client();
     $httpClient->get($uri)->setResponseBody($outputZipFilePath)->send();
     $zip = new \ZipArchive();
     $zip->open($outputZipFilePath);
     $patchFile = $zip->getNameIndex(0);
     $zip->extractTo($outputDirectory);
     $zip->close();
     Files::unlink($outputZipFilePath);
     return Files::concatenatePaths(array($outputDirectory, $patchFile));
 }
示例#3
0
 /**
  * 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));
 }
示例#4
0
 /**
  * Releases the lock
  *
  * @return boolean TRUE on success, FALSE otherwise
  */
 public function release()
 {
     $success = true;
     if (is_resource($this->filePointer)) {
         if (flock($this->filePointer, LOCK_UN) === false) {
             $success = false;
         }
         fclose($this->filePointer);
         Files::unlink($this->lockFileName);
     }
     return $success;
 }
 /**
  * @test
  * @outputBuffering enabled
  *     ... because the chmod call in ResourceManager emits a warning making this fail in strict mode
  */
 public function unlinkReturnsFalseIfSpecifiedPathDoesNotExist()
 {
     $this->assertFalse(Files::unlink('NonExistingPath'));
 }
 /**
  * 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 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), 1416244512);
     }
     if (!file_exists(dirname($targetPathAndFilename))) {
         Files::createDirectoryRecursively(dirname($targetPathAndFilename));
     }
     try {
         if (Files::is_link($targetPathAndFilename)) {
             Files::unlink($targetPathAndFilename);
         }
         $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), 1416244515, isset($exception) ? $exception : null);
     }
     $this->systemLogger->log(sprintf('FileSystemSymlinkTarget: Published directory. (target: %s, file: %s)', $this->name, $relativeTargetPathAndFilename), LOG_DEBUG);
 }
 /**
  * Flush all caches
  *
  * The flush command flushes all caches (including code caches) which have been
  * registered with Flow's Cache Manager. It also removes any session data.
  *
  * If fatal errors caused by a package prevent the compile time bootstrap
  * from running, the removal of any temporary data can be forced by specifying
  * the option <b>--force</b>.
  *
  * This command does not remove the precompiled data provided by frozen
  * packages unless the <b>--force</b> option is used.
  *
  * @param boolean $force Force flushing of any temporary data
  * @return void
  * @see typo3.flow:cache:warmup
  * @see typo3.flow:package:freeze
  * @see typo3.flow:package:refreeze
  */
 public function flushCommand($force = FALSE)
 {
     // Internal note: the $force option is evaluated early in the Flow
     // bootstrap in order to reliably flush the temporary data before any
     // other code can cause fatal errors.
     $this->cacheManager->flushCaches();
     $dataTemporaryPath = $this->environment->getPathToTemporaryDirectory();
     \TYPO3\Flow\Utility\Files::unlink($dataTemporaryPath . 'AvailableProxyClasses.php');
     $this->outputLine('Flushed all caches for "' . $this->bootstrap->getContext() . '" context.');
     if ($this->lockManager->isSiteLocked()) {
         $this->lockManager->unlockSite();
     }
     $frozenPackages = array();
     foreach (array_keys($this->packageManager->getActivePackages()) as $packageKey) {
         if ($this->packageManager->isPackageFrozen($packageKey)) {
             $frozenPackages[] = $packageKey;
         }
     }
     if ($frozenPackages !== array()) {
         $this->outputFormatted(PHP_EOL . 'Please note that the following package' . (count($frozenPackages) === 1 ? ' is' : 's are') . ' currently frozen: ' . PHP_EOL);
         $this->outputFormatted(implode(PHP_EOL, $frozenPackages) . PHP_EOL, array(), 2);
         $message = 'As code and configuration changes in these packages are not detected, the application may respond ';
         $message .= 'unexpectedly if modifications were done anyway or the remaining code relies on these changes.' . PHP_EOL . PHP_EOL;
         $message .= 'You may call <b>package:refreeze all</b> in order to refresh frozen packages or use the <b>--force</b> ';
         $message .= 'option of this <b>cache:flush</b> command to flush caches if Flow becomes unresponsive.' . PHP_EOL;
         $this->outputFormatted($message, array($frozenPackages));
     }
     $this->sendAndExit(0);
 }