protected function createOutputDirectory() { if (!kFile::fullMkfileDir($this->outFilePath)) { KalturaLog::debug('failed to create [' . $this->outFilePath . '] directory'); throw new KOperationEngineException('failed to create [' . $this->outFilePath . '] directory'); } }
public function configure() { $this->tempDirectory = isset(KBatchBase::$taskConfig->params->tempDirectoryPath) ? KBatchBase::$taskConfig->params->tempDirectoryPath : sys_get_temp_dir(); if (!is_dir($this->tempDirectory)) { kFile::fullMkfileDir($this->tempDirectory, 0700, true); } }
/** * @see IDistributionEngine::configure() */ public function configure(KSchedularTaskConfig $taskConfig) { if ($taskConfig->params->tempFilePath) { $this->tempFilePath = $taskConfig->params->tempFilePath; if (!is_dir($this->tempFilePath)) { kFile::fullMkfileDir($this->tempFilePath, 0777, true); } } else { $this->tempFilePath = sys_get_temp_dir(); KalturaLog::info('params.tempFilePath configuration not supplied, using default system directory [' . $this->tempFilePath . ']'); } }
public function configure(KSchedularTaskConfig $taskConfig) { if ($taskConfig->params->tempXmlPath) { $this->tempXmlPath = $taskConfig->params->tempXmlPath; if (!is_dir($this->tempXmlPath)) { kFile::fullMkfileDir($this->tempXmlPath, 0777, true); } } else { KalturaLog::err("params.tempXmlPath configuration not supplied"); $this->tempXmlPath = sys_get_temp_dir(); } }
public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null) { //$this->outFilePath = "k:".$this->outFilePath; KalturaLog::debug("creating directory:" . $this->outFilePath); kFile::fullMkfileDir($this->outFilePath, 0777, true); $res = parent::operate($operator, $inFilePath, $configFilePath); rename("{$this->outFilePath}//playlist.m3u8", "{$this->outFilePath}//playlist.tmp"); self::parsePlayList("{$this->outFilePath}//playlist.tmp", "{$this->outFilePath}//playlist.m3u8"); // rename("out_dummy.m3u8", "$this->outFilePath//out_dummy.m3u8"); // KalturaLog::info("operator($operator), inFilePath($inFilePath), configFilePath($configFilePath)"); return $res; }
public function exec(KalturaBatchJob $job) { $sharedPath = $this->getAdditionalParams('sharedTempPath'); if (!is_dir($sharedPath)) { kFile::fullMkfileDir($sharedPath); if (!is_dir($sharedPath)) { throw new Exception('Shared path [' . $sharedPath . '] doesn\'t exist and could not be created'); } } KalturaLog::debug('Temp shared path: ' . $sharedPath); /** @var KalturaScheduledTaskJobData $jobData */ $jobData = $job->data; $profileId = $job->jobObjectId; $maxResults = $jobData->maxResults ? $jobData->maxResults : 500; $scheduledTaskClient = $this->getScheduledTaskClient(); $scheduledTaskProfile = $scheduledTaskClient->scheduledTaskProfile->get($profileId); $pager = new KalturaFilterPager(); $pager->pageSize = 500; $pager->pageIndex = 1; $response = new KalturaObjectListResponse(); $response->objects = array(); $response->totalCount = 0; $resultsCount = 0; while (true) { $client = $this->getClient(); $ks = $this->createKs($client, $jobData); $client->setKs($ks); $this->impersonate($scheduledTaskProfile->partnerId); try { $results = ScheduledTaskBatchHelper::query($client, $scheduledTaskProfile, $pager); $this->unimpersonate(); } catch (Exception $ex) { $this->unimpersonate(); throw $ex; } if (!count($results->objects)) { break; } $resultsCount += count($results->objects); if ($resultsCount >= $maxResults) { break; } $response->objects = array_merge($response->objects, $results->objects); $response->totalCount += count($results->objects); $pager->pageIndex++; } $sharedFilePath = $sharedPath . '/' . uniqid('sheduledtask_'); KalturaLog::debug('Temp shared file: ' . $sharedFilePath); file_put_contents($sharedFilePath, serialize($response)); $jobData->resultsFilePath = $sharedFilePath; return $this->closeJob($job, null, null, 'Dry run finished', KalturaBatchJobStatus::FINISHED, $jobData); }
public function configure() { parent::configure(); if (KBatchBase::$taskConfig->params->tempXmlPath) { $this->tempXmlPath = KBatchBase::$taskConfig->params->tempXmlPath; if (!is_dir($this->tempXmlPath)) { kFile::fullMkfileDir($this->tempXmlPath, 0777, true); } } else { KalturaLog::err("params.tempXmlPath configuration not supplied"); $this->tempXmlPath = sys_get_temp_dir(); } }
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->flavorParamsOutput->format; } else { KalturaLog::debug('failed to create [' . $this->outFilePath . '] directory'); throw new KOperationEngineException('failed to create [' . $this->outFilePath . '] directory'); } parent::operate($operator, $inFilePath, $configFilePath); $imagesListXML = $this->createImagesListXML($outDirPath); 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'); }
protected static function loadConsumers() { $cachePath = kConf::get('cache_root_path') . '/EventConsumers.cache'; if (file_exists($cachePath)) { self::$consumers = unserialize(file_get_contents($cachePath)); return; } $coreConsumers = kConf::get('event_consumers'); $pluginConsumers = array(); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaEventConsumers'); foreach ($pluginInstances as $pluginInstance) { foreach ($pluginInstance->getEventConsumers() as $pluginConsumer) { $pluginConsumers[] = $pluginConsumer; } } $consumers = array_merge($coreConsumers, $pluginConsumers); $consumersLists = array(); foreach ($consumers as $consumer) { if (!class_exists($consumer)) { continue; } $clazz = new ReflectionClass($consumer); $interfaces = $clazz->getInterfaces(); foreach ($interfaces as $interface) { if ($interface->name == self::BASE_CONSUMER_INTERFACE) { continue; } if (!$interface->implementsInterface(self::BASE_CONSUMER_INTERFACE)) { continue; } if (!isset($consumersLists[$interface->name])) { $consumersLists[$interface->name] = array(); } $consumersLists[$interface->name][] = $consumer; } } foreach ($consumersLists as $interfaceName => $interfaceConsumersArray) { usort($interfaceConsumersArray, array('kEventsManager', 'compareConsumers')); self::$consumers[$interfaceName] = $interfaceConsumersArray; } $cacheDir = dirname($cachePath); if (!file_exists($cacheDir)) { kFile::fullMkfileDir($cacheDir, 0777, true); } @file_put_contents($cachePath, serialize(self::$consumers)); }
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 static function moveFromFileToDirectory(FileSyncKey $directory_key, $temp_file_path, $base_file_name = null) { KalturaLog::debug("move file to directory: [{$temp_file_path}] to key [{$directory_key}]"); $c = FileSyncPeer::getCriteriaForFileSyncKey($directory_key); $c->add(FileSyncPeer::FILE_TYPE, array(FileSync::FILE_SYNC_FILE_TYPE_FILE, FileSync::FILE_SYNC_FILE_TYPE_LINK), Criteria::IN); $c->add(FileSyncPeer::DC, kDataCenterMgr::getCurrentDcId()); $fileSync = FileSyncPeer::doSelectOne($c); $dirFullPath = null; if ($fileSync) { $dirFullPath = $fileSync->getFullPath(); } else { list($rootPath, $filePath) = self::getLocalFilePathArrForKey($directory_key); $dirFullPath = $rootPath . $filePath; if (!$dirFullPath) { $dirFullPath = kPathManager::getFilePath($directory_key); KalturaLog::info("Generated new path [{$dirFullPath}]"); } $dirFullPath = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $dirFullPath); if (file_exists($dirFullPath)) { $time = time(); $dirFullPath .= $time; $filePath .= $time; } else { KalturaLog::info("Creating directory [{$dirFullPath}] for file"); kFile::fullMkfileDir($dirFullPath); } self::createSyncFileForKey($rootPath, $filePath, $directory_key); } $existing_files = glob($dirFullPath . DIRECTORY_SEPARATOR . '*'); if (count($existing_files) >= self::MAX_FILES_IN_CATEGORY) { throw new kFileSyncException("Exceeded max number of files [" . self::MAX_FILES_IN_CATEGORY . "] in category [{$dirFullPath}]"); } if ($base_file_name) { $filesCount = 0; $files = glob($dirFullPath . DIRECTORY_SEPARATOR . '*'); if ($files) { $filesCount = count($files); } $base_file_name = str_pad($filesCount, 4, 0, STR_PAD_LEFT) . '.' . $base_file_name; } else { $base_file_name = basename($temp_file_path); } $destination_file_path = $dirFullPath . DIRECTORY_SEPARATOR . $base_file_name; $success = kFile::moveFile($temp_file_path, $destination_file_path); self::setPermissions($dirFullPath); KalturaLog::debug("temp_file_path [{$temp_file_path}](" . filesize($temp_file_path) . ") destination_file_path [{$destination_file_path}](" . filesize($destination_file_path) . ")"); if (!$success) { throw new kFileSyncException("Could not move file from [{$temp_file_path}] to [{$destination_file_path}]"); } }
private static function createFileName($partner_id) { $args = func_get_args(); $file_name = uniqid(); $time_suffix = date("Y-m-D-H", (int) (time() / 43200) * 43200); // calculate for intervlas of half days (86400/2) $folderPath = "/content/reports/{$partner_id}"; $fullPath = myContentStorage::getFSContentRootPath() . $folderPath; if (!file_exists($fullPath)) { kFile::fullMkfileDir($fullPath, 0777, true); } $fileName = "{$file_name}_{$time_suffix}"; $file_path = "{$fullPath}/{$fileName}"; // $path = "/content/reports/$partner_id/{$file_name}_{$time_suffix}"; // $file_path = myContentStorage::getFSContentRootPath() . $path; // $url = requestUtils::getHost() . $path; return array($file_path, $fileName); }
private static function createFileName($partner_id) { $args = func_get_args(); $file_name = ""; foreach ($args as $arg) { // if ( $file_name ) $file_name .= "_"; if ($arg instanceof reportsInputFilter) { $file_name .= $arg->toShortString(); } else { $file_name .= "{$arg}"; } } $time_suffix = date("Y-m-D-H", (int) (time() / 43200) * 43200); // calculate for intervlas of half days (86400/2) $folderPath = "/content/reports/{$partner_id}"; $fullPath = myContentStorage::getFSContentRootPath() . $folderPath; if (!file_exists($fullPath)) { kFile::fullMkfileDir($fullPath, 0777, true); } $fileName = "{$file_name}_{$time_suffix}"; $url = requestUtils::getHost() . "{$folderPath}/{$fileName}"; $file_path = "{$fullPath}/{$fileName}"; // $path = "/content/reports/$partner_id/{$file_name}_{$time_suffix}"; // $file_path = myContentStorage::getFSContentRootPath() . $path; // $url = requestUtils::getHost() . $path; return array($file_path, $url); }
/** * @return string */ protected static function getQueueFiltersDir() { $path = self::getCachePath() . DIRECTORY_SEPARATOR . 'filters'; if (!file_exists($path)) { kFile::fullMkfileDir($path); } return $path; }