public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null) { $this->createOutputDirectory(); $realInFilePath = realpath($inFilePath); parent::operate($operator, $realInFilePath, $configFilePath); $this->createDirDescriber($this->outFilePath, self::IMAGES_LIST_XML_NAME); return true; }
public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null) { if (kFile::fullMkfileDir($this->outFilePath)) { KalturaLog::debug('dir [' . $this->outFilePath . '] created'); //outFilePath will be the path to the directory in which the images will be saved. $outDirPath = $this->outFilePath; //imageMagick decides the format of the output file according to the outFilePath's extension.so the format need to be added. $this->outFilePath = $this->outFilePath . DIRECTORY_SEPARATOR . basename($this->outFilePath) . self::LEADING_ZEROS_PADDING . '.' . $this->data->flavorParamsOutput->format; } else { KalturaLog::debug('failed to create [' . $this->outFilePath . '] directory'); throw new KOperationEngineException('failed to create [' . $this->outFilePath . '] directory'); } $ext = strtolower(pathinfo($inFilePath, PATHINFO_EXTENSION)); $inputFormat = $this->getInputFormat(); if ($inputFormat == self::PDF_FORMAT && $ext != 'pdf' && kFile::linkFile($inFilePath, "{$inFilePath}.pdf")) { $inFilePath = "{$inFilePath}.pdf"; } if ($inputFormat == self::JPG_FORMAT && $ext != 'jpg' && kFile::linkFile($inFilePath, "{$inFilePath}.jpg")) { $inFilePath = "{$inFilePath}.jpg"; } $realInFilePath = realpath($inFilePath); // Test input // - Test file type $errorMsg = $this->checkFileType($realInFilePath, $this->SUPPORTED_FILE_TYPES); if (!is_null($errorMsg)) { $this->data->engineMessage = $errorMsg; } // Test password required if ($this->testPasswordRequired($realInFilePath)) { $this->data->engineMessage = "Password required."; } parent::operate($operator, $realInFilePath, $configFilePath); $imagesList = kFile::dirList($outDirPath, false); // Test output // - Test black Image $identifyExe = KBatchBase::$taskConfig->params->identify; $firstImage = $outDirPath . DIRECTORY_SEPARATOR . $imagesList[0]; $errorMsg = $this->testBlackImage($identifyExe, $firstImage, $errorMsg); if (!is_null($errorMsg)) { $this->data->engineMessage = $errorMsg; } $imagesListXML = $this->createImagesListXML($imagesList); kFile::setFileContent($outDirPath . DIRECTORY_SEPARATOR . self::IMAGES_LIST_XML_NAME, $imagesListXML->asXML()); KalturaLog::info('images list xml [' . $outDirPath . DIRECTORY_SEPARATOR . self::IMAGES_LIST_XML_NAME . '] created'); return true; }
public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null) { KalturaLog::debug("document : operator [" . print_r($operator, true) . "] inFilePath [{$inFilePath}]"); if ($configFilePath) { $configFilePath = realpath($configFilePath); } // bypassing PDF Creator for source PDF files $inputExtension = strtolower(pathinfo($inFilePath, PATHINFO_EXTENSION)); if ($inputExtension == 'pdf' && !$this->data->flavorParamsOutput->readonly) { KalturaLog::notice('Bypassing PDF Creator for source PDF files'); if (!@copy($inFilePath, $this->outFilePath)) { $error = ''; if (function_exists('error_get_last')) { $error = error_get_last(); } throw new KOperationEngineException('Cannot copy PDF file [' . $this->inFilePath . '] to [' . $this->outFilePath . '] - [' . $error . ']'); } else { // PDF input file copied as is to output file return true; } } // renaming with unique name to allow conversion 2 conversions of same input file to be done together (PDF+SWF) $tmpUniqInFilePath = dirname($inFilePath) . '/' . uniqid() . '_' . basename($inFilePath); $realInFilePath = ''; $uniqueName = false; if (@copy($inFilePath, $tmpUniqInFilePath)) { $realInFilePath = realpath($tmpUniqInFilePath); $uniqueName = true; } else { KalturaLog::notice('Could not rename input file [' . $inFilePath . '] with a unique name [' . $tmpUniqInFilePath . ']'); $realInFilePath = realpath($inFilePath); } $filePrefix = file_get_contents($realInFilePath, false, null, 0, strlen(self::OLD_OFFICE_SIGNATURE)); $path_info = pathinfo($realInFilePath); $ext = $path_info['extension']; $newOfficeExtensions = array('pptx', 'docx', 'xlsx'); $ext = strtolower($ext); //checks if $realInFilePath is an old office document with a new extension ('pptx|docx|xlsx') //if $realInFilePath is not the fileSync itself ($uniqueName = true) , rename the file by removing the 'x' from the extension. if ($uniqueName && in_array($ext, $newOfficeExtensions) && $filePrefix == self::OLD_OFFICE_SIGNATURE) { $RealInFilePathWithoutX = substr($realInFilePath, 0, -1); if (rename($realInFilePath, $RealInFilePathWithoutX)) { KalturaLog::notice("renamed file [{$realInFilePath}] to [{$RealInFilePathWithoutX}]"); $realInFilePath = $RealInFilePathWithoutX; } } $finalOutputPath = $this->outFilePath; if ($inputExtension == 'pdf' && $this->data->flavorParamsOutput->readonly == true) { $tmpFile = $this->outFilePath . '.pdf'; } else { $tmpFile = kFile::replaceExt(basename($realInFilePath), 'pdf'); $tmpFile = dirname($this->outFilePath) . '/' . $tmpFile; } $this->outFilePath = $tmpFile; // Create popups log file $killPopupsPath = $this->getKillPopupsPath(); if (file_exists($killPopupsPath)) { unlink($killPopupsPath); } // Test file type $errorMsg = $this->checkFileType($realInFilePath, $this->SUPPORTED_FILE_TYPES); if (!is_null($errorMsg)) { $this->data->engineMessage = $errorMsg; } parent::operate($operator, $realInFilePath, $configFilePath); $this->outFilePath = $finalOutputPath; if ($uniqueName) { @unlink($tmpUniqInFilePath); } $sleepTimes = KBatchBase::$taskConfig->fileExistReties; if (!$sleepTimes) { $sleepTimes = self::DEFAULT_SLEEP_TIMES; } $sleepSeconds = KBatchBase::$taskConfig->fileExistInterval; if (!$sleepSeconds) { $sleepSeconds = self::DEFAULT_SLEEP_SECONDS; } // sleeping while file not ready, since PDFCreator exists a bit before the file is actually ready while (!file_exists(realpath($tmpFile)) && $sleepTimes > 0) { sleep($sleepSeconds); $sleepTimes--; clearstatcache(); } // Read popup log file if (file_exists($killPopupsPath)) { $data = file_get_contents($killPopupsPath); $data = trim($data); if (!empty($data)) { KalturaLog::notice("Convert popups warnings - " . $data); if (is_null($this->message)) { $this->message = $data; } else { $this->message .= $data; } } unlink($killPopupsPath); } if (!file_exists(realpath($tmpFile))) { throw new kTemporaryException('Temp PDF Creator file not found [' . $tmpFile . '] output file [' . $this->outFilePath . '] Convert Engine message [' . $this->message . ']'); } else { KalturaLog::notice('document temp found [' . $tmpFile . '] output file [' . $this->outFilePath . ']'); } $this->validateOutput($inFilePath, realpath($tmpFile)); $fileUnlockRetries = KBatchBase::$taskConfig->params->fileUnlockRetries; if (!$fileUnlockRetries) { $fileUnlockRetries = self::DEFAULT_FILE_UNLOCK_RETRIES; } $fileUnlockInterval = KBatchBase::$taskConfig->params->fileUnlockInterval; if (!$fileUnlockInterval) { $fileUnlockInterval = self::DEFAULT_FILE_UNLOCK_INTERVAL; } $tmpFile = realpath($tmpFile); while (!rename($tmpFile, $this->outFilePath) && $fileUnlockRetries > 0) { sleep($fileUnlockInterval); $fileUnlockRetries--; clearstatcache(); } if (!file_exists($this->outFilePath)) { $error = ''; if (function_exists('error_get_last')) { $error = error_get_last(); } throw new KOperationEngineException('Cannot rename file [' . $tmpFile . '] to [' . $this->outFilePath . '] - [' . $error . ']'); } return true; }