/** * Allows you to add a new KalturaDropFolderFile object * * @action add * @param KalturaDropFolderFile $dropFolderFile * @return KalturaDropFolderFile * * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL * @throws KalturaDropFolderErrors::DROP_FOLDER_NOT_FOUND * @throws KalturaDropFolderErrors::DROP_FOLDER_FILE_ALREADY_EXISTS */ public function addAction(KalturaDropFolderFile $dropFolderFile) { // 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); } // check that the file doesn't already exist in the drop folder if (DropFolderFilePeer::retrieveByDropFolderIdAndFileName($dropFolderFile->dropFolderId, $dropFolderFile->fileName)) { throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_FILE_ALREADY_EXISTS, $dropFolderFile->dropFolderId, $dropFolderFile->fileName); } // save in database $dbDropFolderFile = $dropFolderFile->toInsertableObject(); /* @var $dbDropFolderFile DropFolderFile */ $dbDropFolderFile->setPartnerId($dropFolder->getPartnerId()); $dbDropFolderFile->setStatus(DropFolderFileStatus::UPLOADING); $dbDropFolderFile->save(); // return the saved object $dropFolderFile = new KalturaDropFolderFile(); $dropFolderFile->fromObject($dbDropFolderFile); return $dropFolderFile; }
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; }