private function onBulkUploadJobStatusUpdated(BatchJob $dbBatchJob)
 {
     $xmlDropFolderFile = DropFolderFilePeer::retrieveByPK($dbBatchJob->getObjectId());
     if (!$xmlDropFolderFile) {
         return;
     }
     KalturaLog::debug('object id ' . $dbBatchJob->getObjectId());
     switch ($dbBatchJob->getStatus()) {
         case BatchJob::BATCHJOB_STATUS_QUEUED:
             $jobData = $dbBatchJob->getData();
             if (!is_null($jobData->getFilePath())) {
                 $syncKey = $dbBatchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
                 try {
                     kFileSyncUtils::moveFromFile($jobData->getFilePath(), $syncKey, true);
                 } catch (Exception $e) {
                     KalturaLog::err($e);
                     throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
                 }
                 $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
                 $jobData->setFilePath($filePath);
                 //save new info on the batch job
                 $dbBatchJob->setData($jobData);
                 $dbBatchJob->save();
             }
             break;
         case BatchJob::BATCHJOB_STATUS_FINISHED:
         case BatchJob::BATCHJOB_STATUS_FINISHED_PARTIALLY:
             KalturaLog::debug("Handling Bulk Upload finished");
             $xmlDropFolderFile->setStatus(DropFolderFileStatus::HANDLED);
             $xmlDropFolderFile->save();
             break;
         case BatchJob::BATCHJOB_STATUS_FAILED:
         case BatchJob::BATCHJOB_STATUS_FATAL:
             KalturaLog::debug("Handling Bulk Upload failed");
             $relatedFiles = DropFolderFilePeer::retrieveByLeadIdAndStatuses($xmlDropFolderFile->getId(), array(DropFolderFileStatus::PROCESSING));
             foreach ($relatedFiles as $relatedFile) {
                 $this->setFileError($relatedFile, DropFolderFileStatus::ERROR_HANDLING, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::ERROR_IN_BULK_UPLOAD), DropFolderXmlBulkUploadPlugin::ERROR_IN_BULK_UPLOAD_MESSAGE);
             }
             break;
     }
 }
 /**
  * Check if all the files are finished upload
  * If yes return XML drop folder file instance
  * otherwise return false
  * @param DropFolderFile $file
  */
 private function getXmlFileIfReadyForProcessing(DropFolderFile $file)
 {
     KalturaLog::debug('Check if file [' . $file->getId() . '] ready for processing ');
     if (!$file->getLeadDropFolderFileId()) {
         KalturaLog::debug('The XML file is not uploaded yet - changing status to WAITING');
         return false;
     }
     $statuses = array(DropFolderFileStatus::PARSED, DropFolderFileStatus::UPLOADING, DropFolderFileStatus::DETECTED);
     $nonReadyFiles = DropFolderFilePeer::retrieveByLeadIdAndStatuses($file->getLeadDropFolderFileId(), $statuses);
     if ($nonReadyFiles && count($nonReadyFiles) > 0) {
         KalturaLog::debug('Not all the files finished uploading - changing status to WAITING');
         return false;
     }
     $xmlFile = null;
     if ($file->getId() == $file->getLeadDropFolderFileId()) {
         $xmlFile = $file;
     } else {
         $xmlFile = DropFolderFilePeer::retrieveByPK($file->getLeadDropFolderFileId());
     }
     return $xmlFile;
 }