/**
  * @param BaseObject $object
  */
 public function attachCreatedObject(BaseObject $object)
 {
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->getDropFolderFileId());
     $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId());
     $entryId = $asset = null;
     // create import job for remote drop folder files
     if ($dropFolder instanceof RemoteDropFolder) {
         // get params
         if ($object instanceof asset) {
             $entryId = $object->getEntryId();
             $asset = $object;
         } else {
             if ($object instanceof entry) {
                 $entryId = $object->getId();
                 $asset = null;
             } else {
                 return;
             }
         }
         $importUrl = $dropFolder->getFolderUrl();
         $importUrl .= '/' . $dropFolderFile->getFileName();
         $jobData = $dropFolder->getImportJobData();
         $jobData->setDropFolderFileId($this->getDropFolderFileId());
         // add job
         kJobsManager::addImportJob(null, $entryId, $dropFolderFile->getPartnerId(), $importUrl, $asset, $dropFolder->getFileTransferMgrType(), $jobData);
         // set file status to DOWNLOADING
         $dropFolderFile->setStatus(DropFolderFileStatus::DOWNLOADING);
         $dropFolderFile->save();
     }
 }
 protected function updatedImportFailed(BatchJob $dbBatchJob, kDropFolderImportJobData $data, BatchJob $twinJob = null)
 {
     // set drop folder file status to ERROR_DOWNLOADING
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($data->getDropFolderFileId());
     $dropFolderFile->setStatus(DropFolderFileStatus::ERROR_DOWNLOADING);
     $dropFolderFile->setErrorCode(DropFolderFileErrorCode::ERROR_DOWNLOADING_FILE);
     $dropFolderFile->setErrorDescription('Error while downloading file');
     $dropFolderFile->save();
     return $dbBatchJob;
 }
 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;
     }
 }
Exemplo n.º 4
0
 private function onImportJobStatusUpdated(BatchJob $dbBatchJob, kDropFolderImportJobData $data)
 {
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($data->getDropFolderFileId());
     if (!$dropFolderFile) {
         return;
     }
     switch ($dbBatchJob->getStatus()) {
         case BatchJob::BATCHJOB_STATUS_FINISHED:
             $newStatus = DropFolderFileStatus::HANDLED;
             $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId());
             if ($dropFolder && $dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY) {
                 // Shift the state to PROCESSING until the associated entry will reach the READY (or ERROR_CONVERTING) state
                 KalturaLog::info("Shifting drop folder file id [{$dropFolderFile->getId()}] from status [{$dropFolderFile->getStatus()}] to PROCESSING due to AUTO_DELETE_WHEN_ENTRY_IS_READY policy");
                 $newStatus = DropFolderFileStatus::PROCESSING;
             }
             $dropFolderFile->setStatus($newStatus);
             $dropFolderFile->save();
             break;
         case BatchJob::BATCHJOB_STATUS_FAILED:
         case BatchJob::BATCHJOB_STATUS_FATAL:
             $this->setFileError($dropFolderFile, DropFolderFileStatus::ERROR_DOWNLOADING, DropFolderFileErrorCode::ERROR_DOWNLOADING_FILE, DropFolderPlugin::ERROR_DOWNLOADING_FILE_MESSAGE);
             break;
     }
 }
 /**
  * Set the KalturaDropFolderFile status to ignore (KalturaDropFolderFileStatus::IGNORE)
  * 
  * @action ignore
  * @param int $dropFolderFileId 
  * @return KalturaDropFolderFile
  *
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 public function ignoreAction($dropFolderFileId)
 {
     $dbDropFolderFile = DropFolderFilePeer::retrieveByPK($dropFolderFileId);
     if (!$dbDropFolderFile) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFileId);
     }
     $dbDropFolderFile->setStatus(DropFolderFileStatus::IGNORE);
     $dbDropFolderFile->save();
     $dropFolderFile = new KalturaDropFolderFile();
     $dropFolderFile->fromObject($dbDropFolderFile);
     return $dropFolderFile;
 }
 /**
  * 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;
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId);
     if (is_null($dropFolderFile)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId);
     }
     if ($dropFolderFile->getStatus() != DropFolderFileStatus::DOWNLOADING) {
         $dropFolderFile->setStatus(DropFolderFileStatus::HANDLED);
         $dropFolderFile->save();
     }
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId);
     if (is_null($dropFolderFile)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId);
     }
     if ($dropFolderFile->getStatus() != DropFolderFileStatus::DOWNLOADING) {
         $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId());
         if (!$dropFolder) {
             throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFile->getDropFolderId());
         }
         if ($dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE && $dropFolder->getAutoFileDeleteDays() == 0) {
             $dropFolderFile->setStatus(DropFolderFileStatus::PURGED);
         } else {
             $dropFolderFile->setStatus(DropFolderFileStatus::HANDLED);
         }
     }
     $dropFolderFile->setEntryId($dbEntry->getId());
     $dropFolderFile->save();
 }