Пример #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);
 }
Пример #2
0
 /**
  * @param FileSync $object
  * @return bool true if should continue to the next consumer
  */
 private function addedFileSync(FileSync $object)
 {
     if (!$object instanceof FileSync || $object->getStatus() != FileSync::FILE_SYNC_STATUS_PENDING || $object->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_FILE) {
         return true;
     }
     if ($object->getObjectType() != FileSyncObjectType::FLAVOR_ASSET) {
         return true;
     }
     $flavorAssetId = $object->getObjectId();
     $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId);
     if (!$flavorAsset || !$flavorAsset->getIsOriginal()) {
         return true;
     }
     if ($this->saveIfShouldScan($flavorAsset)) {
         // file sync belongs to a flavor asset in status pending and suits a virus scan profile
         return false;
         // stop all remaining consumers
     }
     return true;
 }
 private function doGetServeIsmUrl(FileSync $fileSync, $partnerPath, StorageProfile $storage = null)
 {
     $serverUrl = $this->getUrl();
     if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_FILE) {
         $path = $partnerPath;
         $path .= '/serveIsm/objectId/' . $fileSync->getObjectId() . '_' . $fileSync->getObjectSubType() . '_' . $fileSync->getVersion();
         $path .= '.' . pathinfo($fileSync->getFilePath(), PATHINFO_EXTENSION) . '/manifest';
     } else {
         if ($storage) {
             $serverUrl = $this->getUrl();
         }
         $path = '/' . $fileSync->getFilePath() . '/manifest';
     }
     $matches = null;
     if (preg_match('/(https?:\\/\\/[^\\/]+)(.*)/', $serverUrl, $matches)) {
         $path = $matches[2] . $path;
     }
     $path = str_replace('//', '/', $path);
     return $path;
 }
Пример #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();
     }
 }
 /**
  * resolve the source filesync when a FileSync input is a LINK
  *
  * @param FileSync $file
  * @return FileSync
  */
 public static function resolve(FileSync $file)
 {
     $parent = null;
     if ($file->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_LINK) {
         $source_file_sync = FileSyncPeer::retrieveByPK($file->getLinkedId());
         if (!$source_file_sync) {
             return $file;
         }
         $parent = self::resolve($source_file_sync);
     }
     if (!$parent) {
         return $file;
     } else {
         return $parent;
     }
 }