/**
  * Install package using 'composer require'.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  * @throws \Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pidFile = $input->getOption('pid');
     $require = $input->getOption('require');
     try {
         /**
          * TODO consider direct/programmatic usage of composer/composer package
          * @see https://github.com/composer/composer/issues/1906#issuecomment-51632453
          */
         $composerPath = Console::getExecutable('composer');
         if (!$composerPath) {
             $composerPath = Console::getExecutable('composer.phar');
         }
         if (!$composerPath) {
             throw new \Exception('composer executable not found');
         }
         $command = implode(' ', [$composerPath, 'require -d', PIMCORE_DOCUMENT_ROOT, $require, '2>&1']);
         $output->writeln(sprintf("Installing package <b>%s</b>\n", $require));
         $process = new Process($command);
         $process->setTimeout(0);
         $return = $process->run(function ($type, $data) use($output) {
             $output->write($data);
         });
         if ($return !== 0) {
             $this->writeError('Process finished with code: ' . $return);
         } else {
             $output->writeln('<br><b style="color: #0a0;">Package installed successfully.</b>');
         }
     } catch (\Exception $e) {
         $this->writeError($e->getMessage());
     }
     @unlink($pidFile);
 }
Beispiel #2
0
 /**
  * @param $documentId
  * @param $config
  * @throws \Exception
  */
 public function preparePdfGeneration($documentId, $config)
 {
     $document = $this->getPrintDocument($documentId);
     if (Model\Tool\TmpStore::get($document->getLockKey())) {
         throw new \Exception("Process with given document alredy running.");
     }
     Model\Tool\TmpStore::add($document->getLockKey(), true);
     $jobConfig = new \stdClass();
     $jobConfig->documentId = $documentId;
     $jobConfig->config = $config;
     $this->saveJobConfigObjectFile($jobConfig);
     $this->updateStatus($documentId, 0, "prepare_pdf_generation");
     $args = ["-p " . $jobConfig->documentId];
     $env = \Pimcore\Config::getEnvironment();
     if ($env !== false) {
         $args[] = "--environment=" . $env;
     }
     $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " web2print:pdf-creation " . implode(" ", $args);
     Logger::info($cmd);
     if (!$config['disableBackgroundExecution']) {
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "web2print-output.log");
     } else {
         Processor::getInstance()->startPdfGeneration($jobConfig->documentId);
     }
 }
Beispiel #3
0
 /**
  * @param $path
  */
 public static function optimize($path)
 {
     $format = getimagesize($path);
     if (is_array($format) && array_key_exists("mime", $format)) {
         $format = strtolower(str_replace("image/", "", $format["mime"]));
         if ($format == "png") {
             $optimizer = self::getPngOptimizerCli();
             if ($optimizer) {
                 /*if($optimizer["type"] == "pngquant") {
                                         Console::exec($optimizer["path"] . " --ext xxxoptimized.png " . $path, null, 60);
                                         $newFile = preg_replace("/\.png$/", "", $path);
                                         $newFile .= "xxxoptimized.png";
                 
                                         if(file_exists($newFile)) {
                                             unlink($path);
                                             rename($newFile, $path);
                                         }
                                     } else */
                 if ($optimizer["type"] == "pngcrush") {
                     $newFile = $path . ".xxxoptimized";
                     Console::exec($optimizer["path"] . " " . $path . " " . $newFile, null, 60);
                     if (file_exists($newFile)) {
                         unlink($path);
                         rename($newFile, $path);
                     }
                 }
             }
         } else {
             if ($format == "jpeg") {
                 $optimizer = self::getJpegOptimizerCli();
                 if ($optimizer) {
                     if ($optimizer["type"] == "imgmin") {
                         $newFile = $path . ".xxxoptimized";
                         Console::exec($optimizer["path"] . " " . $path . " " . $newFile, null, 60);
                         if (file_exists($newFile)) {
                             unlink($path);
                             rename($newFile, $path);
                         }
                     } else {
                         if ($optimizer["type"] == "jpegoptim") {
                             $additionalParams = "";
                             if (filesize($path) > 10000) {
                                 $additionalParams = " --all-progressive";
                             }
                             Console::exec($optimizer["path"] . $additionalParams . " -o --strip-all --max=85 " . $path, null, 60);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @param $width
  * @param $height
  * @return $this|Imagick
  */
 public function resize($width, $height)
 {
     if (!$this->isOriginal || !$this->isSvg()) {
         return parent::resize($width, $height);
     }
     $width = (int) $width;
     $height = (int) $height;
     $tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . uniqid() . "_pimcore_image_svg_resize_tmp_file.png";
     $this->tmpFiles[] = $tmpFile;
     Console::exec(self::getBinary() . " -w " . $width . " -h " . $height . " -D -f " . $this->imagePath . " -e " . $tmpFile);
     $this->initImagick($tmpFile);
     return $this;
 }
 /**
  * @param $package
  * @return string
  * @throws \Exception
  */
 public static function installPackage($package)
 {
     $logFile = self::getLogFile();
     $jobId = uniqid();
     $pidFile = self::getPidFile($jobId);
     $console = implode(DIRECTORY_SEPARATOR, [PIMCORE_PATH, 'cli', 'console.php']);
     $cmd = implode(' ', [Console::getPhpCli(), $console, 'manager:require', '-p ' . $pidFile, '-r ' . $package]);
     if (is_file($logFile)) {
         unlink($logFile);
     }
     file_put_contents($pidFile, $jobId);
     Console::execInBackground($cmd, $logFile);
     return $jobId;
 }
Beispiel #6
0
 /**
  * @param $url
  * @param $outputFile
  * @param int $screenWidth
  * @param string $format
  * @return bool
  */
 public static function convert($url, $outputFile, $screenWidth = 1200, $format = "png")
 {
     // add parameter pimcore_preview to prevent inclusion of google analytics code, cache, etc.
     $url .= (strpos($url, "?") ? "&" : "?") . "pimcore_preview=true";
     $arguments = " --width " . $screenWidth . " --format " . $format . " \"" . $url . "\" " . $outputFile;
     // use xvfb if possible
     if ($xvfb = self::getXvfbBinary()) {
         $command = $xvfb . " --auto-servernum --server-args=\"-screen 0, 1280x1024x24\" " . self::getWkhtmltoimageBinary() . " --use-xserver" . $arguments;
     } else {
         $command = self::getWkhtmltoimageBinary() . $arguments;
     }
     Console::exec($command, PIMCORE_LOG_DIRECTORY . "/wkhtmltoimage.log", 60);
     if (file_exists($outputFile) && filesize($outputFile) > 1000) {
         return true;
     }
     return false;
 }
Beispiel #7
0
 /**
  * @param null $page
  * @param null $path
  * @return bool|string
  * @throws \Exception
  */
 public function getText($page = null, $path = null)
 {
     $path = $path ? $this->preparePath($path) : $this->path;
     if ($page || parent::isFileTypeSupported($path)) {
         // for per page extraction we have to convert the document to PDF and extract the text via ghostscript
         return parent::getText($page, $this->getPdf($path));
     } elseif (File::getFileExtension($path)) {
         // if we want to get the text of the whole document, we can use libreoffices text export feature
         $cmd = self::getLibreOfficeCli() . " --headless --nologo --nofirststartwizard --norestore --convert-to txt:Text --outdir " . escapeshellarg(PIMCORE_TEMPORARY_DIRECTORY) . " " . escapeshellarg($path);
         $out = Console::exec($cmd, null, 240);
         Logger::debug("LibreOffice Output was: " . $out);
         $tmpName = PIMCORE_TEMPORARY_DIRECTORY . "/" . preg_replace("/\\." . File::getFileExtension($path) . "\$/", ".txt", basename($path));
         if (file_exists($tmpName)) {
             $text = file_get_contents($tmpName);
             $text = \Pimcore\Tool\Text::convertToUTF8($text);
             unlink($tmpName);
             return $text;
         } else {
             $message = "Couldn't convert document to PDF: " . $path . " with the command: '" . $cmd . "' - now trying to get the text out of the PDF ...";
             Logger::error($message);
             return parent::getText(null, $this->getPdf($path));
         }
     }
     return "";
     // default empty string
 }
Beispiel #8
0
 /**
  *
  */
 public function convert()
 {
     $this->save();
     Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:video-converter " . $this->getProcessId());
 }
Beispiel #9
0
 /**
  * @param $script
  * @param $arguments
  * @param $outputFile
  * @return string
  */
 public static function runPhpScriptInBackground($script, $arguments = "", $outputFile = null)
 {
     $cmd = self::buildPhpScriptCmd($script, $arguments);
     $return = Console::execInBackground($cmd, $outputFile);
     return $return;
 }
 /**
  * Returns a list of all class definitions.
  */
 public function serverInfoAction()
 {
     $this->checkUserPermission("system_settings");
     $systemSettings = \Pimcore\Config::getSystemConfig()->toArray();
     $system = array("currentTime" => time(), "phpCli" => Tool\Console::getPhpCli());
     $pimcoreConstants = array();
     //only Pimcore_ constants -> others might break the \Zend_Encode functionality
     foreach ((array) get_defined_constants() as $constant => $value) {
         if (strpos($constant, 'PIMCORE_') === 0) {
             $pimcoreConstants[$constant] = $value;
         }
     }
     $pimcore = array("version" => \Pimcore\Version::getVersion(), "revision" => \Pimcore\Version::getRevision(), "instanceIdentifier" => $systemSettings["general"]["instanceIdentifier"], "modules" => array(), "constants" => $pimcoreConstants);
     foreach ((array) \Pimcore\API\Plugin\Broker::getInstance()->getModules() as $module) {
         $pimcore["modules"][] = get_class($module);
     }
     $plugins = \Pimcore\ExtensionManager::getPluginConfigs();
     $this->encoder->encode(array("success" => true, "system" => $system, "pimcore" => $pimcore, "plugins" => $plugins));
 }
 public function sendAction()
 {
     $document = Document\Newsletter::getById($this->getParam("id"));
     if (Tool\TmpStore::get($document->getTmpStoreId())) {
         throw new Exception("newsletter sending already in progress, need to finish first.");
     }
     $document = Document\Newsletter::getById($this->getParam("id"));
     Tool\TmpStore::add($document->getTmpStoreId(), ['documentId' => $document->getId(), 'addressSourceAdapterName' => $this->getParam("addressAdapterName"), 'adapterParams' => json_decode($this->getParam("adapterParams"), true), 'inProgress' => false, 'progress' => 0], 'newsletter');
     \Pimcore\Tool\Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:newsletter-document-send " . escapeshellarg($document->getTmpStoreId()) . " " . escapeshellarg(\Pimcore\Tool::getHostUrl()), PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "newsletter-sending-output.log");
     $this->_helper->json(["success" => true]);
 }
Beispiel #12
0
 public static function optimizeJpegoptim($path)
 {
     $bin = \Pimcore\Tool\Console::getExecutable("jpegoptim");
     if ($bin) {
         $newFile = self::getTempFile("jpg");
         $additionalParams = "";
         if (filesize($path) > 10000) {
             $additionalParams = " --all-progressive";
         }
         $content = Console::exec($bin . $additionalParams . " -o --strip-all --max=85 --stdout " . $path, null, 60);
         if ($content) {
             File::put($newFile, $content);
         }
         return $newFile;
     }
     return null;
 }
Beispiel #13
0
 /**
  *
  */
 public function convert()
 {
     $this->save();
     $cmd = Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " internal:video-converter " . $this->getProcessId();
     Console::execInBackground($cmd);
 }
 public function sendAction()
 {
     $letter = Newsletter\Config::getByName($this->getParam("name"));
     if ($letter) {
         Tool\Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:newsletter-send " . escapeshellarg($letter->getName()) . " " . escapeshellarg(Tool::getHostUrl()));
     }
     $this->_helper->json(["success" => true]);
 }
Beispiel #15
0
 /**
  * @return bool
  */
 public static function isComposerAvailable()
 {
     return (bool) \Pimcore\Tool\Console::getExecutable("composer");
 }
Beispiel #16
0
 /**
  * Returns the composite cli script path.
  *
  * @return string
  */
 public function getCompositeScriptPath()
 {
     if (null === $this->compositeScriptPath) {
         $this->compositeScriptPath = Console::getExecutable('composite');
     }
     return $this->compositeScriptPath;
 }
Beispiel #17
0
 /**
  * @param null $page
  * @param null $path
  * @return bool|string
  */
 public function getText($page = null, $path = null)
 {
     try {
         $path = $path ? $path : $this->path;
         $pageRange = "";
         try {
             // first try to use poppler's pdftotext, because this produces more accurate results than the txtwrite device from ghostscript
             if ($page) {
                 $pageRange = "-f " . $page . " -l " . $page . " ";
             }
             $text = Console::exec(self::getPdftotextCli() . " " . $pageRange . $path . " -", null, 120);
         } catch (\Exception $e) {
             // pure ghostscript way
             if ($page) {
                 $pageRange = "-dFirstPage=" . $page . " -dLastPage=" . $page . " ";
             }
             $textFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/pdf-text-extract-" . uniqid() . ".txt";
             Console::exec(self::getGhostscriptCli() . " -dBATCH -dNOPAUSE -sDEVICE=txtwrite " . $pageRange . "-dTextFormat=2 -sOutputFile=" . $textFile . " " . $path, null, 120);
             if (is_file($textFile)) {
                 $text = file_get_contents($textFile);
                 // this is a little bit strange the default option -dTextFormat=3 from ghostscript should return utf-8 but it doesn't
                 // so we use option 2 which returns UCS-2LE and convert it here back to UTF-8 which works fine
                 $text = mb_convert_encoding($text, 'UTF-8', 'UCS-2LE');
                 unlink($textFile);
             }
         }
         return $text;
     } catch (\Exception $e) {
         \Logger::error($e);
         return false;
     }
 }
Beispiel #18
0
 public function downloadImageThumbnailAction()
 {
     $image = Asset\Image::getById($this->getParam("id"));
     $config = null;
     if ($this->getParam("config")) {
         $config = \Zend_Json::decode($this->getParam("config"));
     } elseif ($this->getParam("type")) {
         $predefined = ["web" => ["resize_mode" => "scaleByWidth", "width" => 3500, "dpi" => 72, "format" => "JPEG", "quality" => 85], "print" => ["resize_mode" => "scaleByWidth", "width" => 6000, "dpi" => 300, "format" => "JPEG", "quality" => 95], "office" => ["resize_mode" => "scaleByWidth", "width" => 1190, "dpi" => 144, "format" => "JPEG", "quality" => 90]];
         $config = $predefined[$this->getParam("type")];
     }
     if ($config) {
         $thumbnailConfig = new Asset\Image\Thumbnail\Config();
         $thumbnailConfig->setName("pimcore-download-" . $image->getId() . "-" . md5($this->getParam("config")));
         if ($config["resize_mode"] == "scaleByWidth") {
             $thumbnailConfig->addItem("scaleByWidth", ["width" => $config["width"]]);
         } elseif ($config["resize_mode"] == "scaleByHeight") {
             $thumbnailConfig->addItem("scaleByHeight", ["height" => $config["height"]]);
         } else {
             $thumbnailConfig->addItem("resize", ["width" => $config["width"], "height" => $config["height"]]);
         }
         $thumbnailConfig->setQuality($config["quality"]);
         $thumbnailConfig->setFormat($config["format"]);
         if ($thumbnailConfig->getFormat() == "JPEG") {
             $thumbnailConfig->setPreserveMetaData(true);
             $thumbnailConfig->setPreserveColor(true);
         }
         $thumbnail = $image->getThumbnail($thumbnailConfig);
         $thumbnailFile = $thumbnail->getFileSystemPath();
         $exiftool = \Pimcore\Tool\Console::getExecutable("exiftool");
         if ($thumbnailConfig->getFormat() == "JPEG" && $exiftool && isset($config["dpi"]) && $config["dpi"]) {
             \Pimcore\Tool\Console::exec($exiftool . " -overwrite_original -xresolution=" . $config["dpi"] . " -yresolution=" . $config["dpi"] . " -resolutionunit=inches " . escapeshellarg($thumbnailFile));
         }
         $downloadFilename = str_replace("." . File::getFileExtension($image->getFilename()), "." . $thumbnail->getFileExtension(), $image->getFilename());
         $downloadFilename = strtolower($downloadFilename);
         header('Content-Disposition: attachment; filename="' . $downloadFilename . '"');
         header("Content-Type: " . $thumbnail->getMimeType(), true);
         // we have to clear the stat cache here, otherwise filesize() would return the wrong value
         // the reason is that exiftool modifies the file's size, but PHP doesn't know anything about that
         clearstatcache();
         header("Content-Length: " . filesize($thumbnailFile), true);
         $this->sendThumbnailCacheHeaders();
         while (@ob_end_flush()) {
         }
         flush();
         readfile($thumbnailFile);
         @unlink($thumbnailFile);
         exit;
     }
 }
 public function sendAction()
 {
     $letter = Newsletter\Config::getByName($this->getParam("name"));
     if ($letter) {
         $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " internal:newsletter-send " . escapeshellarg($letter->getName()) . " " . escapeshellarg(Tool::getHostUrl());
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . "/newsletter--" . $letter->getName() . ".log");
     }
     $this->_helper->json(array("success" => true));
 }
Beispiel #20
0
 /**
  * Determines if mbayer html2text is installed (more information at http://www.mbayer.de/html2text/)
  * and uses it to automatically create a text version of the html email
  *
  * @static
  * @return bool
  */
 public static function determineHtml2TextIsInstalled()
 {
     return (bool) \Pimcore\Tool\Console::getExecutable("html2text");
 }
Beispiel #21
0
 public function indexAction()
 {
     $checksPHP = array();
     $checksMySQL = array();
     $checksFS = array();
     $checksApps = array();
     // check for memory limit
     $memoryLimit = ini_get("memory_limit");
     $memoryLimit = filesize2bytes($memoryLimit . "B");
     $state = "ok";
     if ($memoryLimit < 67108000) {
         $state = "error";
     } elseif ($memoryLimit < 134217000) {
         $state = "warning";
     }
     $checksPHP[] = array("name" => "memory_limit (in php.ini)", "link" => "http://www.php.net/memory_limit", "state" => $state);
     // mcrypt
     $checksPHP[] = array("name" => "mcrypt", "link" => "http://www.php.net/mcrypt", "state" => function_exists("mcrypt_encrypt") ? "ok" : "error");
     // pdo_mysql
     $checksPHP[] = array("name" => "PDO_Mysql", "link" => "http://www.php.net/pdo_mysql", "state" => @constant("PDO::MYSQL_ATTR_FOUND_ROWS") ? "ok" : "error");
     // pdo_mysql
     $checksPHP[] = array("name" => "Mysqli", "link" => "http://www.php.net/mysqli", "state" => class_exists("mysqli") ? "ok" : "error");
     // iconv
     $checksPHP[] = array("name" => "iconv", "link" => "http://www.php.net/iconv", "state" => function_exists("iconv") ? "ok" : "error");
     // dom
     $checksPHP[] = array("name" => "dom", "link" => "http://www.php.net/dom", "state" => class_exists("DOMDocument") ? "ok" : "error");
     // simplexml
     $checksPHP[] = array("name" => "SimpleXML", "link" => "http://www.php.net/simplexml", "state" => class_exists("SimpleXMLElement") ? "ok" : "error");
     // gd
     $checksPHP[] = array("name" => "GD", "link" => "http://www.php.net/gd", "state" => function_exists("gd_info") ? "ok" : "error");
     // exif
     $checksPHP[] = array("name" => "EXIF", "link" => "http://www.php.net/exif", "state" => function_exists("exif_read_data") ? "ok" : "error");
     // multibyte support
     $checksPHP[] = array("name" => "Multibyte String (mbstring)", "link" => "http://www.php.net/mbstring", "state" => function_exists("mb_get_info") ? "ok" : "error");
     // file_info support
     $checksPHP[] = array("name" => "File Information (file_info)", "link" => "http://www.php.net/file_info", "state" => function_exists("finfo_open") ? "ok" : "error");
     // zip
     $checksPHP[] = array("name" => "zip", "link" => "http://www.php.net/zip", "state" => class_exists("ZipArchive") ? "ok" : "error");
     // gzip
     $checksPHP[] = array("name" => "zlib / gzip", "link" => "http://www.php.net/zlib", "state" => function_exists("gzcompress") ? "ok" : "error");
     // bzip
     $checksPHP[] = array("name" => "Bzip2", "link" => "http://www.php.net/bzip2", "state" => function_exists("bzcompress") ? "ok" : "error");
     // openssl
     $checksPHP[] = array("name" => "OpenSSL", "link" => "http://www.php.net/openssl", "state" => function_exists("openssl_open") ? "ok" : "error");
     // Imagick
     $checksPHP[] = array("name" => "Imagick", "link" => "http://www.php.net/imagick", "state" => class_exists("Imagick") ? "ok" : "warning");
     // OPcache
     $checksPHP[] = array("name" => "OPcache", "link" => "http://www.php.net/opcache", "state" => function_exists("opcache_reset") ? "ok" : "warning");
     // memcache
     $checksPHP[] = array("name" => "Memcache", "link" => "http://www.php.net/memcache", "state" => class_exists("Memcache") ? "ok" : "warning");
     // Redis
     $checksPHP[] = array("name" => "Redis", "link" => "https://pecl.php.net/package/redis", "state" => class_exists("Redis") ? "ok" : "warning");
     // curl for google api sdk
     $checksPHP[] = array("name" => "curl", "link" => "http://www.php.net/curl", "state" => function_exists("curl_init") ? "ok" : "warning");
     $db = null;
     if ($this->getParam("mysql_adapter")) {
         // this is before installing
         try {
             $dbConfig = ['username' => $this->getParam("mysql_username"), 'password' => $this->getParam("mysql_password"), 'dbname' => $this->getParam("mysql_database")];
             $hostSocketValue = $this->getParam("mysql_host_socket");
             if (file_exists($hostSocketValue)) {
                 $dbConfig["unix_socket"] = $hostSocketValue;
             } else {
                 $dbConfig["host"] = $hostSocketValue;
                 $dbConfig["port"] = $this->getParam("mysql_port");
             }
             $db = \Zend_Db::factory($this->getParam("mysql_adapter"), $dbConfig);
             $db->getConnection();
         } catch (\Exception $e) {
             $db = null;
         }
     } else {
         // this is after installing, eg. after a migration, ...
         $db = \Pimcore\Db::get();
     }
     if ($db) {
         // storage engines
         $engines = array();
         $enginesRaw = $db->fetchAll("SHOW ENGINES;");
         foreach ($enginesRaw as $engineRaw) {
             $engines[] = strtolower($engineRaw["Engine"]);
         }
         // innodb
         $checksMySQL[] = array("name" => "InnoDB Support", "state" => in_array("innodb", $engines) ? "ok" : "error");
         // myisam
         $checksMySQL[] = array("name" => "MyISAM Support", "state" => in_array("myisam", $engines) ? "ok" : "error");
         // memory
         $checksMySQL[] = array("name" => "MEMORY Support", "state" => in_array("memory", $engines) ? "ok" : "error");
         // check database charset =>  utf-8 encoding
         $result = $db->fetchRow('SHOW VARIABLES LIKE "character\\_set\\_database"');
         $checksMySQL[] = array("name" => "Database Charset UTF8", "state" => $result['Value'] == "utf8" ? "ok" : "error");
         // create table
         $queryCheck = true;
         try {
             $db->query("CREATE TABLE __pimcore_req_check (\n                  id int(11) NOT NULL AUTO_INCREMENT,\n                  field varchar(255) CHARACTER SET latin1 NULL DEFAULT NULL,\n                  PRIMARY KEY (id)\n                ) DEFAULT CHARSET=utf8 COLLATE utf8_general_ci");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "CREATE TABLE", "state" => $queryCheck ? "ok" : "error");
         // alter table
         $queryCheck = true;
         try {
             $db->query("ALTER TABLE __pimcore_req_check ADD COLUMN alter_field varchar(255) NULL DEFAULT NULL");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "ALTER TABLE", "state" => $queryCheck ? "ok" : "error");
         // Manage indexes
         $queryCheck = true;
         try {
             $db->query("ALTER TABLE __pimcore_req_check\n                  CHANGE COLUMN id id int(11) NOT NULL,\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\n                  ADD KEY field (field),\n                  DROP PRIMARY KEY ,\n                 DEFAULT CHARSET=utf8");
             $db->query("ALTER TABLE __pimcore_req_check\n                  CHANGE COLUMN id id int(11) NOT NULL AUTO_INCREMENT,\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\n                  ADD PRIMARY KEY (id) ,\n                 DEFAULT CHARSET=utf8");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "Manage Indexes", "state" => $queryCheck ? "ok" : "error");
         // insert data
         $queryCheck = true;
         try {
             $db->insert("__pimcore_req_check", array("field" => uniqid(), "alter_field" => uniqid()));
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "INSERT", "state" => $queryCheck ? "ok" : "error");
         // update
         $queryCheck = true;
         try {
             $db->update("__pimcore_req_check", array("field" => uniqid(), "alter_field" => uniqid()));
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "UPDATE", "state" => $queryCheck ? "ok" : "error");
         // select
         $queryCheck = true;
         try {
             $db->fetchAll("SELECT * FROM __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SELECT", "state" => $queryCheck ? "ok" : "error");
         // create view
         $queryCheck = true;
         try {
             $db->query("CREATE OR REPLACE VIEW __pimcore_req_check_view AS SELECT * FROM __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "CREATE VIEW", "state" => $queryCheck ? "ok" : "error");
         // select from view
         $queryCheck = true;
         try {
             $db->fetchAll("SELECT * FROM __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SELECT (from view)", "state" => $queryCheck ? "ok" : "error");
         // delete
         $queryCheck = true;
         try {
             $db->delete("__pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DELETE", "state" => $queryCheck ? "ok" : "error");
         // show create view
         $queryCheck = true;
         try {
             $db->query("SHOW CREATE VIEW __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SHOW CREATE VIEW", "state" => $queryCheck ? "ok" : "error");
         // show create table
         $queryCheck = true;
         try {
             $db->query("SHOW CREATE TABLE __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SHOW CREATE TABLE", "state" => $queryCheck ? "ok" : "error");
         // drop view
         $queryCheck = true;
         try {
             $db->query("DROP VIEW __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DROP VIEW", "state" => $queryCheck ? "ok" : "error");
         // drop table
         $queryCheck = true;
         try {
             $db->query("DROP TABLE __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DROP TABLE", "state" => $queryCheck ? "ok" : "error");
     } else {
         die("Not possible... no or wrong database settings given.<br />Please fill out the MySQL Settings in the install form an click again on `Check Requirements´");
     }
     // filesystem checks
     // website/var writable
     $websiteVarWritable = true;
     try {
         $files = $this->rscandir(PIMCORE_WEBSITE_VAR);
         foreach ($files as $file) {
             if (!is_writable($file)) {
                 $websiteVarWritable = false;
             }
         }
         $checksFS[] = array("name" => "/website/var/ writeable", "state" => $websiteVarWritable ? "ok" : "error");
     } catch (\Exception $e) {
         $checksFS[] = array("name" => "/website/var/ (not checked - too many files)", "state" => "warning");
     }
     // pimcore writeable
     $checksFS[] = array("name" => "/pimcore/ writeable", "state" => \Pimcore\Update::isWriteable() ? "ok" : "warning");
     // system & application checks
     // PHP CLI BIN
     try {
         $phpCliBin = (bool) \Pimcore\Tool\Console::getPhpCli();
     } catch (\Exception $e) {
         $phpCliBin = false;
     }
     $checksApps[] = array("name" => "PHP CLI Binary", "state" => $phpCliBin ? "ok" : "error");
     // FFMPEG BIN
     try {
         $ffmpegBin = (bool) \Pimcore\Video\Adapter\Ffmpeg::getFfmpegCli();
     } catch (\Exception $e) {
         $ffmpegBin = false;
     }
     $checksApps[] = array("name" => "FFMPEG (CLI)", "state" => $ffmpegBin ? "ok" : "warning");
     // WKHTMLTOIMAGE BIN
     try {
         $wkhtmltopdfBin = (bool) \Pimcore\Image\HtmlToImage::getWkhtmltoimageBinary();
     } catch (\Exception $e) {
         $wkhtmltopdfBin = false;
     }
     $checksApps[] = array("name" => "wkhtmltoimage (CLI)", "state" => $wkhtmltopdfBin ? "ok" : "warning");
     // HTML2TEXT BIN
     try {
         $html2textBin = (bool) \Pimcore\Mail::determineHtml2TextIsInstalled();
     } catch (\Exception $e) {
         $html2textBin = false;
     }
     $checksApps[] = array("name" => "mbayer html2text (CLI)", "state" => $html2textBin ? "ok" : "warning");
     // ghostscript BIN
     try {
         $ghostscriptBin = (bool) \Pimcore\Document\Adapter\Ghostscript::getGhostscriptCli();
     } catch (\Exception $e) {
         $ghostscriptBin = false;
     }
     $checksApps[] = array("name" => "Ghostscript (CLI)", "state" => $ghostscriptBin ? "ok" : "warning");
     // LibreOffice BIN
     try {
         $libreofficeBin = (bool) \Pimcore\Document\Adapter\LibreOffice::getLibreOfficeCli();
     } catch (\Exception $e) {
         $libreofficeBin = false;
     }
     $checksApps[] = array("name" => "LibreOffice (CLI)", "state" => $libreofficeBin ? "ok" : "warning");
     // PNG optimizer
     try {
         $pngOptimizer = (bool) \Pimcore\Image\Optimizer::getPngOptimizerCli();
     } catch (\Exception $e) {
         $pngOptimizer = false;
     }
     $checksApps[] = array("name" => "PNG Optimizer (pngcrush)", "state" => $pngOptimizer ? "ok" : "warning");
     // JPEG optimizer
     try {
         $jpgOptimizer = (bool) \Pimcore\Image\Optimizer::getJpegOptimizerCli();
     } catch (\Exception $e) {
         $jpgOptimizer = false;
     }
     $checksApps[] = array("name" => "JPEG Optimizer (imgmin, jpegoptim)", "state" => $jpgOptimizer ? "ok" : "warning");
     // timeout binary
     try {
         $timeoutBin = (bool) \Pimcore\Tool\Console::getTimeoutBinary();
     } catch (\Exception $e) {
         $timeoutBin = false;
     }
     $checksApps[] = array("name" => "timeout - (GNU coreutils)", "state" => $timeoutBin ? "ok" : "warning");
     // pdftotext binary
     try {
         $pdftotextBin = (bool) \Pimcore\Document\Adapter\Ghostscript::getPdftotextCli();
     } catch (\Exception $e) {
         $pdftotextBin = false;
     }
     $checksApps[] = array("name" => "pdftotext - (part of poppler-utils)", "state" => $pdftotextBin ? "ok" : "warning");
     $this->view->checksApps = $checksApps;
     $this->view->checksPHP = $checksPHP;
     $this->view->checksMySQL = $checksMySQL;
     $this->view->checksFS = $checksFS;
 }
 public function wordExportDownloadAction()
 {
     $id = $this->getParam("id");
     $exportFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $id . ".html";
     // add closing body/html
     //$f = fopen($exportFile, "a+");
     //fwrite($f, "</body></html>");
     //fclose($f);
     // should be done via Pimcore_Document(_Adapter_LibreOffice) in the future
     if (\Pimcore\Document::isFileTypeSupported("docx")) {
         $lockKey = "soffice";
         Model\Tool\Lock::acquire($lockKey);
         // avoid parallel conversions of the same document
         $out = Tool\Console::exec(\Pimcore\Document\Adapter\LibreOffice::getLibreOfficeCli() . ' --headless --convert-to docx:"Office Open XML Text" --outdir ' . PIMCORE_TEMPORARY_DIRECTORY . " " . $exportFile);
         \Logger::debug("LibreOffice Output was: " . $out);
         $tmpName = PIMCORE_TEMPORARY_DIRECTORY . "/" . preg_replace("/\\." . File::getFileExtension($exportFile) . "\$/", ".docx", basename($exportFile));
         Model\Tool\Lock::release($lockKey);
         // end what should be done in Pimcore_Document
         header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
         header('Content-Disposition: attachment; filename="' . basename($tmpName) . '"');
     } else {
         // no conversion, output html file
         $tmpName = $exportFile;
         header("Content-Type: text/html");
         header('Content-Disposition: attachment; filename="' . basename($tmpName) . '"');
     }
     while (@ob_end_flush()) {
     }
     flush();
     readfile($tmpName);
     @unlink($exportFile);
     @unlink($tmpName);
     exit;
 }
 /**
  * @return int
  * @throws \Exception
  */
 public function getDuration()
 {
     $tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/video-info-" . uniqid() . ".out";
     $cmd = self::getFfmpegCli() . " -i " . realpath($this->file);
     Console::exec($cmd, $tmpFile, null, 60);
     $contents = file_get_contents($tmpFile);
     unlink($tmpFile);
     return $this->extractDuration($contents);
 }
Beispiel #24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $currentRevision = null;
     if ($input->getOption("source-build")) {
         $currentRevision = $input->getOption("source-build");
     }
     $availableUpdates = Update::getAvailableUpdates($currentRevision);
     if ($input->getOption("list")) {
         if (count($availableUpdates["releases"])) {
             $rows = [];
             foreach ($availableUpdates["releases"] as $release) {
                 $rows[] = [$release["version"], date("Y-m-d", $release["date"]), $release["id"]];
             }
             $table = new Table($output);
             $table->setHeaders(['Version', 'Date', 'Build'])->setRows($rows);
             $table->render();
         }
         if (count($availableUpdates["revisions"])) {
             $this->output->writeln("The latest available build is: <comment>" . $availableUpdates["revisions"][0]["id"] . "</comment> (" . date("Y-m-d", $availableUpdates["revisions"][0]["date"]) . ")");
         }
         if (!count($availableUpdates["releases"]) && !count($availableUpdates["revisions"])) {
             $this->output->writeln("<info>No updates available</info>");
         }
     }
     if ($input->getOption("update")) {
         $returnMessages = [];
         $build = null;
         $updateInfo = trim($input->getOption("update"));
         if (is_numeric($updateInfo)) {
             $build = $updateInfo;
         } else {
             // get build nr. by version number
             foreach ($availableUpdates["releases"] as $release) {
                 if ($release["version"] == $updateInfo) {
                     $build = $release["id"];
                     break;
                 }
             }
         }
         if (!$build) {
             $this->writeError("Update with build / version " . $updateInfo . " not found.");
             exit;
         }
         if (!Update::isWriteable()) {
             $this->writeError(PIMCORE_PATH . " is not recursivly writable, please check!");
             exit;
         }
         if (!Update::isComposerAvailable()) {
             $this->writeError("Composer is not installed properly, please ensure composer is in your PATH variable.");
             exit;
         }
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion("You are going to update to build {$build}! Continue with this action? (y/n)", false);
         if (!$helper->ask($input, $output, $question)) {
             return;
         }
         $this->output->writeln("Starting the update process ...");
         if ($input->getOption("dry-run")) {
             $this->output->writeln("<info>---------- DRY-RUN ----------</info>");
         }
         $jobs = Update::getJobs($build, $currentRevision);
         $steps = count($jobs["parallel"]) + count($jobs["procedural"]);
         $progress = new ProgressBar($output, $steps);
         $progress->start();
         foreach ($jobs["parallel"] as $job) {
             if ($job["type"] == "download") {
                 Update::downloadData($job["revision"], $job["url"]);
             }
             $progress->advance();
         }
         $maintenanceModeId = 'cache-warming-dummy-session-id';
         Admin::activateMaintenanceMode($maintenanceModeId);
         $stoppedByError = false;
         foreach ($jobs["procedural"] as $job) {
             if ($input->getOption("dry-run")) {
                 $job["dry-run"] = true;
             }
             $script = realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php");
             $return = Console::runPhpScript($script, "internal:update-processor " . escapeshellarg(json_encode($job)));
             $return = trim($return);
             $returnData = @json_decode($return, true);
             if (is_array($returnData)) {
                 if (trim($returnData["message"])) {
                     $returnMessages[] = [$job["revision"], strip_tags($returnData["message"])];
                 }
                 if (!$returnData["success"]) {
                     $stoppedByError = true;
                     break;
                 }
             } else {
                 $stoppedByError = true;
                 break;
             }
             $progress->advance();
         }
         $progress->finish();
         Update::composerDumpAutoload();
         Admin::deactivateMaintenanceMode();
         $this->output->writeln("\n");
         if ($stoppedByError) {
             $this->output->writeln("<error>Update stopped by error! Please check your logs</error>");
             $this->output->writeln("Last return value was: " . $return);
         } else {
             $this->output->writeln("<info>Update done!</info>");
             if (count($returnMessages)) {
                 $table = new Table($output);
                 $table->setHeaders(['Build', 'Message'])->setRows($returnMessages);
                 $table->render();
             }
         }
     }
 }