/**
  * @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();
     }
 }
 public static function retrieveByDropFolderIdAndStatus($dropFolderId, $status)
 {
     $c = new Criteria();
     $c->addAnd(DropFolderFilePeer::DROP_FOLDER_ID, $dropFolderId, Criteria::EQUAL);
     $c->addAnd(DropFolderFilePeer::STATUS, $status, Criteria::EQUAL);
     $dropFolderFiles = DropFolderFilePeer::doSelect($c);
     return $dropFolderFiles;
 }
Beispiel #3
0
 public static function retrieveByEntryIdPartnerIdAndStatuses($entryId, $partnerId, $statuses)
 {
     $c = new Criteria();
     $c->addAnd(DropFolderFilePeer::ENTRY_ID, $entryId, Criteria::EQUAL);
     $c->addAnd(DropFolderFilePeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
     $c->addAnd(DropFolderFilePeer::STATUS, $statuses, Criteria::IN);
     $dropFolderFiles = DropFolderFilePeer::doSelect($c);
     return $dropFolderFiles;
 }
 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;
 }
 /**
  * Convert all drop folder files' status from PROCESSING to HANDLED/DELETED in case of DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY
  * 
  * Note that if the entry reached entryStatus::ERROR_CONVERTING, then the drop folder files' 
  * conversions already failed, so there's no need to change their status (thus they won't be handled here).  
  *  
  * @param entry $entry
  */
 private function onEntryStatusChanged($entry)
 {
     // Handle only files that are still in the PROCESSING state, which were left
     // in this state due to AUTO_DELETE_WHEN_ENTRY_IS_READY delete policy.
     $dropFolderFiles = DropFolderFilePeer::retrieveByEntryIdPartnerIdAndStatuses($entry->getId(), $entry->getPartnerId(), array(DropFolderFileStatus::PROCESSING));
     $dropFolderIdToDropFolderCache = array();
     $entryStatus = $entry->getStatus();
     foreach ($dropFolderFiles as $dropFolderFile) {
         $newDropFolderFileStatus = null;
         if ($entryStatus == entryStatus::ERROR_CONVERTING) {
             $newDropFolderFileStatus = DropFolderFileStatus::ERROR_HANDLING;
         } elseif ($entryStatus == entryStatus::READY) {
             // Get the associated drop folder
             $dropFolderId = $dropFolderFile->getDropFolderId();
             if (key_exists($dropFolderId, $dropFolderIdToDropFolderCache)) {
                 $dropFolder = $dropFolderIdToDropFolderCache[$dropFolderId];
             } else {
                 $dropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
                 $dropFolderIdToDropFolderCache[$dropFolderId] = $dropFolder;
             }
             if ($dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY) {
                 if ($dropFolder->getAutoFileDeleteDays() == 0) {
                     $newDropFolderFileStatus = DropFolderFileStatus::DELETED;
                     // Mark for immediate deletion
                 } else {
                     $newDropFolderFileStatus = DropFolderFileStatus::HANDLED;
                 }
             }
         }
         KalturaLog::info("Entry id [{$entry->getId()}] status [{$entryStatus}], drop folder file id [{$dropFolderFile->getId()}] status [{$dropFolderFile->getStatus()}] => [" . ($newDropFolderFileStatus ? $newDropFolderFileStatus : "{$dropFolderFile->getStatus()} (unchanged)") . "]");
         if ($newDropFolderFileStatus) {
             $dropFolderFile->setStatus($newDropFolderFileStatus);
             $dropFolderFile->save();
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(DropFolderFilePeer::DATABASE_NAME);
     $criteria->add(DropFolderFilePeer::ID, $this->id);
     if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(DropFolderFilePeer::UPDATED_AT)) {
         $theModifiedColumn = null;
         foreach ($this->modifiedColumns as $modifiedColumn) {
             if ($modifiedColumn != DropFolderFilePeer::UPDATED_AT) {
                 $theModifiedColumn = $modifiedColumn;
             }
         }
         $atomicColumns = DropFolderFilePeer::getAtomicColumns();
         if (in_array($theModifiedColumn, $atomicColumns)) {
             $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
         }
     }
     return $criteria;
 }
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(DropFolderFilePeer::DATABASE_NAME);
     $criteria->add(DropFolderFilePeer::ID, $this->id);
     if ($this->alreadyInSave) {
         if ($this->isColumnModified(DropFolderFilePeer::CUSTOM_DATA)) {
             if (!is_null($this->custom_data_md5)) {
                 $criteria->add(DropFolderFilePeer::CUSTOM_DATA, "MD5(cast(" . DropFolderFilePeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM);
             } else {
                 $criteria->add(DropFolderFilePeer::CUSTOM_DATA, NULL, Criteria::ISNULL);
             }
         }
         if (count($this->modifiedColumns) == 2 && $this->isColumnModified(DropFolderFilePeer::UPDATED_AT)) {
             $theModifiedColumn = null;
             foreach ($this->modifiedColumns as $modifiedColumn) {
                 if ($modifiedColumn != DropFolderFilePeer::UPDATED_AT) {
                     $theModifiedColumn = $modifiedColumn;
                 }
             }
             $atomicColumns = DropFolderFilePeer::getAtomicColumns();
             if (in_array($theModifiedColumn, $atomicColumns)) {
                 $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
             }
         }
     }
     return $criteria;
 }
 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;
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(DropFolderFilePeer::DATABASE_NAME);
         $criteria->add(DropFolderFilePeer::ID, $pks, Criteria::IN);
         $objs = DropFolderFilePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 private function newFileAddedOrDetected(KalturaDropFolderFile $dropFolderFile, $fileStatus)
 {
     // check for required parameters
     $dropFolderFile->validatePropertyNotNull('dropFolderId');
     $dropFolderFile->validatePropertyNotNull('fileName');
     $dropFolderFile->validatePropertyMinValue('fileSize', 0);
     // check that drop folder id exists in the system
     $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->dropFolderId);
     if (!$dropFolder) {
         throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_NOT_FOUND, $dropFolderFile->dropFolderId);
     }
     // save in database
     $dropFolderFile->status = null;
     $dbDropFolderFile = $dropFolderFile->toInsertableObject();
     /* @var $dbDropFolderFile DropFolderFile  */
     $dbDropFolderFile->setPartnerId($dropFolder->getPartnerId());
     $dbDropFolderFile->setStatus($fileStatus);
     $dbDropFolderFile->setType($dropFolder->getType());
     try {
         $dbDropFolderFile->save();
     } catch (PropelException $e) {
         if ($e->getCause() && $e->getCause()->getCode() == self::MYSQL_CODE_DUPLICATE_KEY) {
             $existingDropFolderFile = DropFolderFilePeer::retrieveByDropFolderIdAndFileName($dropFolderFile->dropFolderId, $dropFolderFile->fileName);
             switch ($existingDropFolderFile->getStatus()) {
                 case DropFolderFileStatus::PARSED:
                     KalturaLog::info('Exisiting file status is PARSED, updating status to [' . $fileStatus . ']');
                     $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile);
                     $existingDropFolderFile->setStatus($fileStatus);
                     $existingDropFolderFile->save();
                     $dbDropFolderFile = $existingDropFolderFile;
                     break;
                 case DropFolderFileStatus::DETECTED:
                     KalturaLog::info('Exisiting file status is DETECTED, updating status to [' . $fileStatus . ']');
                     $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile);
                     if ($existingDropFolderFile->getStatus() != $fileStatus) {
                         $existingDropFolderFile->setStatus($fileStatus);
                     }
                     $existingDropFolderFile->save();
                     $dbDropFolderFile = $existingDropFolderFile;
                     break;
                 case DropFolderFileStatus::UPLOADING:
                     if ($fileStatus == DropFolderFileStatus::UPLOADING) {
                         KalturaLog::log('Exisiting file status is UPLOADING, updating properties');
                         $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile);
                         $existingDropFolderFile->save();
                         $dbDropFolderFile = $existingDropFolderFile;
                         break;
                     }
                 default:
                     KalturaLog::log('Setting current file to PURGED [' . $existingDropFolderFile->getId() . ']');
                     $existingDropFolderFile->setStatus(DropFolderFileStatus::PURGED);
                     $existingDropFolderFile->save();
                     $newDropFolderFile = $dbDropFolderFile->copy();
                     if ($existingDropFolderFile->getLeadDropFolderFileId() && $existingDropFolderFile->getLeadDropFolderFileId() != $existingDropFolderFile->getId()) {
                         KalturaLog::info('Updating lead id [' . $existingDropFolderFile->getLeadDropFolderFileId() . ']');
                         $newDropFolderFile->setLeadDropFolderFileId($existingDropFolderFile->getLeadDropFolderFileId());
                     }
                     $newDropFolderFile->save();
                     $dbDropFolderFile = $newDropFolderFile;
             }
         } else {
             throw $e;
         }
     }
     // return the saved object
     $dropFolderFile = KalturaDropFolderFile::getInstanceByType($dbDropFolderFile->getType());
     $dropFolderFile->fromObject($dbDropFolderFile, $this->getResponseProfile());
     return $dropFolderFile;
 }
 public function getFieldNameFromPeer($field_name)
 {
     $res = DropFolderFilePeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     return $res;
 }
 /**
  * 1. add resource in status PARSED
  * 2. if already exist, but is not processed yet update lead drop folder file id
  * 3. if already processed, mark processed file as purged and create new row in status PARSED
  * @param string $fileName
  * @param DropFolderFile $leadFile
  * @param DropFolder $folder
  * @throws Exception
  */
 private function addParsedContentResourceFile($fileName, DropFolderFile $leadFile, DropFolder $folder)
 {
     KalturaLog::debug('Trying to add content resource in status PARSED [' . $fileName . ']');
     try {
         $newFile = new DropFolderFile();
         $newFile->setDropFolderId($folder->getId());
         $newFile->setFileName($fileName);
         $newFile->setFileSize(0);
         $newFile->setStatus(DropFolderFileStatus::PARSED);
         $newFile->setLeadDropFolderFileId($leadFile->getId());
         $newFile->setPartnerId($folder->getPartnerId());
         $newFile->save();
     } catch (PropelException $e) {
         if ($e->getCause() && $e->getCause()->getCode() == kDropFolderXmlEventsConsumer::MYSQL_CODE_DUPLICATE_KEY) {
             $existingFile = DropFolderFilePeer::retrieveByDropFolderIdAndFileName($folder->getId(), $fileName);
             if ($existingFile) {
                 $unprocessedStatuses = array(DropFolderFileStatus::WAITING, DropFolderFileStatus::DETECTED, DropFolderFileStatus::UPLOADING, DropFolderFileStatus::PENDING);
                 if (in_array($existingFile->getStatus(), $unprocessedStatuses)) {
                     KalturaLog::debug('Updating drop folder file [' . $existingFile->getId() . '] with lead id [' . $leadFile->getId() . ']');
                     $existingFile->setLeadDropFolderFileId($leadFile->getId());
                     $existingFile->save();
                 } else {
                     KalturaLog::debug('Deleting drop folder file [' . $existingFile->getId() . ']');
                     $existingFile->setStatus(DropFolderFileStatus::PURGED);
                     $existingFile->save();
                     KalturaLog::debug('Adding new drop folder file [' . $newFile->getFileName() . '] with status PARSED');
                     $newFileCopy = $newFile->copy();
                     $newFileCopy->save();
                 }
             }
         } else {
             KalturaLog::err('Failed to add content resource for Xml file [' . $leadFile->getId() . '] - ' . $e->getMessage());
             throw new Exception(DropFolderXmlBulkUploadPlugin::ERROR_ADD_CONTENT_RESOURCE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::ERROR_ADD_CONTENT_RESOURCE));
         }
     }
 }
 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 static function cleanMemory()
 {
     DropFolderPeer::clearInstancePool();
     DropFolderFilePeer::clearInstancePool();
 }
 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();
 }