Пример #1
0
 /**
  * @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);
 }
 protected function doGetFileSyncUrl(FileSync $fileSync)
 {
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return parent::doGetFileSyncUrl($fileSync);
     }
     $partnerPath = myPartnerUtils::getUrlForPartner($fileSync->getPartnerId(), $fileSync->getPartnerId() * 100);
     $objectSubType = $fileSync->getObjectSubType();
     if ($fileSync->getObjectType() == FileSyncObjectType::ENTRY && $objectSubType == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM) {
         return $this->doGetServeIsmUrl($fileSync, $partnerPath, $storage);
     }
     //To Remove - Until the migration process from asset sub type 3 to asset sub type 1 will be completed we need to support both formats
     if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET && $objectSubType == flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ISM) {
         return $this->doGetServeIsmUrl($fileSync, $partnerPath, $storage);
     }
     if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET && $objectSubType == flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET) {
         $asset = assetPeer::retrieveById($fileSync->getObjectId());
         if ($asset->hasTag(assetParams::TAG_ISM_MANIFEST)) {
             return $this->doGetServeIsmUrl($fileSync, $partnerPath, $storage);
         }
     }
     return parent::doGetFileSyncUrl($fileSync);
 }
Пример #4
0
 /**
  * gets a source file of current DC, will make sure all links points to that source
  * are converted to files on all DCs
  *
  * @param FileSyncKey $key
  * @return void
  */
 protected static function convertLinksToFiles(FileSync $fileSync)
 {
     $linkTotalCount = 0;
     /* @var $fileSync FileSync */
     // for each source, find its links and fix them
     $c = new Criteria();
     $c->add(FileSyncPeer::DC, $fileSync->getDc());
     $c->add(FileSyncPeer::FILE_TYPE, array(FileSync::FILE_SYNC_FILE_TYPE_LINK, FileSync::FILE_SYNC_FILE_TYPE_URL), Criteria::IN);
     $c->add(FileSyncPeer::LINKED_ID, $fileSync->getId());
     $c->addAscendingOrderByColumn(FileSyncPeer::PARTNER_ID);
     //relink the links into groups of 100 links
     $c->setLimit(100);
     $links = FileSyncPeer::doSelect($c);
     //check if any links were returned in the do select if not no need to continue
     if (!count($links)) {
         return;
     }
     // choose the first link and convert it to file
     $firstLink = array_shift($links);
     /* @var $firstLink FileSync */
     if ($firstLink) {
         $firstLink->setStatus($fileSync->getStatus());
         $firstLink->setFileSize($fileSync->getFileSize());
         $firstLink->setFileRoot($fileSync->getFileRoot());
         $firstLink->setFilePath($fileSync->getFilePath());
         $firstLink->setFileType($fileSync->getFileType());
         $firstLink->setLinkedId(0);
         // keep it zero instead of null, that's the only way to know it used to be a link.
         $firstLink->setIsDir($fileSync->getIsDir());
         if (!is_null($fileSync->getOriginalDc())) {
             $firstLink->setOriginalDc($fileSync->getOriginalDc());
             $firstLink->unsetOriginalId();
             // recalculate the original id when importing the file sync
         }
         $firstLink->save();
     }
     while (count($links)) {
         // change all the rest of the links to point on the new file sync
         foreach ($links as $link) {
             $linkTotalCount += count($links);
             /* @var $link FileSync */
             $link->setStatus($fileSync->getStatus());
             $link->setLinkedId($firstLink->getId());
             $link->save();
         }
         FileSyncPeer::clearInstancePool();
         $links = FileSyncPeer::doSelect($c);
     }
     if ($firstLink) {
         $firstLink->setLinkCount($linkTotalCount);
         $firstLink->save();
     }
 }
Пример #5
0
 public static function getInternalRemoteUrl(FileSync $file_sync)
 {
     KalturaLog::log("File Sync [{$file_sync->getId()}]");
     // LOG retrieval
     $dc = self::getDcById($file_sync->getDc());
     $file_sync_id = $file_sync->getId();
     $file_hash = md5($dc["secret"] . $file_sync_id);
     // will be verified on the other side to make sure not some attack or external invalid request
     $filename = 'f.' . $file_sync->getFileExt();
     $build_remote_url = $dc["url"] . "/index.php/extwidget/servefile/id/{$file_sync_id}/hash/{$file_hash}/f/{$filename}";
     // or something similar
     return $build_remote_url;
 }
 /**
  * @param FileSync $fileSyncA
  * @param FileSync $fileSyncB
  * @return number
  */
 public static function compareStorageProfiles($fileSyncA, $fileSyncB)
 {
     if (!is_array(self::$storageProfilesOrder) || !count(self::$storageProfilesOrder)) {
         return 0;
     }
     $a = array_search($fileSyncA->getDc(), self::$storageProfilesOrder);
     $b = array_search($fileSyncB->getDc(), self::$storageProfilesOrder);
     if ($a == $b) {
         return 0;
     }
     return $a < $b ? -1 : 1;
 }
Пример #7
0
 private static function isAssetExportFinished(FileSync $fileSync, asset $asset)
 {
     $c = new Criteria();
     $c->addAnd(FileSyncPeer::OBJECT_ID, $fileSync->getObjectId());
     $c->addAnd(FileSyncPeer::OBJECT_TYPE, $fileSync->getObjectType());
     $c->addAnd(FileSyncPeer::VERSION, $fileSync->getVersion());
     $c->addAnd(FileSyncPeer::FILE_TYPE, FileSync::FILE_SYNC_FILE_TYPE_URL);
     $c->addAnd(FileSyncPeer::DC, $fileSync->getDc());
     $c->addAnd(FileSyncPeer::STATUS, Filesync::FILE_SYNC_STATUS_PENDING);
     $pendingFileSync = FileSyncPeer::doSelectOne($c);
     if ($pendingFileSync) {
         return false;
     } else {
         return true;
     }
 }