/** * @param KSchedularTaskConfig $taskConfig */ public function __construct($taskConfig = null) { /* * argv[0] - the script name * argv[1] - serialized KSchedulerConfig config */ global $argv, $g_context; $this->sessionKey = uniqid('sess'); $this->start = microtime(true); if (is_null($taskConfig)) { $data = gzuncompress(base64_decode($argv[1])); self::$taskConfig = unserialize($data); } else { self::$taskConfig = $taskConfig; } if (!self::$taskConfig) { die("Task config not supplied"); } date_default_timezone_set(self::$taskConfig->getTimezone()); // clear seperator between executions KalturaLog::debug('___________________________________________________________________________________'); KalturaLog::stderr('___________________________________________________________________________________', KalturaLog::DEBUG); KalturaLog::info(file_get_contents(dirname(__FILE__) . "/../VERSION.txt")); if (!self::$taskConfig instanceof KSchedularTaskConfig) { KalturaLog::err('config is not a KSchedularTaskConfig'); die; } KalturaLog::debug("set_time_limit({" . self::$taskConfig->maximumExecutionTime . "})"); set_time_limit(self::$taskConfig->maximumExecutionTime); KalturaLog::debug('This batch index: ' . $this->getIndex()); KalturaLog::debug('This session key: ' . $this->sessionKey); self::$kClientConfig = new KalturaConfiguration(); self::$kClientConfig->setLogger($this); self::$kClientConfig->serviceUrl = self::$taskConfig->getServiceUrl(); self::$kClientConfig->curlTimeout = self::$taskConfig->getCurlTimeout(); if (isset(self::$taskConfig->clientConfig)) { foreach (self::$taskConfig->clientConfig as $attr => $value) { self::$kClientConfig->{$attr} = $value; } } self::$kClient = new KalturaClient(self::$kClientConfig); self::$kClient->setPartnerId(self::$taskConfig->getPartnerId()); self::$clientTag = 'batch: ' . self::$taskConfig->getSchedulerName() . ' ' . get_class($this) . " index: {$this->getIndex()} sessionId: " . UniqueId::get(); self::$kClient->setClientTag(self::$clientTag); //$ks = self::$kClient->session->start($secret, "user-2", KalturaSessionType::ADMIN); $ks = $this->createKS(); self::$kClient->setKs($ks); KDwhClient::setEnabled(self::$taskConfig->getDwhEnabled()); KDwhClient::setFileName(self::$taskConfig->getDwhPath()); $this->onBatchUp(); KScheduleHelperManager::saveRunningBatch($this->getName(), $this->getIndex()); }
$secret = $argv[3]; $profile_name = $argv[4]; $delivery_url = $argv[5]; $storage_host = $argv[6]; $storage_basedir = $argv[7]; $storage_user = $argv[8]; $storage_passwd = $argv[9]; $basedir = dirname(__FILE__); $storage_protocol = $argv[10]; $playback_protocol = $argv[11]; try { $config = new KalturaConfiguration($partnerId); $config->serviceUrl = $service_url; $client = new KalturaClient($config); $config->partnerId = $partnerId; $client->setPartnerId($partnerId); $ks = $client->session->start($secret, null, KalturaSessionType::ADMIN, -2, null, null); $client->setKs($ks); $delivery = new KalturaDeliveryProfile(); $delivery->name = $profile_name; $delivery->status = KalturaDeliveryStatus::ACTIVE; $delivery->type = KalturaDeliveryProfileType::HTTP; $delivery->streamerType = KalturaPlaybackProtocol::HTTP; $delivery->systemName = $profile_name; $delivery->url = $delivery_url; //$delivery->isDefault = KalturaNullableBoolean::FALSE_VALUE; $delivery_obj = $client->deliveryProfile->add($delivery); if ($protocols[$storage_protocol] === 'S3') { $storageProfile = new KalturaAmazonS3StorageProfile(); $storageProfile->filesPermissionInS3 = KalturaAmazonS3StorageProfileFilesPermissionLevel::ACL_PUBLIC_READ; } else {
writeLog($logPrefix, 'Service URL ' . $serviceUrl); $sleepSec = $config['sleep_time']; $fileName = basename($filePath); $folderPath = dirname($filePath); writeLog($logPrefix, '---------------------------- Start handling --------------------------'); writeLog($logPrefix, 'action:' . $action); writeLog($logPrefix, 'file path:' . $filePath); writeLog($logPrefix, 'folder path:' . $folderPath); writeLog($logPrefix, 'file name:' . $fileName); writeLog($logPrefix, 'file size:' . $fileSize); $kClientConfig = new KalturaConfiguration(); $kClientConfig->serviceUrl = $serviceUrl; $kClientConfig->curlTimeout = 180; $kClientConfig->setLogger(new SyncDropFolderWatcherLogger($logPrefix)); $kClient = new KalturaClient($kClientConfig); $kClient->setPartnerId(-1); $dropFolderPlugin = KalturaDropFolderClientPlugin::get($kClient); try { $folder = null; $filter = new KalturaDropFolderFilter(); $filter->pathEqual = $folderPath; $filter->typeEqual = KalturaDropFolderType::LOCAL; $filter->statusIn = KalturaDropFolderStatus::ENABLED . ',' . KalturaDropFolderStatus::ERROR; $dropFolders = $dropFolderPlugin->dropFolder->listAction($filter); writeLog($logPrefix, 'found ' . $dropFolders->totalCount . ' folders'); if ($dropFolders->totalCount == 1) { $folder = $dropFolders->objects[0]; writeLog($logPrefix, 'drop folder id ' . $folder->id); $ignorePatterns = array_map('trim', explode(',', $folder->ignoreFileNamePatterns)); foreach ($ignorePatterns as $ignorePattern) { if (!is_null($ignorePattern) && $ignorePattern != '' && fnmatch($ignorePattern, $fileName)) {