protected function createDirDescriber($outDir, $fileName)
 {
     $fileList = kFile::dirList($outDir, false);
     $fileListXml = $this->createImagesListXML($fileList);
     kFile::setFileContent($outDir . DIRECTORY_SEPARATOR . $fileName, $fileListXml->asXML());
     KalturaLog::info('file list xml [' . $outDir . DIRECTORY_SEPARATOR . $fileName . '] created');
 }
 private function createImagesListXML($outDirPath)
 {
     $imagesList = kFile::dirList($outDirPath, false);
     sort($imagesList);
     $imagesListXML = new SimpleXMLElement('<' . self::IMAGES_LIST_XML_LABEL_ITEMS . '/>');
     foreach ($imagesList as $image) {
         $imageNode = $imagesListXML->addChild(self::IMAGES_LIST_XML_LABEL_ITEM);
         $imageNode->addChild(self::IMAGES_LIST_XML_LABEL_NAME, $image);
     }
     $imagesListXML->addAttribute(self::IMAGES_LIST_XML_ATTRIBUTE_COUNT, count($imagesList));
     return $imagesListXML;
 }
 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;
 }
 /**
  * Will take a single KalturaBatchJob and export the given file 
  * 
  * @param KalturaBatchJob $job
  * @param KalturaStorageExportJobData $data
  * @return KalturaBatchJob
  */
 protected function export(KalturaBatchJob $job, KalturaStorageExportJobData $data)
 {
     KalturaLog::debug("export({$job->id})");
     $srcFile = str_replace('//', '/', trim($data->srcFileSyncLocalPath));
     if (!$this->pollingFileExists($srcFile)) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$srcFile} does not exist", KalturaBatchJobStatus::RETRY);
     }
     $destFile = str_replace('//', '/', trim($data->destFileSyncStoredPath));
     $this->updateJob($job, "Exporting {$srcFile} to {$destFile}", KalturaBatchJobStatus::QUEUED, 1);
     $engine = kFileTransferMgr::getInstance($job->jobSubType);
     try {
         $engine->login($data->serverUrl, $data->serverUsername, $data->serverPassword, null, $data->ftpPassiveMode);
     } catch (Exception $e) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::RETRY);
     }
     try {
         if (is_file($srcFile)) {
             $engine->putFile($destFile, $srcFile, $data->force);
         } else {
             if (is_dir($srcFile)) {
                 $filesPaths = kFile::dirList($srcFile);
                 $destDir = $destFile;
                 foreach ($filesPaths as $filePath) {
                     $destFile = $destDir . DIRECTORY_SEPARATOR . basename($filePath);
                     $engine->putFile($destFile, $filePath, $data->force);
                 }
             }
         }
     } catch (kFileTransferMgrException $e) {
         if ($e->getCode() == kFileTransferMgrException::remoteFileExists) {
             return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::FILE_ALREADY_EXISTS, $e->getMessage(), KalturaBatchJobStatus::FAILED);
         }
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::FAILED);
     } catch (Exception $e) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::FAILED);
     }
     if ($this->taskConfig->params->chmod) {
         try {
             $engine->chmod($destFile, $this->taskConfig->params->chmod);
         } catch (Exception $e) {
         }
     }
     return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED);
 }
예제 #5
0
 function export()
 {
     if (!KBatchBase::pollingFileExists($this->srcFile)) {
         throw new kTemporaryException("Source file {$this->srcFile} does not exist");
     }
     $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array();
     $engineOptions['passiveMode'] = $this->data->ftpPassiveMode;
     $engineOptions['createLink'] = $this->data->createLink;
     if ($this->data instanceof KalturaAmazonS3StorageExportJobData) {
         $engineOptions['filesAcl'] = $this->data->filesPermissionInS3;
         $engineOptions['s3Region'] = $this->data->s3Region;
     }
     $engine = kFileTransferMgr::getInstance($this->protocol, $engineOptions);
     try {
         $keyPairLogin = false;
         if ($this->protocol == KalturaStorageProfileProtocol::SFTP) {
             $keyPairLogin = $this->data->serverPrivateKey || $this->data->serverPublicKey;
         }
         if ($keyPairLogin) {
             $privateKeyFile = self::getTempFileWithContent($this->data->serverPrivateKey, 'privateKey');
             $publicKeyFile = self::getTempFileWithContent($this->data->serverPublicKey, 'publicKey');
             $engine->loginPubKey($this->data->serverUrl, $this->data->serverUsername, $publicKeyFile, $privateKeyFile, $this->data->serverPassPhrase);
         } else {
             $engine->login($this->data->serverUrl, $this->data->serverUsername, $this->data->serverPassword);
         }
     } catch (Exception $e) {
         throw new kTemporaryException($e->getMessage());
     }
     try {
         if (is_file($this->srcFile)) {
             $engine->putFile($this->destFile, $this->srcFile, $this->data->force);
             if (KBatchBase::$taskConfig->params->chmod) {
                 try {
                     $engine->chmod($this->destFile, KBatchBase::$taskConfig->params->chmod);
                 } catch (Exception $e) {
                 }
             }
         } else {
             if (is_dir($this->srcFile)) {
                 $filesPaths = kFile::dirList($this->srcFile);
                 $destDir = $this->destFile;
                 foreach ($filesPaths as $filePath) {
                     $destFile = $destDir . '/' . basename($filePath);
                     $engine->putFile($destFile, $filePath, $this->data->force);
                     if (KBatchBase::$taskConfig->params->chmod) {
                         try {
                             $engine->chmod($destFile, KBatchBase::$taskConfig->params->chmod);
                         } catch (Exception $e) {
                         }
                     }
                 }
             }
         }
     } catch (kFileTransferMgrException $e) {
         if ($e->getCode() == kFileTransferMgrException::remoteFileExists) {
             throw new kApplicativeException(KalturaBatchJobAppErrors::FILE_ALREADY_EXISTS, $e->getMessage());
         }
         throw new Exception($e->getMessage(), $e->getCode());
     }
     return true;
 }
예제 #6
0
 public static function getAllTemplateNames()
 {
     return kFile::dirList(self::getTemplateDir(), false);
 }
 public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null)
 {
     /*
      * Creating unique output folder for nbrPlay/Webex sessions.
      * This is required in order to support concurrent conversion sessions,
      * because the nbrPlay tool generates temp files with the same name.
      * Upon completion move the generated file into the 'regular' outFilePath
      */
     $saveOutPath = $this->outFilePath;
     $path_parts = pathinfo($this->outFilePath);
     $outDir = realpath($path_parts['dirname']);
     /*
      * The temp folder name
      */
     $tempFolder = "{$outDir}/" . $path_parts['basename'] . ".webex_temp_folder";
     $tempOutPath = "{$tempFolder}/" . $path_parts['basename'];
     if (!file_exists($tempFolder)) {
         $oldUmask = umask(00);
         $result = @mkdir($tempFolder, 0777, true);
         umask($oldUmask);
     }
     /*
      * Switch to temp forlder
      */
     $this->outFilePath = $tempOutPath;
     $rv = parent::operate($operator, $inFilePath, $configFilePath);
     /*
      * Restore the original
      */
     if (file_exists($tempOutPath)) {
         $outFilelist = kFile::dirList($tempFolder);
         if (isset($outFilelist) && count($outFilelist) > 0) {
             foreach ($outFilelist as $fileName) {
                 for ($tries = 0; $tries < 5; $tries++) {
                     $toFile = "{$outDir}/" . pathinfo($fileName, PATHINFO_BASENAME);
                     $rv = kFile::moveFile($fileName, $toFile);
                     if (!file_exists($fileName)) {
                         break;
                     }
                     KalturaLog::err("Failed to move ({$fileName}) to ({$toFile})");
                     Sleep(60);
                 }
             }
             Sleep(60);
             rmdir($tempFolder);
         }
     }
     $this->outFilePath = $saveOutPath;
     return $rv;
 }