/**
  * @param flavorAsset $flavorAsset
  * @return boolean true if the given flavor asset is configured to be exported or false otherwise
  */
 public function shouldExportFlavorAsset(flavorAsset $flavorAsset)
 {
     $shouldExport = null;
     // check if flavor params id is in the list to export
     $flavorParamsIdsToExport = $this->getFlavorParamsIds();
     KalturaLog::log(__METHOD__ . " flavorParamsIds [{$flavorParamsIdsToExport}]");
     if (is_null($flavorParamsIdsToExport) || strlen(trim($flavorParamsIdsToExport)) == 0) {
         // all flavor assets should be exported
         $shouldExport = true;
     } else {
         $flavorParamsIdsToExport = array_map('trim', explode(',', $flavorParamsIdsToExport));
         if (in_array($flavorAsset->getFlavorParamsId(), $flavorParamsIdsToExport)) {
             // flavor set to export
             $shouldExport = true;
         } else {
             // flavor not set to export
             $shouldExport = false;
         }
     }
     // check if flavor fits the export rules defined on the profile
     if ($shouldExport) {
         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $shouldExport = kStorageExporter::shouldExport($key, $this);
         if (!$shouldExport) {
             KalturaLog::log("no need to export key [{$key}] to externalStorage id[" . $this->getId() . "]");
         }
     }
     return $shouldExport;
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param flavorAsset $currentFlavorAsset
  * @return BatchJob
  */
 public static function handleConvertFinished(BatchJob $dbBatchJob = null, flavorAsset $currentFlavorAsset)
 {
     KalturaLog::debug("entry id [" . $currentFlavorAsset->getEntryId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "]");
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($currentFlavorAsset->getEntryId());
         KalturaLog::debug("profile [" . $profile->getId() . "]");
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
     }
     $currentReadyBehavior = self::getReadyBehavior($currentFlavorAsset, $profile);
     KalturaLog::debug("Current ready behavior [{$currentReadyBehavior}]");
     if ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
         return $dbBatchJob;
     }
     $rootBatchJob = null;
     if ($dbBatchJob) {
         $rootBatchJob = $dbBatchJob->getRootJob();
     }
     if ($rootBatchJob) {
         KalturaLog::debug("root batch job id [" . $rootBatchJob->getId() . "] type [" . $rootBatchJob->getJobType() . "]");
     }
     // update the root job end exit
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $siblingJobs = $rootBatchJob->getChildJobs();
         foreach ($siblingJobs as $siblingJob) {
             // checking only conversion child jobs
             if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::CONVERT_COLLECTION && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) {
                 continue;
             }
             // if not complete leave function
             if (!in_array($siblingJob->getStatus(), BatchJobPeer::getClosedStatusList())) {
                 KalturaLog::debug("job id [" . $siblingJob->getId() . "] status [" . $siblingJob->getStatus() . "]");
                 return $dbBatchJob;
             }
         }
         KalturaLog::debug("finish bulk download root job");
         // all child jobs completed
         kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         return $dbBatchJob;
     }
     $inheritedFlavorParamsIds = array();
     $requiredFlavorParamsIds = array();
     $flavorParamsConversionProfileItems = array();
     if ($profile) {
         $flavorParamsConversionProfileItems = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     }
     foreach ($flavorParamsConversionProfileItems as $flavorParamsConversionProfile) {
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             $inheritedFlavorParamsIds[] = $flavorParamsConversionProfile->getFlavorParamsId();
         }
     }
     $flavorParamsItems = assetParamsPeer::retrieveByPKs($inheritedFlavorParamsIds);
     foreach ($flavorParamsItems as $flavorParams) {
         if ($flavorParams->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     // go over all the flavor assets of the entry
     $inCompleteFlavorIds = array();
     $origianlAssetFlavorId = null;
     $siblingFlavorAssets = assetPeer::retrieveFlavorsByEntryId($currentFlavorAsset->getEntryId());
     foreach ($siblingFlavorAssets as $siblingFlavorAsset) {
         KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] flavor params id [" . $siblingFlavorAsset->getFlavorParamsId() . "]");
         // don't mark any incomplete flag
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ready");
             if (isset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()])) {
                 unset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()]);
             }
             continue;
         }
         $readyBehavior = self::getReadyBehavior($siblingFlavorAsset, $profile);
         if ($siblingFlavorAsset->getStatus() == flavorAsset::ASSET_STATUS_EXPORTING) {
             if ($siblingFlavorAsset->getIsOriginal()) {
                 $origianlAssetFlavorId = $siblingFlavorAsset->getFlavorParamsId();
             } else {
                 if ($readyBehavior != flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
                     KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
                     $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
                 }
             }
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ignored");
             continue;
         }
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
             $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is required");
             $requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("left required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     KalturaLog::debug("left incomplete flavor ids [" . print_r($inCompleteFlavorIds, true) . "]");
     if (count($requiredFlavorParamsIds)) {
         $inCompleteRequiredFlavorParamsIds = array_keys($requiredFlavorParamsIds);
         foreach ($inCompleteRequiredFlavorParamsIds as $inCompleteFlavorId) {
             $inCompleteFlavorIds[] = $inCompleteFlavorId;
         }
         KalturaLog::debug('Convert Finished - has In-Complete Required flavors [[' . print_r($inCompleteRequiredFlavorParamsIds, true) . ']');
     } elseif ($currentFlavorAsset->getStatus() == asset::ASSET_STATUS_READY && ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL || $currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED)) {
         // mark the entry as ready if all required conversions completed or any of the optionals
         if ($currentFlavorAsset->getentry()->getReplacedEntryId()) {
             KalturaLog::debug('Entry is temporary replacement and requires all flavors to complete');
         } else {
             KalturaLog::debug('Mark the entry as ready');
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
         }
     }
     if ($origianlAssetFlavorId) {
         $inCompleteFlavorIds = array_diff($inCompleteFlavorIds, array($origianlAssetFlavorId));
     }
     if (!count($inCompleteFlavorIds)) {
         KalturaLog::debug('Convert Finished');
         if ($origianlAssetFlavorId && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             kStorageExporter::exportSourceAssetFromJob($rootBatchJob);
         } else {
             // mark the context root job as finished only if all conversion jobs are completed
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
             }
         }
         return $dbBatchJob;
     }
     KalturaLog::debug('Convert Finished - has In-Complete flavors [' . print_r($inCompleteFlavorIds, true) . ']');
     if (!$rootBatchJob || $rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         return $dbBatchJob;
     }
     $childJobs = $rootBatchJob->getChildJobs();
     KalturaLog::debug('Child jobs found [' . count($childJobs) . ']');
     if (count($childJobs) > 1) {
         $allDone = true;
         foreach ($childJobs as $childJob) {
             if ($childJob->getId() != $rootBatchJob->getId() && $childJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED) {
                 KalturaLog::debug('Child job id [' . $childJob->getId() . '] status [' . $childJob->getStatus() . ']');
                 $allDone = false;
             }
         }
         if ($allDone) {
             KalturaLog::debug('All child jobs done, closing profile');
             kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         }
     }
     return $dbBatchJob;
 }
 /**
  * @action export
  * Action for manually exporting an entry
  * @param string $entryId
  * @param int $storageProfileId
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND
  * @return KalturaBaseEntry The exported entry
  */
 public function exportAction($entryId, $storageProfileId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId);
     if (!$dbStorageProfile) {
         throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $storageProfileId);
     }
     kStorageExporter::exportEntry($dbEntry, $dbStorageProfile);
     //TODO: implement export errors
     $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType());
     $entry->fromObject($dbEntry);
     return $entry;
 }
Пример #4
0
 /**
  * @action export
  * Action for manually exporting an entry
  * @param string $entryId
  * @param int $storageProfileId
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND
  * @return KalturaBaseEntry The exported entry
  */
 public function exportAction($entryId, $storageProfileId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId);
     if (!$dbStorageProfile) {
         throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $storageProfileId);
     }
     $scope = $dbStorageProfile->getScope();
     $scope->setEntryId($entryId);
     if (!$dbStorageProfile->fulfillsRules($scope)) {
         throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_RULES_NOT_FULFILLED, $storageProfileId);
     }
     try {
         kStorageExporter::exportEntry($dbEntry, $dbStorageProfile);
     } catch (kCoreException $e) {
         if ($e->getCode() == kCoreException::PROFILE_STATUS_DISABLED) {
             throw new KalturaAPIException(APIErrors::PROFILE_STATUS_DISABLED, $entryId);
         }
     }
     //TODO: implement export errors
     $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType());
     $entry->fromObject($dbEntry, $this->getResponseProfile());
     return $entry;
 }
Пример #5
0
 /**
  * Action for manually exporting an asset
  * @param string $assetId
  * @param int $storageProfileId
  * @throws KalturaErrors::INVALID_FLAVOR_ASSET_ID
  * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND
  * @throws KalturaErrors::INTERNAL_SERVERL_ERROR
  * @return KalturaFlavorAsset The exported asset
  */
 protected function exportAction($assetId, $storageProfileId)
 {
     $dbAsset = assetPeer::retrieveById($assetId);
     if (!$dbAsset) {
         throw new KalturaAPIException(KalturaErrors::INVALID_FLAVOR_ASSET_ID, $assetId);
     }
     $dbStorageProfile = StorageProfilePeer::retrieveByPK($storageProfileId);
     if (!$dbStorageProfile) {
         throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND, $storageProfileId);
     }
     $scope = $dbStorageProfile->getScope();
     $scope->setEntryId($dbAsset->getEntryId());
     if (!$dbStorageProfile->fulfillsRules($scope)) {
         throw new KalturaAPIException(KalturaErrors::STORAGE_PROFILE_RULES_NOT_FULFILLED, $storageProfileId);
     }
     $exported = kStorageExporter::exportFlavorAsset($dbAsset, $dbStorageProfile);
     if ($exported !== true) {
         //TODO: implement export errors
         throw new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR);
     }
     return $this->getAction($assetId);
 }
Пример #6
0
 public function objectDataChanged(BaseObject $object, $previousVersion = null, BatchJob $raisedJob = null)
 {
     // updated in the indexing server (sphinx)
     $relatedObject = kMetadataManager::getObjectFromPeer($object);
     if ($relatedObject && $relatedObject instanceof IIndexable) {
         $relatedObject->setUpdatedAt(time());
         $relatedObject->save();
         $relatedObject->indexToSearchIndex();
     }
     /** @var Metadata $object */
     if ($object->getObjectType() == MetadataObjectType::DYNAMIC_OBJECT && !$object->isLikeNew()) {
         /**
          * when dynamic object is modified, we need to reindex the metadata and the objects (users, entries)
          * that are referencing it
          */
         $profileFields = MetadataProfileFieldPeer::retrieveByPartnerAndRelatedMetadataProfileId($object->getPartnerId(), $object->getMetadataProfileId());
         $relatedMetadataProfiles = array();
         foreach ($profileFields as $profileField) {
             /** @var MetadataProfileField $profileField */
             if (in_array($profileField->getMetadataProfileId(), $relatedMetadataProfiles)) {
                 continue;
             }
             $filter = new MetadataFilter();
             $filter->set('_eq_metadata_profile_id', $profileField->getMetadataProfileId());
             $indexObjectType = kPluginableEnumsManager::apiToCore('IndexObjectType', MetadataPlugin::getApiValue(MetadataIndexObjectType::METADATA));
             kJobsManager::addIndexJob($object->getPartnerId(), $indexObjectType, $filter, true);
             $relatedMetadataProfiles[] = $profileField->getMetadataProfileId();
         }
     }
     if ($relatedObject instanceof entry) {
         kStorageExporter::reExportEntry($relatedObject);
     }
     return true;
 }