/**
  * @param string $entryId
  * @param FileSync $object
  * @param int $fileSyncId
  * @param string $sourceFileUrl
  * @return BatchJob
  */
 public static function addFileSyncImportJob($entryId, FileSync $fileSync, $sourceFileUrl, BatchJob $parentJob = null, $fileSize = null)
 {
     $partnerId = $fileSync->getPartnerId();
     $fileSyncId = $fileSync->getId();
     $dc = $fileSync->getDc();
     KalturaLog::log(__METHOD__ . " entryId[{$entryId}], partnerId[{$partnerId}], fileSyncId[{$fileSyncId}], sourceFileUrl[{$sourceFileUrl}]");
     $fileSyncImportData = new kFileSyncImportJobData();
     $fileSyncImportData->setSourceUrl($sourceFileUrl);
     $fileSyncImportData->setFilesyncId($fileSyncId);
     $fileSyncImportData->setFileSize($fileSize);
     // tmpFilePath and destFilePath will be set later during get exlusive call on the target data center
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::FILESYNC_IMPORT, null, true, $dc);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setDc($dc);
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($partnerId);
     }
     $batchJob->setObjectId($fileSyncId);
     $batchJob->setObjectType(BatchJobObjectType::FILE_SYNC);
     //In case file sync is of type data and holds flavor asset than we need to check if its the source asset that is being synced and raise it sync priority
     if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET && $fileSync->getObjectSubType() == entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA && $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_FILE) {
         $assetdb = assetPeer::retrieveById($fileSync->getObjectId());
         if ($assetdb) {
             $isSourceAsset = $assetdb->getIsOriginal();
             if ($isSourceAsset) {
                 $fileSyncImportData->setIsSourceAsset(true);
             }
         }
     }
     KalturaLog::log("Creating Filesync Import job, with file sync id: {$fileSyncId} size: {$fileSize}");
     return kJobsManager::addJob($batchJob, $fileSyncImportData, BatchJobType::FILESYNC_IMPORT);
 }
 /**
  * @param string $entryId
  * @param FileSync $object
  * @param int $fileSyncId
  * @param string $sourceFileUrl
  * @return BatchJob
  */
 public static function addFileSyncImportJob($entryId, FileSync $fileSync, $sourceFileUrl, BatchJob $parentJob = null, $fileSize = null)
 {
     $partnerId = $fileSync->getPartnerId();
     $fileSyncId = $fileSync->getId();
     $dc = $fileSync->getDc();
     KalturaLog::log(__METHOD__ . " entryId[{$entryId}], partnerId[{$partnerId}], fileSyncId[{$fileSyncId}], sourceFileUrl[{$sourceFileUrl}]");
     $fileSyncImportData = new kFileSyncImportJobData();
     $fileSyncImportData->setSourceUrl($sourceFileUrl);
     $fileSyncImportData->setFilesyncId($fileSyncId);
     // tmpFilePath and destFilePath will be set later during get exlusive call on the target data center
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(true, $dc);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setDc($dc);
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($partnerId);
     }
     $batchJob->setFileSize($fileSize);
     KalturaLog::log("Creating Filesync Import job, with file sync id: {$fileSyncId} size: {$fileSize}");
     return kJobsManager::addJob($batchJob, $fileSyncImportData, BatchJobType::FILESYNC_IMPORT);
 }
 /**
  * Get the FileSyncKey object by its file sync object
  *
  * @param FileSync $fileSync
  * @return FileSyncKey
  */
 public static function getKeyForFileSync(FileSync $fileSync)
 {
     $key = new FileSyncKey();
     $key->object_type = $fileSync->getObjectType();
     $key->object_id = $fileSync->getObjectId();
     $key->version = $fileSync->getVersion();
     $key->object_sub_type = $fileSync->getObjectSubType();
     $key->partner_id = $fileSync->getPartnerId();
     return $key;
 }
 /**
  * @param FileSync $fileSync
  */
 protected function fileSyncDelete(FileSync $fileSync, BatchJob $raisedJob = null)
 {
     $partnerId = $fileSync->getPartnerId();
     $purgePermission = PermissionPeer::isValidForPartner('PURGE_FILES_ON_DELETE', $partnerId);
     if ($purgePermission) {
         $syncKey = kFileSyncUtils::getKeyForFileSync($fileSync);
         kJobsManager::addDeleteFileJob($raisedJob, null, $partnerId, $syncKey, $fileSync->getFullPath(), $fileSync->getDc());
     }
 }
Exemple #5
0
 /**
  * 
  * Handle deleteion of original entries file sync when in the process of entry replacement.
  * @param FileSync $fileSync
  * @param array $fileSyncSubTypesToHandle
  */
 private static function handleEntryReplacementFileSyncDeletion(FileSync $fileSync, $fileSyncSubTypesToHandle)
 {
     $c = new Criteria();
     $c->add(FileSyncPeer::FILE_TYPE, array(FileSync::FILE_SYNC_FILE_TYPE_URL, FileSync::FILE_SYNC_FILE_TYPE_FILE), Criteria::IN);
     $c->add(FileSyncPeer::OBJECT_TYPE, $fileSync->getObjectType());
     $c->add(FileSyncPeer::OBJECT_SUB_TYPE, $fileSync->getObjectSubType());
     $c->add(FileSyncPeer::PARTNER_ID, $fileSync->getPartnerId());
     $c->add(FileSyncPeer::LINKED_ID, $fileSync->getId());
     $originalEntryFileSync = FileSyncPeer::doSelectOne($c);
     if (!$originalEntryFileSync) {
         KalturaLog::info("Origianl entry file sync not found with the following details: [object_type, object_sub_type, Partner_id, Linked_id] [" . $fileSync->getObjectType() . ", " . $fileSync->getObjectSubType() . ", " . $fileSync->getPartnerId() . ", " . $fileSync->getId() . "]");
         return;
     }
     $originalAssetToDeleteFileSyncFor = assetPeer::retrieveById($originalEntryFileSync->getObjectId());
     if (!$originalAssetToDeleteFileSyncFor) {
         KalturaLog::info("Could not find asset matching file sync object id " . $originalEntryFileSync->getObjectId());
         return;
     }
     foreach ($fileSyncSubTypesToHandle as $fileSyncSubType) {
         $syncKeyToDelete = $originalAssetToDeleteFileSyncFor->getSyncKey($fileSyncSubType);
         kFileSyncUtils::deleteSyncFileForKey($syncKeyToDelete, false, true);
     }
 }