Pimcore\File::rename PHP Method

rename() public static method

public static rename ( $oldPath, $newPath ) : boolean
$oldPath
$newPath
return boolean
    public static function rename($oldPath, $newPath)
    {
        if (stream_is_local($oldPath) && stream_is_local($newPath)) {
            // rename is only possible if both stream wrapper are the same
            // unfortunately it seems that there's no other alternative for stream_is_local() although it isn't
            // absolutely correct it solves the problem temporary
            $return = rename($oldPath, $newPath, self::getContext());
        } else {
            $return = recursiveCopy($oldPath, $newPath);
            recursiveDelete($oldPath);
        }
        return $return;
    }

Usage Example

Example #1
0
 /**
  * @param null $path
  * @return null|string|void
  * @throws \Exception
  */
 public function getPdf($path = null)
 {
     if ($path) {
         $path = $this->preparePath($path);
     }
     $pdfPath = null;
     if (!$path && $this->path) {
         $path = $this->path;
     }
     try {
         // if the document is already an PDF, delegate the call directly to parent::getPdf() (Ghostscript)
         $pdfPath = parent::getPdf($path);
         return $pdfPath;
     } catch (\Exception $e) {
         // nothing to do, delegate to libreoffice
     }
     $pdfFile = PIMCORE_TEMPORARY_DIRECTORY . "/document-pdf-cache/document_" . md5($path . filemtime($path)) . "__libreoffice.pdf";
     if (!is_dir(dirname($pdfFile))) {
         File::mkdir(dirname($pdfFile));
     }
     $lockKey = "soffice";
     if (!file_exists($pdfFile)) {
         // a list of all available filters is here:
         // http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/config/fragments/filters
         $cmd = self::getLibreOfficeCli() . " --headless --nologo --nofirststartwizard --norestore --convert-to pdf:writer_web_pdf_Export --outdir " . escapeshellarg(PIMCORE_SYSTEM_TEMP_DIRECTORY) . " " . escapeshellarg($path);
         Model\Tool\Lock::acquire($lockKey);
         // avoid parallel conversions
         $out = Console::exec($cmd, PIMCORE_LOG_DIRECTORY . "/libreoffice-pdf-convert.log", 240);
         Model\Tool\Lock::release($lockKey);
         Logger::debug("LibreOffice Output was: " . $out);
         $tmpName = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . preg_replace("/\\." . File::getFileExtension($path) . "\$/", ".pdf", basename($path));
         if (file_exists($tmpName)) {
             File::rename($tmpName, $pdfFile);
             $pdfPath = $pdfFile;
         } else {
             $message = "Couldn't convert document to PDF: " . $path . " with the command: '" . $cmd . "'";
             Logger::error($message);
             throw new \Exception($message);
         }
     } else {
         $pdfPath = $pdfFile;
     }
     return $pdfPath;
 }
All Usage Examples Of Pimcore\File::rename