public function run($jobs = null)
 {
     $this->curlWrapper = new KCurlWrapper(self::$taskConfig->params);
     $retJobs = parent::run($jobs);
     $this->curlWrapper->close();
     return $retJobs;
 }
 protected static function unsetCurrentJob()
 {
     $currentJob = self::getCurrentJob();
     KalturaLog::debug("End job[{$currentJob->id}]");
     self::$currentJob = null;
     self::$kClient->setClientTag(self::$clientTag);
 }
 protected function getFilter()
 {
     $filter = parent::getFilter();
     if (KBatchBase::$taskConfig->params->minFileSize && is_numeric(KBatchBase::$taskConfig->params->minFileSize)) {
         $filter->fileSizeGreaterThan = KBatchBase::$taskConfig->params->minFileSize;
     }
     if (KBatchBase::$taskConfig->params->maxFileSize && is_numeric(KBatchBase::$taskConfig->params->maxFileSize)) {
         $filter->fileSizeLessThan = KBatchBase::$taskConfig->params->maxFileSize;
     }
     return $filter;
 }
 protected function getFilter()
 {
     $filter = parent::getFilter();
     if (is_null($filter->jobSubTypeIn)) {
         $filter->jobSubTypeIn = $this->getSupportedProtocols();
     }
     if ($this->taskConfig->params->minFileSize && is_numeric($this->taskConfig->params->minFileSize)) {
         $filter->fileSizeGreaterThan = $this->taskConfig->params->minFileSize;
     }
     if ($this->taskConfig->params->maxFileSize && is_numeric($this->taskConfig->params->maxFileSize)) {
         $filter->fileSizeLessThan = $this->taskConfig->params->maxFileSize;
     }
     return $filter;
 }
 public function run($jobs = null)
 {
     // creates a temp file path
     $this->localTempPath = self::$taskConfig->params->localTempPath;
     $this->sharedTempPath = self::$taskConfig->params->sharedTempPath;
     $res = self::createDir($this->localTempPath);
     if (!$res) {
         KalturaLog::err("Cannot continue conversion without temp local directory");
         return null;
     }
     $res = self::createDir($this->sharedTempPath);
     if (!$res) {
         KalturaLog::err("Cannot continue conversion without temp shared directory");
         return null;
     }
     return parent::run($jobs);
 }
 public function dispatch(KalturaEventNotificationTemplate $eventNotificationTemplate, KalturaEventNotificationDispatchJobData &$data)
 {
     $job = KJobHandlerWorker::getCurrentJob();
     $variables = array();
     if (is_array($data->contentParameters) && count($data->contentParameters)) {
         foreach ($data->contentParameters as $contentParameter) {
             /* @var $contentParameter KalturaKeyValue */
             $variables[$contentParameter->key] = $contentParameter->value;
         }
     }
     switch ($job->jobSubType) {
         case KalturaEventNotificationTemplateType::BPM_START:
             return $this->startBusinessProcess($eventNotificationTemplate, $data, $variables);
         case KalturaEventNotificationTemplateType::BPM_SIGNAL:
             return $this->signalCase($eventNotificationTemplate, $data, $variables);
         case KalturaEventNotificationTemplateType::BPM_ABORT:
             return $this->abortCase($eventNotificationTemplate, $data);
     }
 }
 public function run($jobs = null)
 {
     // creates a temp file path
     $this->localTempPath = self::$taskConfig->params->localTempPath;
     $this->sharedTempPath = self::$taskConfig->params->sharedTempPath;
     $res = self::createDir($this->localTempPath);
     if (!$res) {
         KalturaLog::err("Cannot continue conversion without temp local directory");
         return null;
     }
     $res = self::createDir($this->sharedTempPath);
     if (!$res) {
         KalturaLog::err("Cannot continue conversion without temp shared directory");
         return null;
     }
     $remoteFileRoot = self::$taskConfig->getRemoteServerUrl() . self::$taskConfig->params->remoteUrlDirectory;
     $this->distributedFileManager = new KDistributedFileManager(self::$taskConfig->params->localFileRoot, $remoteFileRoot, self::$taskConfig->params->fileCacheExpire);
     return parent::run($jobs);
 }
 public function doRecalculate(KalturaRecalculateResponseProfileCacheJobData $data)
 {
     $job = KJobHandlerWorker::getCurrentJob();
     KBatchBase::impersonate($job->partnerId);
     $partner = KBatchBase::$kClient->partner->get($job->partnerId);
     KBatchBase::unimpersonate();
     $role = reset($data->userRoles);
     /* @var $role KalturaIntegerValue */
     $privileges = array('setrole:' . $role->value, 'disableentitlement');
     $privileges = implode(',', $privileges);
     $client = new KalturaClient(KBatchBase::$kClientConfig);
     $ks = $client->generateSession($partner->adminSecret, 'batchUser', $data->ksType, $job->partnerId, 86400, $privileges);
     $client->setKs($ks);
     $options = new KalturaResponseProfileCacheRecalculateOptions();
     $options->limit = $this->maxCacheObjectsPerRequest;
     $options->cachedObjectType = $data->cachedObjectType;
     $options->objectId = $data->objectId;
     $options->startObjectKey = $data->startObjectKey;
     $options->endObjectKey = $data->endObjectKey;
     $options->jobCreatedAt = $job->createdAt;
     $options->isFirstLoop = true;
     $recalculated = 0;
     try {
         do {
             $results = $client->responseProfile->recalculate($options);
             $recalculated += $results->recalculated;
             $options->startObjectKey = $results->lastObjectKey;
             $options->isFirstLoop = false;
         } while ($results->lastObjectKey);
     } catch (KalturaException $e) {
         if ($e->getCode() != self::RESPONSE_PROFILE_CACHE_ALREADY_RECALCULATED && $e->getCode() != self::RESPONSE_PROFILE_CACHE_RECALCULATE_RESTARTED) {
             throw $e;
         }
         KalturaLog::err($e);
     }
     return $recalculated;
 }
 protected function getNotificationUrl(KalturaUnicornDistributionJobProviderData $providerData)
 {
     $job = KJobHandlerWorker::getCurrentJob();
     $serviceUrl = trim($providerData->notificationBaseUrl, '/');
     return "{$serviceUrl}/api_v3/index.php/service/unicornDistribution_unicorn/action/notify/partnerId/{$job->partnerId}/id/{$job->id}";
 }
 protected function getPrivileges()
 {
     return array_merge(parent::getPrivileges(), array(self::PRIVILEGE_BATCH_JOB_TYPE . ':' . self::getType()));
 }
 protected static function unsetCurrentJob()
 {
     self::$currentJob = null;
 }