protected function process(KalturaBatchJob $job, KalturaDropFolderContentProcessorJobData $data)
 {
     $job = $this->updateJob($job, "Start processing drop folder files [{$data->dropFolderFileIds}]", KalturaBatchJobStatus::QUEUED);
     $engine = KDropFolderEngine::getInstance($job->jobSubType);
     $engine->processFolder($job, $data);
     return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED);
 }
 public function run($jobs = null)
 {
     KalturaLog::info("Drop folder watcher batch is running");
     $this->dropFolderPlugin = KalturaDropFolderClientPlugin::get(self::$kClient);
     if (self::$taskConfig->isInitOnly()) {
         return $this->init();
     }
     $dropFolders = $this->getDropFoldersList();
     if (isset($dropFolders)) {
         $dropFolders = $dropFolders->objects;
         KalturaLog::log('[' . count($dropFolders) . '] folders to watch');
         foreach ($dropFolders as $folder) {
             /* @var $folder KalturaDropFolder */
             try {
                 $this->impersonate($folder->partnerId);
                 $engine = KDropFolderEngine::getInstance($folder->type);
                 $engine->watchFolder($folder);
                 $this->setDropFolderOK($folder);
                 $this->unimpersonate();
             } catch (kFileTransferMgrException $e) {
                 if ($e->getCode() == kFileTransferMgrException::cantConnect) {
                     $this->setDropFolderError($folder, KalturaDropFolderErrorCode::ERROR_CONNECT, DropFolderPlugin::ERROR_CONNECT_MESSAGE, $e);
                 } else {
                     if ($e->getCode() == kFileTransferMgrException::cantAuthenticate) {
                         $this->setDropFolderError($folder, KalturaDropFolderErrorCode::ERROR_AUTENTICATE, DropFolderPlugin::ERROR_AUTENTICATE_MESSAGE, $e);
                     } else {
                         $this->setDropFolderError($folder, KalturaDropFolderErrorCode::ERROR_GET_PHISICAL_FILE_LIST, DropFolderPlugin::ERROR_GET_PHISICAL_FILE_LIST_MESSAGE, $e);
                     }
                 }
                 $this->unimpersonate();
             } catch (KalturaException $e) {
                 $this->setDropFolderError($folder, KalturaDropFolderErrorCode::ERROR_GET_DB_FILE_LIST, DropFolderPlugin::ERROR_GET_DB_FILE_LIST_MESSAGE, $e);
                 $this->unimpersonate();
             } catch (Exception $e) {
                 $this->setDropFolderError($folder, KalturaDropFolderErrorCode::DROP_FOLDER_APP_ERROR, DropFolderPlugin::DROP_FOLDER_APP_ERROR_MESSAGE . $e->getMessage(), $e);
                 $this->unimpersonate();
             }
         }
     }
 }