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); }
public function postSave(PropelPDO $con = null) { if ($this->xsdData) { $key = $this->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION); kFileSyncUtils::file_put_contents($key, $this->xsdData); kMetadataManager::parseProfileSearchFields($this->getPartnerId(), $this); } if ($this->viewsData) { $key = $this->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS); kFileSyncUtils::file_put_contents($key, $this->viewsData); } if ($this->xsltData) { $key = $this->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT); kFileSyncUtils::file_put_contents($key, $this->xsltData); } return parent::postSave($con); }
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); }
<?php if ($argc != 2) { echo "Arguments missing.\n\n"; echo "Usage: php parseMetadataProfileFields.php {metadata profile id}\n"; exit; } $metadataProfileId = $argv[1]; set_time_limit(0); ini_set("memory_limit", "1024M"); define('ROOT_DIR', realpath(dirname(__FILE__) . '/../../')); require_once ROOT_DIR . '/infra/bootstrap_base.php'; require_once ROOT_DIR . '/infra/KAutoloader.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(); error_reporting(E_ALL); KalturaLog::setLogger(new KalturaStdoutLogger()); $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $metadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId); if (!$metadataProfile) { echo "Metadata Profile not found.\n"; exit; } kMetadataManager::parseProfileSearchFields($metadataProfile);
/** * 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; }
/** * Update an existing metadata object definition file * * @action updateDefinitionFromFile * @param int $id * @param file $xsdFile XSD metadata definition * @return KalturaMetadataProfile * @throws KalturaErrors::INVALID_OBJECT_ID * @throws MetadataErrors::METADATA_FILE_NOT_FOUND * @throws MetadataErrors::METADATA_UNABLE_TO_TRANSFORM */ function updateDefinitionFromFileAction($id, $xsdFile) { $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id); if (!$dbMetadataProfile) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id); } $filePath = null; if ($xsdFile) { $filePath = $xsdFile['tmp_name']; if (!file_exists($filePath)) { throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $xsdFile['name']); } } $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION); $oldXsd = kFileSyncUtils::getLocalFilePathForKey($key); $oldVersion = $dbMetadataProfile->getVersion(); $dbMetadataProfile->incrementVersion(); try { kMetadataManager::diffMetadataProfile($dbMetadataProfile, $oldVersion, $oldXsd, $dbMetadataProfile->getVersion(), $filePath); } catch (kXsdException $e) { throw new KalturaAPIException(MetadataErrors::METADATA_UNABLE_TO_TRANSFORM); } $dbMetadataProfile->save(); $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION); kFileSyncUtils::moveFromFile($filePath, $key); kMetadataManager::parseProfileSearchFields($dbMetadataProfile); $metadataProfile = new KalturaMetadataProfile(); $metadataProfile->fromObject($dbMetadataProfile); return $metadataProfile; }