function createMetadataProfile($version, $versionToXsdMap)
{
    $metadataProfile = new MetadataProfile();
    $metadataProfile->setPartnerId(99);
    $metadataProfile->setStatus(MetadataProfile::STATUS_ACTIVE);
    $metadataProfile->setName('Tvinci ingest v' . $version);
    $metadataProfile->setSystemName('TvinciIngestV' . $version);
    $metadataProfile->setDescription('Tvinci ingest schema version ' . $version);
    $metadataProfile->setObjectType(MetadataObjectType::ENTRY);
    $metadataProfile->setRequiredCopyTemplatePermissions(FEATURE_TVINCI_INGEST_BASE . $version);
    $metadataProfile->save();
    $xsdData = $versionToXsdMap[$version];
    $key = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
    kFileSyncUtils::file_put_contents($key, $xsdData);
    kMetadataManager::parseProfileSearchFields($metadataProfile->getPartnerId(), $metadataProfile);
}
function createMetadataProfile()
{
    $metadataProfile = new MetadataProfile();
    $metadataProfile->setPartnerId(99);
    $metadataProfile->setStatus(MetadataProfile::STATUS_ACTIVE);
    $metadataProfile->setName('Live Stream Monitoring');
    $metadataProfile->setSystemName('LiveMonitor');
    $metadataProfile->setDescription('Email notification flag indicating a 24/7 live-entry should be monitored.');
    $metadataProfile->setObjectType(MetadataObjectType::ENTRY);
    $metadataProfile->setRequiredCopyTemplatePermissions(FEATURE_KALTURA_LIVE_MONITOR);
    $metadataProfile->save();
    $xsdData = '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:element name="metadata">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="Monitor" minOccurs="1" maxOccurs="1">
					<xsd:annotation>
						<xsd:documentation></xsd:documentation>
						<xsd:appinfo>
							<label>Monitor 24/7</label>
							<key>monitor</key>
							<searchable>true</searchable>
							<description>Send E-mail notification if live-stream broadcast stopped</description>
						</xsd:appinfo>
					</xsd:annotation>
					<xsd:simpleType>
						<xsd:restriction base="listType">
							<xsd:enumeration value="on"/>
							<xsd:enumeration value="off"/>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:simpleType name="listType">
		<xsd:restriction base="xsd:string"/>
	</xsd:simpleType>
</xsd:schema>';
    $key = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
    kFileSyncUtils::file_put_contents($key, $xsdData);
    kMetadataManager::parseProfileSearchFields($metadataProfile->getPartnerId(), $metadataProfile);
}
Esempio n. 3
0
 /**
  * Parse the XSD and update the list of search fields
  *
  * @param MetadataProfile $metadataProfile
  * @param partnerId
  *
  * @return TBD
  */
 public static function parseProfileSearchFields($partnerId, MetadataProfile $metadataProfile)
 {
     $key = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     $xsdPath = kFileSyncUtils::getLocalFilePathForKey($key);
     $xPaths = kXsd::findXpathsByAppInfo($xsdPath, self::APP_INFO_SEARCH, 'true');
     MetadataProfileFieldPeer::setUseCriteriaFilter(false);
     $profileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfile->getId());
     MetadataProfileFieldPeer::setUseCriteriaFilter(true);
     // check all existing fields
     foreach ($profileFields as $profileField) {
         /** @var MetadataProfileField $profileField*/
         $xPath = $profileField->getXpath();
         // field removed
         if (!isset($xPaths[$xPath])) {
             $profileField->setStatus(MetadataProfileField::STATUS_DEPRECATED);
             $profileField->save();
             continue;
         }
         $xPathData = $xPaths[$xPath];
         $profileField->setStatus(MetadataProfileField::STATUS_ACTIVE);
         $profileField->setMetadataProfileVersion($metadataProfile->getFileSyncVersion());
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
         }
         self::setAdditionalProfileFieldData($metadataProfile, $profileField, $xPathData);
         $profileField->save();
         unset($xPaths[$xPath]);
     }
     // add new searchable fields
     foreach ($xPaths as $xPath => $xPathData) {
         $profileField = new MetadataProfileField();
         $profileField->setMetadataProfileId($metadataProfile->getId());
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         $profileField->setPartnerId($metadataProfile->getPartnerId());
         $profileField->setStatus(MetadataProfileField::STATUS_ACTIVE);
         $profileField->setXpath($xPath);
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
             self::setAdditionalProfileFieldData($metadataProfile, $profileField, $xPathData);
             $profileField->save();
         }
     }
     // set none searchable existing fields
     $xPaths = kXsd::findXpathsByAppInfo($xsdPath, self::APP_INFO_SEARCH, 'false');
     foreach ($profileFields as $profileField) {
         $xPath = $profileField->getXpath();
         if (!isset($xPaths[$xPath])) {
             continue;
         }
         $xPathData = $xPaths[$xPath];
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
         }
         $profileField->setStatus(MetadataProfileField::STATUS_NONE_SEARCHABLE);
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         $profileField->save();
         self::setAdditionalProfileFieldData($metadataProfile, $profileField, $xPathData);
         unset($xPaths[$xPath]);
     }
     // add new none searchable fields
     foreach ($xPaths as $xPath => $xPathData) {
         $profileField = new MetadataProfileField();
         $profileField->setMetadataProfileId($metadataProfile->getId());
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         $profileField->setPartnerId($metadataProfile->getPartnerId());
         $profileField->setStatus(MetadataProfileField::STATUS_NONE_SEARCHABLE);
         $profileField->setXpath($xPath);
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
             self::setAdditionalProfileFieldData($metadataProfile, $profileField, $xPathData);
         }
         $profileField->save();
     }
 }
 /**
  * Parse the XSD and update the list of search fields
  * 
  * @param MetadataProfile $metadataProfile
  * @param partnerId
  * 
  * @return TBD
  */
 public static function parseProfileSearchFields($partnerId, MetadataProfile $metadataProfile)
 {
     $key = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     $xsdPath = kFileSyncUtils::getLocalFilePathForKey($key);
     $xPaths = kXsd::findXpathsByAppInfo($xsdPath, self::APP_INFO_SEARCH, 'true');
     MetadataProfileFieldPeer::setUseCriteriaFilter(false);
     $profileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfile->getId());
     MetadataProfileFieldPeer::setUseCriteriaFilter(true);
     // check all existing fields
     foreach ($profileFields as $profileField) {
         $xPath = $profileField->getXpath();
         // field removed
         if (!isset($xPaths[$xPath])) {
             $profileField->setStatus(MetadataProfileField::STATUS_DEPRECATED);
             $profileField->save();
             continue;
         }
         $xPathData = $xPaths[$xPath];
         if ($profileField->getStatus() != MetadataProfileField::STATUS_ACTIVE && isset($xPathData['type']) && ($xPathData['type'] == MetadataSearchFilter::KMC_FIELD_TYPE_DATE || $xPathData['type'] == MetadataSearchFilter::KMC_FIELD_TYPE_INT)) {
             $availableSearchIndex = self::getAvailableSearchIndex($partnerId, $metadataProfile->getObjectType());
             if (!isset($availableSearchIndex)) {
                 throw new Exception('could not find available search index');
             }
             $profileField->setSearchIndex($availableSearchIndex);
         }
         $profileField->setStatus(MetadataProfileField::STATUS_ACTIVE);
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
         }
         $profileField->save();
         unset($xPaths[$xPath]);
     }
     // add new searchable fields
     foreach ($xPaths as $xPath => $xPathData) {
         $profileField = new MetadataProfileField();
         $profileField->setMetadataProfileId($metadataProfile->getId());
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         $profileField->setPartnerId($metadataProfile->getPartnerId());
         $profileField->setStatus(MetadataProfileField::STATUS_ACTIVE);
         $profileField->setXpath($xPath);
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
             if ($xPathData['type'] == MetadataSearchFilter::KMC_FIELD_TYPE_DATE || $xPathData['type'] == MetadataSearchFilter::KMC_FIELD_TYPE_INT) {
                 $availableSearchIndex = self::getAvailableSearchIndex($partnerId, $metadataProfile->getObjectType());
                 if (!isset($availableSearchIndex)) {
                     throw new Exception('could not find available search index');
                 }
                 $profileField->setSearchIndex($availableSearchIndex);
             }
             $profileField->save();
         }
     }
     // set none searchable existing fields
     $xPaths = kXsd::findXpathsByAppInfo($xsdPath, self::APP_INFO_SEARCH, 'false');
     foreach ($profileFields as $profileField) {
         $xPath = $profileField->getXpath();
         if (!isset($xPaths[$xPath])) {
             continue;
         }
         $xPathData = $xPaths[$xPath];
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
         }
         $profileField->setStatus(MetadataProfileField::STATUS_NONE_SEARCHABLE);
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         $profileField->save();
         unset($xPaths[$xPath]);
     }
     // add new none searchable fields
     foreach ($xPaths as $xPath => $xPathData) {
         $profileField = new MetadataProfileField();
         $profileField->setMetadataProfileId($metadataProfile->getId());
         $profileField->setMetadataProfileVersion($metadataProfile->getVersion());
         $profileField->setPartnerId($metadataProfile->getPartnerId());
         $profileField->setStatus(MetadataProfileField::STATUS_NONE_SEARCHABLE);
         $profileField->setXpath($xPath);
         if (isset($xPathData['name'])) {
             $profileField->setKey($xPathData['name']);
         }
         if (isset($xPathData['label'])) {
             $profileField->setLabel($xPathData['label']);
         }
         if (isset($xPathData['type'])) {
             $profileField->setType($xPathData['type']);
         }
         $profileField->save();
     }
 }