/**
  * Update an existing KalturaDropFolderFile object
  * 
  * @action update
  * @param int $dropFolderFileId
  * @param KalturaDropFolderFile $dropFolderFile
  * @return KalturaDropFolderFile
  *
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 public function updateAction($dropFolderFileId, KalturaDropFolderFile $dropFolderFile)
 {
     $dbDropFolderFile = DropFolderFilePeer::retrieveByPK($dropFolderFileId);
     if (!$dbDropFolderFile) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFileId);
     }
     if (!is_null($dropFolderFile->fileSize)) {
         $dropFolderFile->validatePropertyMinValue('fileSize', 0);
     }
     $dbDropFolderFile = $dropFolderFile->toUpdatableObject($dbDropFolderFile);
     $dbDropFolderFile->save();
     $dropFolderFile = new KalturaDropFolderFile();
     $dropFolderFile->fromObject($dbDropFolderFile);
     return $dropFolderFile;
 }
예제 #2
0
 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;
 }