/**
  * @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();
     }
 }
 /**
  * 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;
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!$object_to_fill) {
         $object_to_fill = new kDropFolderFileResource();
     }
     $object_to_fill = parent::toObject($object_to_fill, $props_to_skip);
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId);
     if (!$dropFolderFile) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId);
     }
     $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId());
     if (!$dropFolder) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFile->getDropFolderId());
     }
     $object_to_fill->setDropFolderFileId($dropFolderFile->getId());
     $fullPath = $dropFolder->getPath() . '/' . $dropFolderFile->getFileName();
     $object_to_fill->setLocalFilePath($fullPath);
     if ($dropFolder->getType() == DropFolderType::LOCAL) {
         // if the drop folder is set to automatic with immidate deletion of files (days = 0) move the files instead of copying them.
         // this will result in fast handling of drop folder files
         $deleteOriginalFile = $dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE && $dropFolder->getAutoFileDeleteDays() == 0;
         $object_to_fill->setKeepOriginalFile(!$deleteOriginalFile);
         $object_to_fill->setIsReady(true);
     } else {
         $object_to_fill->setKeepOriginalFile(false);
         $object_to_fill->setIsReady(false);
     }
     return $object_to_fill;
 }
 public function shouldConsumeChangedEvent(BaseObject $object, array $modifiedColumns)
 {
     try {
         if ($object instanceof DropFolderFile && ($object->getStatus() == DropFolderFileStatus::PENDING || $object->getStatus() == DropFolderFileStatus::PURGED) && in_array(DropFolderFilePeer::STATUS, $modifiedColumns)) {
             $folder = DropFolderPeer::retrieveByPK($object->getDropFolderId());
             if (!$folder) {
                 KalturaLog::err('Failed to process shouldConsumeChangedEvent - Failed to retrieve drop folder with ID ' . $object->getDropFolderId());
                 return false;
             }
             if ($folder->getFileHandlerType() == DropFolderXmlBulkUploadPlugin::getFileHandlerTypeCoreValue(DropFolderXmlFileHandlerType::XML)) {
                 return true;
             }
         }
     } catch (Exception $e) {
         KalturaLog::err('Failed to process shouldConsumeChangedEvent - ' . $e->getMessage());
     }
     return false;
 }
 /**
  * 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();
         }
     }
 }
Esempio n. 6
0
 public function getRootObjects(IRelatedObject $object)
 {
     return array(DropFolderPeer::retrieveByPK($object->getDropFolderId()));
 }
Esempio n. 7
0
 public function getFileUrl()
 {
     $dropFolder = DropFolderPeer::retrieveByPK($this->getDropFolderId());
     return $dropFolder->getFolderUrl() . '/' . $this->getFileName();
 }
Esempio n. 8
0
 /**
  * Mark the KalturaDropFolder object as deleted
  * 
  * @action delete
  * @param int $dropFolderId 
  * @return KalturaDropFolder
  *
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 public function deleteAction($dropFolderId)
 {
     $dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
     if (!$dbDropFolder) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
     }
     $dbDropFolder->setStatus(DropFolderStatus::DELETED);
     $dbDropFolder->save();
     $dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
     $dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
     return $dropFolder;
 }
Esempio n. 9
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;
 }
 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();
 }