protected function copyLiveMetadata(baseEntry $object, $liveEntryId)
 {
     $recordedEntryId = $object->getId();
     $partnerId = $object->getPartnerId();
     $metadataProfiles = MetadataProfilePeer::retrieveAllActiveByPartnerId($partnerId, MetadataObjectType::ENTRY);
     foreach ($metadataProfiles as $metadataProfile) {
         $originMetadataObj = MetadataPeer::retrieveByObject($metadataProfile->getId(), MetadataObjectType::ENTRY, $liveEntryId);
         if ($originMetadataObj) {
             $metadataProfileId = $metadataProfile->getId();
             $metadataProfileVersion = $metadataProfile->getVersion();
             $destMetadataObj = new Metadata();
             $destMetadataObj->setPartnerId($partnerId);
             $destMetadataObj->setMetadataProfileId($metadataProfileId);
             $destMetadataObj->setMetadataProfileVersion($metadataProfileVersion);
             $destMetadataObj->setObjectType(MetadataObjectType::ENTRY);
             $destMetadataObj->setObjectId($recordedEntryId);
             $destMetadataObj->setStatus(KalturaMetadataStatus::VALID);
             $originMetadataKey = $originMetadataObj->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
             $originXml = kFileSyncUtils::file_get_contents($originMetadataKey, true, false);
             // validate object exists
             $object = kMetadataManager::getObjectFromPeer($destMetadataObj);
             if ($object) {
                 $destMetadataObj->save();
             } else {
                 KalturaLog::err('invalid object type');
                 continue;
             }
             $destMetadataKey = $destMetadataObj->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
             kFileSyncUtils::file_put_contents($destMetadataKey, $originXml);
         }
     }
 }
Exemple #2
0
 /**
  * Adds a metadata object associated with Kaltura object
  * 
  * @param int $metadataProfileId
  * @param KalturaMetadataObjectType $objectType
  * @param string $objectId
  * @return Metadata
  * @throws MetadataErrors::METADATA_ALREADY_EXISTS
  * @throws MetadataErrors::INVALID_METADATA_PROFILE
  * @throws MetadataErrors::INVALID_METADATA_OBJECT
  */
 protected function addMetadata($metadataProfileId, $objectType, $objectId)
 {
     $check = MetadataPeer::retrieveByObject($metadataProfileId, $objectType, $objectId);
     if ($check) {
         throw new KalturaAPIException(MetadataErrors::METADATA_ALREADY_EXISTS, $check->getId());
     }
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_PROFILE, $metadataProfileId);
     }
     $dbMetadata = new Metadata();
     $dbMetadata->setPartnerId($this->getPartnerId());
     $dbMetadata->setMetadataProfileId($metadataProfileId);
     $dbMetadata->setMetadataProfileVersion($dbMetadataProfile->getVersion());
     $dbMetadata->setObjectType($objectType);
     $dbMetadata->setObjectId($objectId);
     $dbMetadata->setStatus(KalturaMetadataStatus::INVALID);
     // validate object exists
     $object = kMetadataManager::getObjectFromPeer($dbMetadata);
     if (!$object) {
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_OBJECT, $objectId);
     }
     $dbMetadata->save();
     $this->deleteOldVersions($dbMetadata);
     return $dbMetadata;
 }
 /**
  * @param Metadata $metadata
  */
 protected function metadataDeleted(Metadata $metadata)
 {
     $this->syncableDeleted($metadata->getId(), FileSyncObjectType::METADATA);
     // updated in the indexing server (sphinx)
     $object = kMetadataManager::getObjectFromPeer($metadata);
     if ($object && $object instanceof IIndexable) {
         kEventsManager::raiseEvent(new kObjectUpdatedEvent($object));
     }
 }
Exemple #4
0
 /**
  * Index metadata by id, will also index the related object
  *
  * @action index
  * @param string $id
  * @param bool $shouldUpdate
  * @return int
  */
 function indexAction($id, $shouldUpdate)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE);
     }
     $dbMetadata = MetadataPeer::retrieveByPK($id);
     if (!$dbMetadata) {
         throw new KalturaAPIException(MetadataErrors::METADATA_NOT_FOUND, $id);
     }
     $dbMetadata->indexToSearchIndex();
     $relatedObject = kMetadataManager::getObjectFromPeer($dbMetadata);
     if ($relatedObject && $relatedObject instanceof IIndexable) {
         $relatedObject->indexToSearchIndex();
     }
     return $dbMetadata->getId();
 }
 /**
  * Update an existing metadata object definition file
  *
  * @action revert
  * @param int $id
  * @param int $toVersion
  * @return KalturaMetadataProfile
  * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND
  * @throws MetadataErrors::METADATA_FILE_NOT_FOUND
  * @throws MetadataErrors::METADATA_UNABLE_TO_TRANSFORM
  */
 function revertAction($id, $toVersion)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $id);
     }
     $oldKey = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION, $toVersion);
     if (!kFileSyncUtils::fileSync_exists($oldKey)) {
         throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $oldKey);
     }
     $dbMetadataProfile->incrementFileSyncVersion();
     $dbMetadataProfile->incrementVersion();
     $dbMetadataProfile->save();
     $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     kFileSyncUtils::createSyncFileLinkForKey($key, $oldKey);
     kMetadataManager::parseProfileSearchFields($this->getPartnerId(), $dbMetadataProfile);
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::retrieveByProfile($id, $toVersion);
     foreach ($metadatas as $metadata) {
         // validate object exists
         $object = kMetadataManager::getObjectFromPeer($metadata);
         if (!$object) {
             continue;
         }
         $metadata->incrementVersion();
         $oldKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA, $toVersion);
         if (!kFileSyncUtils::fileSync_exists($oldKey)) {
             continue;
         }
         $xml = kFileSyncUtils::file_get_contents($oldKey, true, false);
         if (!$xml) {
             continue;
         }
         $errorMessage = '';
         if (!kMetadataManager::validateMetadata($dbMetadataProfile->getId(), $xml, $errorMessage)) {
             continue;
         }
         $metadata->setMetadataProfileVersion($dbMetadataProfile->getVersion());
         $metadata->setStatus(Metadata::STATUS_VALID);
         $metadata->save();
         $key = $metadata->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
         kFileSyncUtils::createSyncFileLinkForKey($key, $oldKey);
     }
     $metadataProfile = new KalturaMetadataProfile();
     $metadataProfile->fromObject($dbMetadataProfile, $this->getResponseProfile());
     return $metadataProfile;
 }
 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();
     }
     return true;
 }
Exemple #7
0
 public function getRootObjects(IBaseObject $object)
 {
     $parentObject = kMetadataManager::getObjectFromPeer($object);
     $roots = array();
     if ($parentObject && $parentObject instanceof IBaseObject) {
         $parentPeer = $parentObject->getPeer();
         if ($parentPeer instanceof IRelatedObjectPeer) {
             $roots = $parentPeer->getRootObjects($parentObject);
         }
         $roots[] = $parentObject;
     }
     return $roots;
 }
 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;
 }
 /**
  * @param BaseObject $object
  * @param string $previousVersion
  * @return bool true if should continue to the next consumer
  */
 public function objectDataChanged(BaseObject $object, $previousVersion = null)
 {
     if (!class_exists('Metadata') || !$object instanceof Metadata) {
         return true;
     }
     // updated in the indexing server (sphinx)
     $relatedObject = kMetadataManager::getObjectFromPeer($object);
     if ($relatedObject && $relatedObject instanceof IIndexable) {
         $relatedObject->setUpdatedAt(time());
         $relatedObject->save();
     }
     return true;
 }