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);
         }
     }
 }
Ejemplo n.º 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      int $partnerId the partner id
  * @param      PropelPDO $con the connection to use
  * @return     array<MetadataProfile>
  */
 public static function retrieveByPartnerId($partnerId, PropelPDO $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(MetadataProfilePeer::PARTNER_ID, $partnerId);
     self::setUseCriteriaFilter(false);
     $ret = MetadataProfilePeer::doSelectOne($criteria, $con);
     self::setUseCriteriaFilter(true);
     return $ret;
 }
Ejemplo n.º 4
0
 public static function retrieveAllActiveByPartnerId($partnerId, $object_type, PropelPDO $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(MetadataProfilePeer::PARTNER_ID, $partnerId);
     if ($object_type) {
         $criteria->add(MetadataProfilePeer::OBJECT_TYPE, $object_type);
     }
     $profiles = MetadataProfilePeer::doSelect($criteria, $con);
     return $profiles;
 }
 public function validateForUsage($sourceObject, $propertiesToSkip = array())
 {
     parent::validateForUsage($sourceObject, $propertiesToSkip);
     $this->validatePropertyNotNull('metadataProfileId');
     $this->validatePropertyNotNull('metadataObjectType');
     $this->validatePropertyNotNull('xslt');
     myPartnerUtils::addPartnerToCriteria('MetadataProfile', kCurrentContext::getCurrentPartnerId(), true);
     $metadataProfile = MetadataProfilePeer::retrieveByPK($this->metadataProfileId);
     if (is_null($metadataProfile)) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $this->metadataProfileId);
     }
 }
Ejemplo n.º 6
0
 protected function updatedTransformMetadataFailed(BatchJob $dbBatchJob, kTransformMetadataJobData $data, BatchJob $twinJob = null)
 {
     if (!$data->getMetadataProfileId()) {
         return $dbBatchJob;
     }
     $metadataProfile = MetadataProfilePeer::retrieveById($data->getMetadataProfileId());
     if (!$metadataProfile) {
         return $dbBatchJob;
     }
     $metadataProfile->setStatus(MetadataProfile::STATUS_DEPRECATED);
     $metadataProfile->save();
     return $dbBatchJob;
 }
Ejemplo n.º 7
0
 /**
  * Retrieve all metadta object by profile.
  *
  * @param      int $metadataProfileId
  * @param      int $metadataProfileVersion
  * @param      PropelPDO $con the connection to use
  * @return     array<Metadata>
  */
 public static function retrieveByProfile($metadataProfileId, $metadataProfileVersion = null, PropelPDO $con = null)
 {
     if (is_null($metadataProfileVersion)) {
         $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId, $con);
         if (!$metadataProfile) {
             return null;
         }
         $metadataProfileVersion = $metadataProfile->getVersion();
     }
     $criteria = new Criteria();
     $criteria->add(MetadataPeer::METADATA_PROFILE_ID, $metadataProfileId);
     $criteria->add(MetadataPeer::METADATA_PROFILE_VERSION, $metadataProfileVersion);
     return MetadataPeer::doSelect($criteria, $con);
 }
Ejemplo n.º 8
0
 protected function updatedTransformMetadataFailed(BatchJob $dbBatchJob, kTransformMetadataJobData $data)
 {
     if (!$data->getMetadataProfileId()) {
         return $dbBatchJob;
     }
     $metadataProfile = MetadataProfilePeer::retrieveByPK($data->getMetadataProfileId());
     if (!$metadataProfile) {
         return $dbBatchJob;
     }
     if ($data->getSrcXslPath()) {
         $metadataProfile->setStatus(MetadataProfile::STATUS_DEPRECATED);
         $metadataProfile->save();
     }
     return $dbBatchJob;
 }
Ejemplo n.º 9
0
 public static function validateMetadataObjects($profileField, $objectIds, &$errorMessage)
 {
     /** @var MetadataProfileField $profileField */
     $subMetadataProfileId = $profileField->getRelatedMetadataProfileId();
     $subMetadataProfile = MetadataProfilePeer::retrieveByPK($subMetadataProfileId);
     if (!$subMetadataProfile) {
         $errorMessage = 'Sub metadata profile ' . $subMetadataProfileId . ' was not found';
         return false;
     }
     $subMetadataObjects = MetadataPeer::retrieveByObjects($subMetadataProfileId, $subMetadataProfile->getObjectType(), $objectIds);
     if (count($subMetadataObjects) != count($objectIds)) {
         $errorMessage = 'One of the following objects: ' . implode(', ', $objectIds) . ' was not found for profile ' . $subMetadataProfileId;
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
 public function getFieldValue(kScope $scope)
 {
     $profileId = $this->profileId;
     if (!$profileId) {
         if (!$this->profileSystemName) {
             KalturaLog::err("No metadata profile id and system-name supplied");
             return null;
         }
         $profile = MetadataProfilePeer::retrieveBySystemName($this->profileSystemName, kCurrentContext::getCurrentPartnerId());
         if (!$profile) {
             KalturaLog::notice("Metadata profile with system-name [{$this->profileSystemName}] not found");
             return null;
         }
         $profileId = $profile->getId();
     }
     $metadata = null;
     if ($scope instanceof accessControlScope || $scope instanceof kStorageProfileScope) {
         $metadata = MetadataPeer::retrieveByObject($profileId, MetadataObjectType::ENTRY, $scope->getEntryId());
     } elseif ($scope instanceof kEventScope) {
         $object = $scope->getEvent()->getObject();
         if (kMetadataManager::isMetadataObject($object)) {
             $objectType = kMetadataManager::getTypeNameFromObject($object);
             $metadata = MetadataPeer::retrieveByObject($profileId, $objectType, $object->getId());
         } else {
             if ($object instanceof Metadata) {
                 $metadata = $object;
             } elseif ($scope->getEvent()->getObject() instanceof categoryEntry) {
                 $profileObject = kMetadataManager::getObjectTypeName($profile->getObjectType());
                 $getter = "get{$profileObject}Id";
                 KalturaLog::info("Using {$getter} in order to retrieve the metadata object ID");
                 $categoryEntry = $scope->getEvent()->getObject();
                 $objectId = $categoryEntry->{$getter}();
                 $metadata = MetadataPeer::retrieveByObject($profileId, $profile->getObjectType(), $objectId);
             } elseif ($object instanceof asset) {
                 $metadata = MetadataPeer::retrieveByObject($profileId, MetadataObjectType::ENTRY, $object->getEntryId());
             }
         }
     }
     if ($metadata) {
         return kMetadataManager::parseMetadataValues($metadata, $this->xPath);
     }
     KalturaLog::notice("Metadata object not found for scope [" . get_class($scope) . "]");
     return null;
 }
Ejemplo n.º 11
0
 /**
  * batch getExclusiveTransformMetadataJob action allows to get a BatchJob of type METADATA_TRANSFORM 
  * 
  * @action getExclusiveTransformMetadataJobs
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism  
  * @param int $maxExecutionTime The maximum time in seconds the job reguarly take. Is used for the locking mechanism when determining an unexpected termination of a batch-process.
  * @param int $numberOfJobs The maximum number of jobs to return. 
  * @param KalturaBatchJobFilter $filter Set of rules to fetch only rartial list of jobs  
  * @return KalturaBatchJobArray 
  */
 function getExclusiveTransformMetadataJobsAction(KalturaExclusiveLockKey $lockKey, $maxExecutionTime, $numberOfJobs, KalturaBatchJobFilter $filter = null)
 {
     $jobs = $this->getExclusiveJobs($lockKey, $maxExecutionTime, $numberOfJobs, $filter, BatchJobType::METADATA_TRANSFORM);
     if ($jobs) {
         foreach ($jobs as &$job) {
             $data = $job->getData();
             $metadataProfileId = $data->getMetadataProfileId();
             $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
             if (!$metadataProfile) {
                 continue;
             }
             $key = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
             $xsdPath = kFileSyncUtils::getLocalFilePathForKey($key);
             $data->setDestXsdPath($xsdPath);
             $job->setData($data);
         }
     }
     return KalturaBatchJobArray::fromBatchJobArray($jobs);
 }
 /**
  * @param int $fromPartnerId
  * @param int $toPartnerId
  */
 protected function copyMetadataProfiles($fromPartnerId, $toPartnerId)
 {
     KalturaLog::debug("Copy metadata profiles from [{$fromPartnerId}] to [{$toPartnerId}]");
     $c = new Criteria();
     $c->add(MetadataProfilePeer::PARTNER_ID, $fromPartnerId);
     $metadataProfiles = MetadataProfilePeer::doSelect($c);
     foreach ($metadataProfiles as $metadataProfile) {
         $newMetadataProfile = $metadataProfile->copy();
         $newMetadataProfile->setPartnerId($toPartnerId);
         $newMetadataProfile->save();
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION), false);
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS), false);
         $metadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfile->getId());
         foreach ($metadataProfileFields as $metadataProfileField) {
             $newMetadataProfileField = $metadataProfileField->copy();
             $newMetadataProfileField->setMetadataProfileId($newMetadataProfile->getId());
             $newMetadataProfileField->setPartnerId($toPartnerId);
             $newMetadataProfileField->save();
         }
     }
 }
 protected function internalFulfilled(kScope $scope)
 {
     $profileId = $this->profileId;
     if (!$profileId) {
         if (!$this->profileSystemName) {
             return null;
         }
         $profile = MetadataProfilePeer::retrieveBySystemName($this->profileSystemName, kCurrentContext::getCurrentPartnerId());
         if (!$profile) {
             return null;
         }
         $profileId = $profile->getId();
     }
     $metadata = null;
     if ($scope instanceof accessControlScope) {
         $metadata = MetadataPeer::retrieveByObject($profileId, MetadataObjectType::ENTRY, $scope->getEntryId());
     } elseif ($scope instanceof kEventScope && $scope->getEvent() instanceof kApplicativeEvent) {
         $object = $scope->getEvent()->getObject();
         if ($object instanceof Metadata) {
             $metadata = $object;
         } elseif (kMetadataManager::isMetadataObject($object)) {
             $objectType = kMetadataManager::getTypeNameFromObject($object);
             $metadata = MetadataPeer::retrieveByObject($profileId, $objectType, $object->getId());
         }
     }
     if (!$metadata) {
         return false;
     }
     if ($this->versionA) {
         $valuesA = kMetadataManager::parseMetadataValues($metadata, $this->xPath, $this->versionA);
     }
     $valuesB = kMetadataManager::parseMetadataValues($metadata, $this->xPath, $this->versionB);
     if (!$valuesA || !count($valuesA)) {
         //previous MD version does not exist
         $changedValues = $valuesB;
     } else {
         $changedValues = array_diff($valuesA, $valuesB);
     }
     return count($changedValues) > 0;
 }
Ejemplo n.º 14
0
 public function getFieldValue(kScope $scope)
 {
     $profileId = $this->profileId;
     if (!$profileId) {
         if (!$this->profileSystemName) {
             return null;
         }
         $profile = MetadataProfilePeer::retrieveBySystemName($this->profileSystemName, kCurrentContext::getCurrentPartnerId());
         if (!$profile) {
             return null;
         }
         $profileId = $profile->getId();
     }
     $metadata = null;
     if ($scope instanceof accessControlScope || $scope instanceof kStorageProfileScope) {
         $metadata = MetadataPeer::retrieveByObject($profileId, MetadataObjectType::ENTRY, $scope->getEntryId());
     } elseif ($scope instanceof kEventScope && $scope->getEvent() instanceof kApplicativeEvent) {
         $object = $scope->getEvent()->getObject();
         if (kMetadataManager::isMetadataObject($object)) {
             $objectType = kMetadataManager::getTypeNameFromObject($object);
             $metadata = MetadataPeer::retrieveByObject($profileId, $objectType, $object->getId());
         } else {
             if ($object instanceof Metadata) {
                 $metadata = $object;
             }
         }
     }
     if (!$metadata) {
         return null;
     }
     $values = kMetadataManager::parseMetadataValues($metadata, $this->xPath);
     if (is_null($values)) {
         return null;
     }
     return array_map('intval', $values);
 }
Ejemplo n.º 15
0
 public function adjustAssetParams($entryId, array &$flavors)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!isset($entry)) {
         KalturaLog::warning("Bad entry id ({$entryId}).");
         return;
     }
     $partnerId = $entry->getPartnerId();
     $profile = MetadataProfilePeer::retrieveBySystemName(self::TRANSCODING_METADATA_PROF_SYSNAME, $partnerId);
     if (!isset($profile)) {
         KalturaLog::log("No Transcoding Metadata Profile (sysName:" . self::TRANSCODING_METADATA_PROF_SYSNAME . ", partner:{$partnerId}). Nothing to adjust");
         return;
     }
     $metadata = MetadataPeer::retrieveByObject($profile->getId(), MetadataObjectType::ENTRY, $entryId);
     if (!isset($metadata)) {
         KalturaLog::log("No Metadata for entry({$entryId}), metadata profile (id:" . $profile->getId() . "). Nothing to adjust");
         return;
     }
     KalturaLog::log("Entry ({$entryId}) has following metadata fields:" . print_r($metadata, 1));
     // Retrieve the associated XML file
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     if (!isset($key)) {
         KalturaLog::log("Entry({$entryId}) metadata object misses file sync key! Nothing to adjust");
         return;
     }
     $xmlStr = kFileSyncUtils::file_get_contents($key, true, false);
     if (!isset($xmlStr)) {
         KalturaLog::log("Entry({$entryId}) metadata object misses valid file sync! Nothing to adjust");
         return;
     }
     KalturaLog::log("Adjusting: entry({$entryId}),metadata profile(" . self::TRANSCODING_METADATA_PROF_SYSNAME . "),xml==>{$xmlStr}");
     $watermarkSettingsStr = null;
     $imageEntry = null;
     $imageUrl = null;
     // Retrieve the custom metadata fields from the asocieted XML
     $xml = new SimpleXMLElement($xmlStr);
     $fldName = self::TRANSCODING_METADATA_WATERMMARK_SETTINGS;
     if (isset($xml->{$fldName})) {
         $watermarkSettingsStr = (string) $xml->{$fldName};
         KalturaLog::log("Found metadata - {$fldName}({$watermarkSettingsStr})");
     }
     $fldName = self::TRANSCODING_METADATA_WATERMMARK_IMAGE_ENTRY;
     if (isset($xml->{$fldName})) {
         $imageEntry = (string) $xml->{$fldName};
         KalturaLog::log("Found metadata - {$fldName}({$imageEntry})");
     }
     $fldName = self::TRANSCODING_METADATA_WATERMMARK_IMAGE_URL;
     if (isset($xml->{$fldName})) {
         $imageUrl = (string) $xml->{$fldName};
         KalturaLog::log("Found metadata - {$fldName}({$imageUrl})");
     }
     /*
      * The imageEntry is preffered if both imageEntry and url are set,
      * in such case - remove the url
      */
     if (isset($imageEntry) && isset($imageUrl)) {
         KalturaLog::log("Found both " . self::TRANSCODING_METADATA_WATERMMARK_IMAGE_URL . "({$imageEntry}) and {$fldName}({$imageUrl}). Removing {$fldName}");
         $imageUrl = null;
         //
     }
     /*
      * If custom-metadate contains 'full' WM settings ('watermarkSettingsStr' is set), 
      * adjust it to custom meta imageEntry/imageUrl values,
      * if those provided.
      */
     if (isset($watermarkSettingsStr)) {
         $watermarkSettings = json_decode($watermarkSettingsStr);
         $this->adjustWatermarSettings($watermarkSettings, $imageEntry, $imageUrl);
     }
     /*
      * Loop through the flavor params to update the WM settings,
      * if it is required.
      */
     foreach ($flavors as $k => $flavor) {
         KalturaLog::log("Processing flavor id:" . $flavor->getId());
         $wmDataObj = null;
         /*
          * The 'full' WM settings in the custom metadata overides any exitings WM settings 
          */
         if (isset($watermarkSettings)) {
             $wmDataObj = clone $watermarkSettings;
         } else {
             /*
              * No 'full' settings.
              * Adjust the existing flavor WM data with custom metadata imageEntry/imageUrl
              */
             $wmDataStr = $flavor->getWatermarkData();
             if (isset($wmDataStr)) {
                 $wmDataObj = json_decode($wmDataStr);
                 if ($this->adjustWatermarSettings($wmDataObj, $imageEntry, $imageUrl) == false) {
                     continue;
                 }
             }
         }
         if (isset($wmDataObj)) {
             $toJson = json_encode($wmDataObj);
             $flavor->setWatermarkData($toJson);
             $flavors[$k] = $flavor;
             KalturaLog::log("Set flavor (" . $flavor->getId() . ") WM to {$toJson}");
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * @param      int $partnerId
  * @param      int $objectType
  * @return     array<MetadataProfileField>
  */
 public static function retrieveIndexableByPartnerAndType($partnerId, $objectType)
 {
     $criteria = new Criteria();
     $criteria->addSelectColumn(MetadataProfilePeer::ID);
     $criteria->add(MetadataProfilePeer::PARTNER_ID, $partnerId);
     $criteria->add(MetadataProfilePeer::OBJECT_TYPE, $objectType);
     $stmt = MetadataProfilePeer::doSelectStmt($criteria);
     $metadataProfileIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
     $criteria = new Criteria();
     $criteria->add(MetadataProfileFieldPeer::PARTNER_ID, $partnerId);
     $criteria->add(MetadataProfileFieldPeer::METADATA_PROFILE_ID, $metadataProfileIds, Criteria::IN);
     $criteria->add(MetadataProfileFieldPeer::STATUS, MetadataProfileField::STATUS_ACTIVE, Criteria::EQUAL);
     $criteria->add(MetadataProfileFieldPeer::SEARCH_INDEX, null, Criteria::ISNOTNULL);
     return MetadataProfileFieldPeer::doSelect($criteria);
 }
 public static function parseXml($objectType, SimpleXMLElement $scene, $partnerId, CuePoint $cuePoint)
 {
     $metadataElements = $scene->xpath('scene-customData');
     if (!count($metadataElements)) {
         return $cuePoint;
     }
     foreach ($metadataElements as $metadataElement) {
         $metadata = null;
         $metadataProfile = null;
         if (isset($metadataElement['metadataId'])) {
             $metadata = MetadataPeer::retrieveByPK($metadataElement['metadataId']);
         }
         if ($metadata) {
             $metadataProfile = $metadata->getMetadataProfile();
         } else {
             if (isset($metadataElement['metadataProfileId'])) {
                 $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataElement['metadataProfileId']);
             } elseif (isset($metadataElement['metadataProfile'])) {
                 $metadataProfile = MetadataProfilePeer::retrieveBySystemName($metadataElement['metadataProfile']);
             }
             if ($metadataProfile) {
                 $metadata = MetadataPeer::retrieveByObject($metadataProfile->getId(), $objectType, $cuePoint->getId());
             }
         }
         if (!$metadataProfile) {
             continue;
         }
         if (!$metadata) {
             $metadata = new Metadata();
             $metadata->setPartnerId($partnerId);
             $metadata->setMetadataProfileId($metadataProfile->getId());
             $metadata->setMetadataProfileVersion($metadataProfile->getVersion());
             $metadata->setObjectType($objectType);
             $metadata->setObjectId($cuePoint->getId());
             $metadata->setStatus(KalturaMetadataStatus::VALID);
             foreach ($metadataElement->children() as $metadataContent) {
                 $xmlData = $metadataContent->asXML();
                 $errorMessage = '';
                 if (kMetadataManager::validateMetadata($metadataProfile->getId(), $xmlData, $errorMessage)) {
                     $metadata->save();
                     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
                     kFileSyncUtils::file_put_contents($key, $xmlData);
                     kEventsManager::raiseEvent(new kObjectDataChangedEvent($metadata));
                 }
                 break;
             }
         }
     }
     return $cuePoint;
 }
Ejemplo n.º 18
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(MetadataProfilePeer::DATABASE_NAME);
     $criteria->add(MetadataProfilePeer::ID, $this->id);
     if ($this->alreadyInSave) {
         if ($this->isColumnModified(MetadataProfilePeer::CUSTOM_DATA)) {
             if (!is_null($this->custom_data_md5)) {
                 $criteria->add(MetadataProfilePeer::CUSTOM_DATA, "MD5(cast(" . MetadataProfilePeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM);
             } else {
                 $criteria->add(MetadataProfilePeer::CUSTOM_DATA, NULL, Criteria::ISNULL);
             }
         }
         if (count($this->modifiedColumns) == 2 && $this->isColumnModified(MetadataProfilePeer::UPDATED_AT)) {
             $theModifiedColumn = null;
             foreach ($this->modifiedColumns as $modifiedColumn) {
                 if ($modifiedColumn != MetadataProfilePeer::UPDATED_AT) {
                     $theModifiedColumn = $modifiedColumn;
                 }
             }
             $atomicColumns = MetadataProfilePeer::getAtomicColumns();
             if (in_array($theModifiedColumn, $atomicColumns)) {
                 $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
             }
         }
     }
     return $criteria;
 }
Ejemplo n.º 19
0
 /**
  * @return MetadataProfile
  */
 public function getMetadataProfile()
 {
     if ($this->aMetadataProfile === null && $this->metadata_profile_id) {
         $this->aMetadataProfile = MetadataProfilePeer::retrieveById($this->metadata_profile_id);
     }
     return $this->aMetadataProfile;
 }
Ejemplo n.º 20
0
 /**
  * Serves metadata profile view file
  *
  * @action serveView
  * @param int $id
  * @return file
  *
  * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 public function serveViewAction($id)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $id);
     }
     $fileName = $dbMetadataProfile->getSystemName() . '.xml';
     $fileSubType = MetadataProfile::FILE_SYNC_METADATA_VIEWS;
     return $this->serveFile($dbMetadataProfile, $fileSubType, $fileName);
 }
// ---------------------------------------------------------------------------
$xsltFilePath = '';
//TODO: change to valid xslt file path
$metadataProfileId = null;
//TODO: change to a valid metadata profile id
// ---------------------------------------------------------------------------
if (!$xsltFilePath) {
    die('ERROR - Missing parameter [$xsltFilePath]' . PHP_EOL);
}
if (!$metadataProfileId) {
    die('ERROR - Missing parameter [$metadataProfileId]' . PHP_EOL);
}
if (!file_exists($xsltFilePath)) {
    die('ERROR - Cannot find file at [' . $xsltFilePath . ']' . PHP_EOL);
}
require_once dirname(__FILE__) . '/../bootstrap.php';
require_once dirname(__FILE__) . '/../../api_v3/bootstrap.php';
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "metadata", "*"));
KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/scripts/' . basename(__FILE__) . '.cache');
KAutoloader::register();
KalturaPluginManager::addPlugin('MetadataPlugin');
$dbMetadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
if (!$dbMetadataProfile) {
    die('ERROR - Cannot find metadata profile with id [' . $metadataProfileId . ']' . PHP_EOL);
}
$dbMetadataProfile->incrementXsltVersion();
$dbMetadataProfile->save();
$key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT);
kFileSyncUtils::moveFromFile($xsltFilePath, $key, true, true);
echo 'Done' . PHP_EOL;
 public function getFieldNameFromPeer($field_name)
 {
     $res = MetadataProfilePeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     return $res;
 }
Ejemplo n.º 23
0
 protected static function init()
 {
     kEventsManager::enableDeferredEvents(false);
     MetadataProfilePeer::setUseCriteriaFilter(false);
     MetadataPeer::setUseCriteriaFilter(false);
     entryPeer::setUseCriteriaFilter(false);
     uiConfPeer::setUseCriteriaFilter(false);
     assetPeer::setUseCriteriaFilter(false);
     PartnerPeer::setUseCriteriaFilter(false);
     FileSyncPeer::setUseCriteriaFilter(false);
     $options = getopt('hrl:p:o:b:e:', array('real-run', 'error-objects', 'old-versions', 'blocked-partners', 'files'));
     if (isset($options['h'])) {
         self::failWrongInputs();
     }
     if (isset($options['blocked-partners'])) {
         self::$deleteDeletedPartnersFileSyncs = true;
     }
     if (isset($options['error-objects'])) {
         self::$deleteErrorObjects = true;
     }
     if (isset($options['old-versions'])) {
         self::$deleteOldVersions = true;
     }
     if (isset($options['files'])) {
         self::$purgeDeletedFileSyncs = true;
     }
     if (isset($options['r']) || isset($options['real-run'])) {
         self::$dryRun = false;
     }
     KalturaStatement::setDryRun(self::$dryRun);
     $cacheFilePath = kConf::get('cache_root_path') . '/scripts/deleteOldContent.cache';
     if (file_exists($cacheFilePath)) {
         $cache = unserialize(file_get_contents($cacheFilePath));
         if (isset($cache['oldVersionsStartUpdatedAt'])) {
             self::$oldVersionsStartUpdatedAt = $cache['oldVersionsStartUpdatedAt'];
         }
         if (isset($cache['purgeStartUpdatedAt'])) {
             self::$purgeStartUpdatedAt = $cache['purgeStartUpdatedAt'];
         }
     }
     if (!self::$purgeStartUpdatedAt) {
         $criteria = new Criteria();
         $criteria->add(FileSyncPeer::UPDATED_AT, 0, Criteria::GREATER_THAN);
         $criteria->add(FileSyncPeer::DC, kDataCenterMgr::getCurrentDcId());
         $criteria->add(FileSyncPeer::STATUS, FileSync::FILE_SYNC_STATUS_DELETED);
         $criteria->addSelectColumn('UNIX_TIMESTAMP(MIN(' . FileSyncPeer::UPDATED_AT . '))');
         $stmt = FileSyncPeer::doSelectStmt($criteria);
         $mins = $stmt->fetchAll(PDO::FETCH_COLUMN);
         if (count($mins)) {
             self::$purgeStartUpdatedAt = reset($mins);
         }
     }
     if (is_null(self::$purgeStartUpdatedAt)) {
         self::$purgeStartUpdatedAt = 0;
     }
     self::$purgeNextStartUpdatedAt = self::$purgeStartUpdatedAt;
     $oldVersionsUpdatedAtPeriod = 30;
     // days
     if (isset($options['o'])) {
         if (!is_numeric($options['o']) || $options['o'] < 0) {
             self::failWrongInputs("Period of old versions to delete must be positive numeric of days");
         }
         $oldVersionsUpdatedAtPeriod = $options['o'];
     }
     foreach (self::$oldVersionsStartUpdatedAt as $objectType => $oldVersionsStartUpdatedAt) {
         self::$oldVersionsEndUpdatedAt[$objectType] = $oldVersionsStartUpdatedAt + $oldVersionsUpdatedAtPeriod * 60 * 60 * 24;
     }
     // days
     $purgeUpdatedAtPeriod = 30;
     // days
     if (isset($options['p'])) {
         if (!is_numeric($options['p']) || $options['p'] < 0) {
             self::failWrongInputs("Period of purge must be positive numeric of days");
         }
         $purgeUpdatedAtPeriod = $options['p'];
     }
     self::$purgeEndUpdatedAt = self::$purgeStartUpdatedAt + $purgeUpdatedAtPeriod * 60 * 60 * 24;
     // days
     $oldPartnersUpdatedAtPeriod = 24;
     // months
     if (isset($options['b'])) {
         if (!is_numeric($options['b']) || $options['b'] < 0) {
             self::failWrongInputs("Period of blocked partners to delete must be positive numeric of months");
         }
         $oldPartnersUpdatedAtPeriod = $options['b'];
     }
     self::$oldPartnersUpdatedAt = time() - $oldPartnersUpdatedAtPeriod * 60 * 60 * 24 * 30;
     // months
     $errObjectsUpdatedAtPeriod = 24;
     // months
     if (isset($options['e'])) {
         if (!is_numeric($options['e']) || $options['e'] < 0) {
             self::failWrongInputs("Period of error objects to delete must be positive numeric of months");
         }
         $errObjectsUpdatedAtPeriod = $options['e'];
     }
     self::$errObjectsUpdatedAt = time() - $errObjectsUpdatedAtPeriod * 60 * 60 * 24 * 30;
     // months
     if (isset($options['l'])) {
         if (!is_numeric($options['l']) || $options['l'] < 0) {
             self::failWrongInputs("Limit querymust be positive numeric value");
         }
         self::$queryLimit = $options['l'];
     }
 }
Ejemplo n.º 24
0
 public static function validateObject(BaseObject $object, $operation)
 {
     if ($operation == IKalturaObjectValidator::OPERATION_COPY) {
         if ($object instanceof Partner) {
             $c = new Criteria();
             $c->add(MetadataProfilePeer::PARTNER_ID, $object->getId());
             $count = MetadataProfilePeer::doCount($c);
             if ($count > kConf::get('copy_partner_limit_metadata_profiles')) {
                 throw new kCoreException("Template partner's number of [metadataProfile] objects exceed allowed limit", kCoreException::TEMPLATE_PARTNER_COPY_LIMIT_EXCEEDED);
             }
         }
     }
 }
Ejemplo n.º 25
0
 private function transformMetadata($metadataProfileId, $xmlData)
 {
     $result = null;
     $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
     if (!$metadataProfile) {
         KalturaLog::err('Cannot find metadata profile id [' . $metadataProfileId . ']');
         return null;
     }
     $metadataXsltKey = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT);
     if (!kFileSyncUtils::file_exists($metadataXsltKey, true)) {
         return null;
     }
     $xsltString = kFileSyncUtils::file_get_contents($metadataXsltKey, true, false);
     if (!$xsltString) {
         return null;
     }
     $xsltParams = array(XsltParameterName::KALTURA_CURRENT_TIMESTAMP => time());
     $xsltErrors = array();
     $xmlDataTransformed = kXml::transformXmlUsingXslt($xmlData, $xsltString, $xsltParams, $xsltErrors);
     if (!empty($xsltErrors)) {
         throw new KalturaAPIException(MetadataErrors::XSLT_VALIDATION_ERROR, implode(',', $xsltErrors));
     }
     if ($xmlDataTransformed) {
         return $xmlDataTransformed;
     }
     KalturaLog::err('Failed XML [$xmlData] transformation for metadata with XSL [$xsltString]');
     return null;
 }
Ejemplo n.º 26
0
 public static function validateProfileFields($partnerId, $xsd)
 {
     $xPaths = array_merge(kXsd::findXpathsByAppInfo($xsd, self::APP_INFO_SEARCH, 'true', false), kXsd::findXpathsByAppInfo($xsd, self::APP_INFO_SEARCH, 'false', false));
     foreach ($xPaths as $xPath => $xPathData) {
         if ($xPathData['type'] === MetadataSearchFilter::KMC_FIELD_TYPE_METADATA_OBJECT && isset($xPathData['metadataProfileId'])) {
             $relatedMetadataProfileId = $xPathData['metadataProfileId'];
             $relatedMetadataProfile = MetadataProfilePeer::retrieveByPK($relatedMetadataProfileId);
             if (!$relatedMetadataProfile) {
                 throw new kCoreException('Metadata profile id [' . $relatedMetadataProfileId . ' was not found', kCoreException::ID_NOT_FOUND, $relatedMetadataProfileId);
             }
         }
     }
 }
 /**
  * @param Partner $fromPartner
  * @param Partner $toPartner
  */
 protected function copyMetadataProfiles(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $fromPartnerId = $fromPartner->getId();
     $toPartnerId = $toPartner->getId();
     KalturaLog::debug("Copy metadata profiles from [{$fromPartnerId}] to [{$toPartnerId}]");
     $c = new Criteria();
     $c->add(MetadataProfilePeer::PARTNER_ID, $fromPartnerId);
     $systemNameCriteria = new Criteria();
     $systemNameCriteria->add(MetadataProfilePeer::PARTNER_ID, $toPartnerId);
     $systemNameCriteria->add(MetadataProfilePeer::STATUS, MetadataProfile::STATUS_ACTIVE);
     $metadataProfiles = MetadataProfilePeer::doSelect($c);
     foreach ($metadataProfiles as $metadataProfile) {
         /* @var $metadataProfile MetadataProfile */
         if ($permissionRequiredOnly && !count($metadataProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!myPartnerUtils::isPartnerPermittedForCopy($toPartner, $metadataProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if ($metadataProfile->getSystemName()) {
             $c = clone $systemNameCriteria;
             $c->add(MetadataProfilePeer::SYSTEM_NAME, $metadataProfile->getSystemName());
             if (MetadataProfilePeer::doCount($c)) {
                 continue;
             }
         }
         $newMetadataProfile = $metadataProfile->copy();
         $newMetadataProfile->setPartnerId($toPartnerId);
         $newMetadataProfile->save();
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION));
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS));
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT));
         $metadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfile->getId());
         foreach ($metadataProfileFields as $metadataProfileField) {
             $newMetadataProfileField = $metadataProfileField->copy();
             $newMetadataProfileField->setMetadataProfileId($newMetadataProfile->getId());
             $newMetadataProfileField->setPartnerId($toPartnerId);
             $newMetadataProfileField->save();
         }
     }
 }
Ejemplo n.º 28
0
 /**
  * @param string $entryId the new created entry
  * @param array $data key => value pairs
  */
 public static function handleBulkUploadData($entryId, array $data)
 {
     KalturaLog::debug("Handle metadata bulk upload data:\n" . print_r($data, true));
     if (!isset($data[self::BULK_UPLOAD_COLUMN_PROFILE_ID])) {
         return;
     }
     $metadataProfileId = $data[self::BULK_UPLOAD_COLUMN_PROFILE_ID];
     $xmlData = null;
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         return;
     }
     //		$criteriaFilter = FileSyncPeer::getCriteriaFilter();
     //		$criteria = $criteriaFilter->getFilter();
     //		$criteria->add(FileSyncPeer::PARTNER_ID, $entry->getPartnerId());
     $metadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
     if (!$metadataProfile) {
         $errorMessage = "Metadata profile [{$metadataProfileId}] not found";
         KalturaLog::err($errorMessage);
         self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
         return;
     }
     if (isset($data[self::BULK_UPLOAD_COLUMN_URL])) {
         try {
             $xmlData = file_get_contents($data[self::BULK_UPLOAD_COLUMN_URL]);
             KalturaLog::debug("Metadata downloaded [" . $data[self::BULK_UPLOAD_COLUMN_URL] . "]");
         } catch (Exception $e) {
             $errorMessage = "Download metadata[" . $data[self::BULK_UPLOAD_COLUMN_URL] . "] error: " . $e->getMessage();
             KalturaLog::err($errorMessage);
             self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
             $xmlData = null;
         }
     } elseif (isset($data[self::BULK_UPLOAD_COLUMN_XML])) {
         $xmlData = $data[self::BULK_UPLOAD_COLUMN_XML];
     } else {
         $metadataProfileFields = array();
         MetadataProfileFieldPeer::setUseCriteriaFilter(false);
         $tmpMetadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfileId);
         MetadataProfileFieldPeer::setUseCriteriaFilter(true);
         foreach ($tmpMetadataProfileFields as $metadataProfileField) {
             $metadataProfileFields[$metadataProfileField->getKey()] = $metadataProfileField;
         }
         KalturaLog::debug("Found fields [" . count($metadataProfileFields) . "] for metadata profile [{$metadataProfileId}]");
         $xml = new DOMDocument();
         $dataFound = false;
         foreach ($data as $key => $value) {
             if (!$value || !strlen($value)) {
                 continue;
             }
             if (!preg_match('/^' . self::BULK_UPLOAD_COLUMN_FIELD_PREFIX . '(.+)$/', $key, $matches)) {
                 continue;
             }
             $key = $matches[1];
             if (!isset($metadataProfileFields[$key])) {
                 $errorMessage = "Field [{$key}] does not exist";
                 KalturaLog::debug($errorMessage);
                 self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
                 continue;
             }
             $metadataProfileField = $metadataProfileFields[$key];
             KalturaLog::debug("Found field [" . $metadataProfileField->getXpath() . "] for value [{$value}]");
             $fieldValues = explode(self::BULK_UPLOAD_MULTI_VALUES_DELIMITER, $value);
             foreach ($fieldValues as $fieldValue) {
                 if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE && !is_numeric($fieldValue)) {
                     $value = self::parseFormatedDate($fieldValue);
                     if (!$value || !strlen($value)) {
                         $errorMessage = "Could not parse date format [{$fieldValue}] for field [{$key}]";
                         KalturaLog::debug($errorMessage);
                         self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
                         continue;
                     }
                     $fieldValue = $value;
                 }
                 self::addXpath($xml, $metadataProfileField->getXpath(), $fieldValue);
             }
             $dataFound = true;
         }
         if ($dataFound) {
             $xmlData = $xml->saveXML($xml->firstChild);
             $xmlData = trim($xmlData, " \n\r\t");
         }
     }
     if (!$xmlData) {
         return;
     }
     $dbMetadata = new Metadata();
     $dbMetadata->setPartnerId($entry->getPartnerId());
     $dbMetadata->setMetadataProfileId($metadataProfileId);
     $dbMetadata->setMetadataProfileVersion($metadataProfile->getVersion());
     $dbMetadata->setObjectType(Metadata::TYPE_ENTRY);
     $dbMetadata->setObjectId($entryId);
     $dbMetadata->setStatus(Metadata::STATUS_INVALID);
     $dbMetadata->save();
     KalturaLog::debug("Metadata [" . $dbMetadata->getId() . "] saved [{$xmlData}]");
     $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     kFileSyncUtils::file_put_contents($key, $xmlData);
     $errorMessage = '';
     $status = kMetadataManager::validateMetadata($dbMetadata, $errorMessage);
     if ($status == Metadata::STATUS_VALID) {
         kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata));
     } else {
         self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
     }
 }
Ejemplo n.º 29
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(MetadataProfilePeer::DATABASE_NAME);
         $criteria->add(MetadataProfilePeer::ID, $pks, Criteria::IN);
         $objs = MetadataProfilePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 30
0
 /**
  * Update an existing metadata object views file
  * 
  * @action updateViewsFromFile
  * @param int $id 
  * @param file $viewsFile UI views file
  * @return KalturaMetadataProfile
  * @throws KalturaErrors::INVALID_OBJECT_ID
  * @throws MetadataErrors::METADATA_FILE_NOT_FOUND
  */
 function updateViewsFromFileAction($id, $viewsFile)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     $filePath = null;
     if ($viewsFile) {
         $filePath = $viewsFile['tmp_name'];
         if (!file_exists($filePath)) {
             throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $viewsFile['name']);
         }
     }
     $dbMetadataProfile->incrementViewsVersion();
     $dbMetadataProfile->save();
     if (trim(file_get_contents($filePath)) != '') {
         $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS);
         kFileSyncUtils::moveFromFile($filePath, $key);
     }
     $metadataProfile = new KalturaMetadataProfile();
     $metadataProfile->fromObject($dbMetadataProfile);
     return $metadataProfile;
 }