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);
         }
     }
 }
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);
}
Esempio n. 3
0
 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);
}
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     if (!$puser_kuser) {
         $this->addError(APIErrors::INVALID_USER_ID, $puser_id);
         return;
     }
     $entry_id = $this->getPM("entry_id");
     $entry = entryPeer::retrieveByPK($entry_id);
     // TODO - verify the user is allowed to modify the entry
     if ($entry->getKshowId() === kshow::SANDBOX_ID) {
         $this->addError(APIErrors::SANDBOX_ALERT);
         return;
     }
     $entry->setThumbnail(".jpg");
     $entry->setCreateThumb(false);
     $entry->save();
     if (isset($HTTP_RAW_POST_DATA)) {
         $thumb_data = $HTTP_RAW_POST_DATA;
     } else {
         $thumb_data = file_get_contents("php://input");
     }
     $thumb_data_size = strlen($thumb_data);
     $fileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     $fileSync = FileSync::createForFileSyncKey($fileSyncKey);
     kFileSyncUtils::file_put_contents($fileSyncKey, $thumb_data);
     // update the metadata in case of a roughcut
     if ($entry->getType() == entryType::MIX) {
         $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         $xml_doc = new DOMDocument();
         $xml_doc->loadXML(kFileSyncUtils::file_get_contents($sync_key));
         if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getThumbnailUrl())) {
             $entry->setMetadata(null, $xml_doc->saveXML(), true, null, null);
             //$entry->getVersion() );
         }
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE_THUMBNAIL, $entry);
     }
     $this->res = $entry->getBigThumbnailUrl();
     $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_REGULAR);
     $wrapper->removeFromCache("entry", $entry->getId());
     $this->addMsg("entry", $wrapper);
 }
 public function postSave(PropelPDO $con = null)
 {
     parent::postSave($con);
     if ($this->xslModified && $this->xsl && $this->getFeedId()) {
         KalturaLog::debug("loads syndication feed id [" . $this->getFeedId() . "]");
         $syndicationFeed = syndicationFeedPeer::retrieveByPK($this->getFeedId());
         KalturaLog::debug("syndication feed id [" . $syndicationFeed->getId() . "] syndication feed type [" . get_class($syndicationFeed) . "]");
         if ($syndicationFeed && $syndicationFeed instanceof genericSyndicationFeed) {
             KalturaLog::log("Updating syndication feed xsl");
             $syndicationFeed->setType(syndicationFeedType::KALTURA_XSLT);
             $syndicationFeed->incrementVersion();
             $syndicationFeed->save();
             $syncKey = $syndicationFeed->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
             kFileSyncUtils::file_put_contents($syncKey, $this->xsl, false);
             $this->xslModified = false;
         }
     }
 }
Esempio n. 7
0
 private function setObjectContent($assetObject, $content, $accuracy = null, $format = null, $shouldSetTranscriptFileName = false)
 {
     $assetObject->incrementVersion();
     $ext = "txt";
     if ($format) {
         if ($format == "DFXP") {
             $ext = "xml";
         }
         if ($format == "SRT") {
             $ext = "srt";
         }
     }
     $assetObject->setFileExt($ext);
     $assetObject->save();
     $syncKey = $assetObject->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::file_put_contents($syncKey, $content);
     $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     $assetObject->setSize(kFile::fileSize($finalPath));
     if ($shouldSetTranscriptFileName && !$assetObject->getFileName()) {
         $language = str_replace(" ", "", $assetObject->getLanguage());
         $patterns = array("{entryId}", "{language}");
         $replacements = array($assetObject->getEntryId(), $language);
         $fileName = str_replace($patterns, $replacements, self::FILE_NAME_PATTERN);
         $assetObject->setFileName($fileName);
     }
     if (!$accuracy) {
         $accuracy = self::DEFAULT_ACCURACY;
     }
     $assetObject->setAccuracy($accuracy);
     $assetObject->setStatus(AttachmentAsset::ASSET_STATUS_READY);
     $assetObject->save();
 }
 /**
  * Update Syndication Feed by ID
  * 
  * @action update
  * @param string $id
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed
  */
 public function updateAction($id, KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($id);
     if (!$syndicationFeedDB) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $id);
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         $syndicationFeed->validateXslt();
         $syndicationFeedDB->incrementVersion();
         $syndicationFeedDB->save();
     }
     $syndicationFeed->type = null;
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed = $syndicationFeed->toUpdatableObject($syndicationFeedDB, array('type'));
     $syndicationFeedDB->save();
     $syndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $syndicationFeed->fromObject($syndicationFeedDB);
     return $syndicationFeed;
 }
Esempio n. 9
0
 function updateImpl($id, $xmlData = null, $version = null)
 {
     $dbMetadata = MetadataPeer::retrieveByPK($id);
     if (!$dbMetadata) {
         throw new KalturaAPIException(MetadataErrors::METADATA_NOT_FOUND, $id);
     }
     if ($version && $dbMetadata->getVersion() != $version) {
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_VERSION, $dbMetadata->getVersion());
     }
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($dbMetadata->getMetadataProfileId());
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_PROFILE, $dbMetadata->getMetadataProfileId());
     }
     $previousVersion = null;
     if ($dbMetadata->getStatus() == Metadata::STATUS_VALID) {
         $previousVersion = $dbMetadata->getVersion();
     }
     if ($xmlData) {
         // if a metadata xslt is defined on the metadata profile - transform the given metadata
         $xmlDataTransformed = $this->transformMetadata($dbMetadata->getMetadataProfileId(), $xmlData);
         if ($xmlDataTransformed) {
             $xmlData = $xmlDataTransformed;
         }
         $errorMessage = '';
         if (!kMetadataManager::validateMetadata($dbMetadata->getMetadataProfileId(), $xmlData, $errorMessage)) {
             // if metadata profile is transforming, and metadata profile version is not the latest, try to validate againts previous version
             if ($dbMetadataProfile->getStatus() != MetadataProfile::STATUS_TRANSFORMING || $dbMetadata->getMetadataProfileVersion() >= $dbMetadataProfile->getVersion()) {
                 throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_DATA, $errorMessage);
             }
             // validates against previous version
             $errorMessagePrevVersion = '';
             if (!kMetadataManager::validateMetadata($dbMetadata->getMetadataProfileId(), $xmlData, $errorMessagePrevVersion, true)) {
                 KalturaLog::err("Failed to validate metadata object [{$id}] against metadata profile previous version [" . $dbMetadata->getMetadataProfileVersion() . "] error: {$errorMessagePrevVersion}");
                 // throw the error with the original error message
                 throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_DATA, $errorMessage);
             }
         } else {
             $dbMetadata->setMetadataProfileVersion($dbMetadataProfile->getVersion());
         }
         $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
         if (!kFileSyncUtils::compareContent($key, $xmlData)) {
             $dbMetadata->incrementVersion();
             $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
             kFileSyncUtils::file_put_contents($key, $xmlData);
             $dbMetadata->save();
             kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata, $previousVersion));
         } else {
             KalturaLog::info("XML data MD5 matches current filesync content MD5. Update is not necessary.");
             //adding this save() in order to save the metadata profile version field in case there are no diffrences
             $dbMetadata->save();
         }
     }
     $metadata = new KalturaMetadata();
     $metadata->fromObject($dbMetadata, $this->getResponseProfile());
     return $metadata;
 }
Esempio n. 10
0
 /**
  * Update Syndication Feed by ID
  * 
  * @action update
  * @param string $id
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed
  * @throws KalturaErrors::INVALID_FEED_ID
  */
 public function updateAction($id, KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($id);
     if (!$syndicationFeedDB) {
         throw new KalturaAPIException(KalturaErrors::INVALID_FEED_ID, $id);
     }
     $syndicationFeed->validateStorageId($this->getPartnerId());
     $syndicationFeed->toUpdatableObject($syndicationFeedDB, array('type'));
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         if (!$syndicationFeedDB instanceof genericSyndicationFeed) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FEED_TYPE, get_class($syndicationFeedDB));
         }
         $syndicationFeedDB->incrementVersion();
     }
     $syndicationFeedDB->save();
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->type = null;
     $syndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $syndicationFeed->fromObject($syndicationFeedDB, $this->getResponseProfile());
     return $syndicationFeed;
 }
 /**
  * @action addFromUrl
  * @param string $entryId
  * @param string $url
  * @return KalturaThumbAsset
  * 
  * @deprecated use thumbAsset.add and thumbAsset.setContent instead
  */
 public function addFromUrlAction($entryId, $url)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ext = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION);
     $dbThumbAsset = new thumbAsset();
     $dbThumbAsset->setPartnerId($dbEntry->getPartnerId());
     $dbThumbAsset->setEntryId($dbEntry->getId());
     $dbThumbAsset->setStatus(thumbAsset::ASSET_STATUS_QUEUED);
     $dbThumbAsset->setFileExt($ext);
     $dbThumbAsset->incrementVersion();
     $dbThumbAsset->save();
     $syncKey = $dbThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::file_put_contents($syncKey, file_get_contents($url));
     $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     list($width, $height, $type, $attr) = getimagesize($finalPath);
     $dbThumbAsset->setWidth($width);
     $dbThumbAsset->setHeight($height);
     $dbThumbAsset->setSize(filesize($finalPath));
     $dbThumbAsset->setStatus(thumbAsset::ASSET_STATUS_READY);
     $dbThumbAsset->save();
     $thumbAssets = new KalturaThumbAsset();
     $thumbAssets->fromObject($dbThumbAsset);
     return $thumbAssets;
 }
Esempio n. 12
0
 /**
  * Read multiple metadata schemas
  * @param BaseObject $object
  * @param array $data
  */
 protected static function addMetadataWithProfilesSystemNames(BaseObject $object, array $data)
 {
     $newFieldValuesMap = array();
     $xmlDataArray = array();
     //Construct mapping of all metadata profile system names, their fields and the field values.
     foreach ($data as $key => $value) {
         if (strpos($key, self::BULK_UPLOAD_METADATA_FIELD_PREFIX) === 0) {
             $prefix = null;
             $metadataProfileSystemName = null;
             $metadataProfileFieldName = null;
             list($prefix, $metadataProfileSystemName, $metadataProfileFieldName) = explode(self::BULK_UPLOAD_METADATA_SYSTEMNAME_SEPARATOR, $key);
             if (!$prefix || !$metadataProfileSystemName || !$metadataProfileFieldName) {
                 $errorMessage = "Unexpected key structure. Expected metadata::ProfileSystemName::FieldSystemName.";
                 KalturaLog::err($errorMessage);
                 self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                 continue;
             }
             if (!isset($newFieldValuesMap[$metadataProfileSystemName])) {
                 $newFieldValuesMap[$metadataProfileSystemName] = array();
             }
             $newFieldValuesMap[$metadataProfileSystemName][$metadataProfileFieldName] = $value;
         }
     }
     foreach ($newFieldValuesMap as $metadataProfileSystemName => $fieldsArray) {
         /* @var array $fieldsArray */
         if (!$fieldsArray || !count($fieldsArray)) {
             continue;
         }
         $metadataProfile = MetadataProfilePeer::retrieveBySystemName($metadataProfileSystemName, $object->getPartnerId());
         if (!$metadataProfile) {
             $errorMessage = "Metadata profile with system name [{$metadataProfileSystemName}] could not be found.";
             KalturaLog::err($errorMessage);
             self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
             continue;
         }
         if ($metadataProfile->getObjectType() != kMetadataManager::getTypeNameFromObject($object)) {
             $errorMessage = "Metadata profile [{$metadataProfileSystemName}] object type [" . $metadataProfile->getObjectType() . "] is not compatible with object type [" . kMetadataManager::getTypeNameFromObject($object) . "]";
             KalturaLog::err($errorMessage);
             self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
             continue;
         }
         $metadataProfileId = $metadataProfile->getId();
         $xml = new DOMDocument();
         $metadataProfileFields = array();
         MetadataProfileFieldPeer::setUseCriteriaFilter(false);
         $tmpMetadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfileId);
         MetadataProfileFieldPeer::setUseCriteriaFilter(true);
         foreach ($tmpMetadataProfileFields as $metadataProfileField) {
             /* @var $metadataProfileField MetadataProfileField */
             $metadataProfileFields[$metadataProfileField->getKey()] = $metadataProfileField;
         }
         foreach ($fieldsArray as $fieldSysName => $fieldValue) {
             if (!isset($metadataProfileFields[$fieldSysName])) {
                 $errorMessage = "Metadata profile field with system name [{$fieldSysName}] missing from metadata profile with id [{$metadataProfileId}]";
                 KalturaLog::err($errorMessage);
                 self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                 continue;
             }
             $metadataProfileField = $metadataProfileFields[$fieldSysName];
             KalturaLog::debug("Found field [" . $metadataProfileField->getXpath() . "] for value [{$fieldValue}]");
             $fieldValues = explode(self::BULK_UPLOAD_MULTI_VALUES_DELIMITER, $fieldValue);
             foreach ($fieldValues as $fieldSingleValue) {
                 if ($fieldSingleValue) {
                     if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE && !is_numeric($fieldSingleValue)) {
                         $valueAsDate = self::parseFormatedDate($fieldSingleValue);
                         if (!$valueAsDate || !strlen($valueAsDate)) {
                             $errorMessage = "Could not parse date format [{$fieldValue}] for field [{$key}]";
                             KalturaLog::err($errorMessage);
                             self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                             continue;
                         }
                         $fieldSingleValue = $valueAsDate;
                     }
                     if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_INT && !is_numeric($fieldSingleValue)) {
                         $errorMessage = "Could not parse int format [{$fieldSingleValue}] for field [{$key}]";
                         KalturaLog::err($errorMessage);
                         self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                         continue;
                     }
                     self::addXpath($xml, $metadataProfileField->getXpath(), $fieldSingleValue);
                 }
             }
             $dataFound = true;
             if ($dataFound && $xml->hasChildNodes()) {
                 $xmlDataArray[$metadataProfileId] = $xml->saveXML($xml->firstChild);
                 $xmlDataArray[$metadataProfileId] = trim($xmlDataArray[$metadataProfileId], " \n\r\t");
             }
         }
     }
     foreach ($xmlDataArray as $metadataProfileId => $xmlData) {
         $errorMessage = '';
         if (!kMetadataManager::validateMetadata($metadataProfileId, $xmlData, $errorMessage)) {
             self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
             continue;
         }
         $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
         $dbMetadata = self::createOrFindMetadataObject($object, $metadataProfile);
         KalturaLog::debug("Metadata [" . $dbMetadata->getId() . "] saved [{$xmlData}]");
         $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
         kFileSyncUtils::file_put_contents($key, $xmlData);
         kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata));
     }
 }
Esempio n. 13
0
 /**
  * Update an existing metadata object
  * 
  * @action update
  * @param int $id 
  * @param KalturaMetadataProfile $metadataProfile
  * @param string $xsdData XSD metadata definition
  * @param string $viewsData UI views definition
  * @return KalturaMetadataProfile
  * @throws KalturaErrors::INVALID_OBJECT_ID
  * @throws MetadataErrors::METADATA_UNABLE_TO_TRANSFORM
  * @throws MetadataErrors::METADATA_TRANSFORMING
  */
 function updateAction($id, KalturaMetadataProfile $metadataProfile, $xsdData = null, $viewsData = null)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     if ($dbMetadataProfile->getStatus() != MetadataProfile::STATUS_ACTIVE) {
         throw new KalturaAPIException(MetadataErrors::METADATA_TRANSFORMING);
     }
     $dbMetadataProfile = $metadataProfile->toUpdatableObject($dbMetadataProfile);
     $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     $oldXsd = kFileSyncUtils::getLocalFilePathForKey($key);
     $oldVersion = $dbMetadataProfile->getVersion();
     if ($xsdData) {
         $xsdData = html_entity_decode($xsdData);
         $dbMetadataProfile->incrementVersion();
     }
     if (!is_null($viewsData)) {
         $viewsData = html_entity_decode($viewsData);
         $dbMetadataProfile->incrementViewsVersion();
     }
     if ($xsdData) {
         $xsdPath = sys_get_temp_dir() . '/' . uniqid() . '.xsd';
         file_put_contents($xsdPath, $xsdData);
         try {
             kMetadataManager::diffMetadataProfile($dbMetadataProfile, $oldVersion, $oldXsd, $dbMetadataProfile->getVersion(), $xsdPath);
         } catch (kXsdException $e) {
             throw new KalturaAPIException(MetadataErrors::METADATA_UNABLE_TO_TRANSFORM, $e->getMessage());
         }
         $dbMetadataProfile->save();
         $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
         kFileSyncUtils::moveFromFile($xsdPath, $key);
     } else {
         $dbMetadataProfile->save();
     }
     if (!is_null($viewsData) && $viewsData != '') {
         $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS);
         kFileSyncUtils::file_put_contents($key, $viewsData);
     }
     kMetadataManager::parseProfileSearchFields($dbMetadataProfile);
     $metadataProfile->fromObject($dbMetadataProfile);
     return $metadataProfile;
 }
 /**
  * addConvertIsmCollectionJob creates a convert collection job 
  * 
  * @param string $tag 
  * @param FileSyncKey $srcSyncKey
  * @param entry $entry
  * @param BatchJob $parentJob
  * @param array<flavorParamsOutput> $flavorParamsOutputs
  * @return BatchJob
  */
 public static function addConvertIsmCollectionJob($tag, FileSyncKey $srcSyncKey, entry $entry, BatchJob $parentJob = null, array $flavorParamsOutputs, $dbConvertCollectionJob = null)
 {
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     $localPath = null;
     $remoteUrl = null;
     if ($fileSync) {
         if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $localPath = $fileSync->getFullPath();
         }
         $remoteUrl = $fileSync->getExternalUrl($entry->getId());
     }
     // increment entry version
     $ismVersion = $entry->incrementIsmVersion();
     $entry->save();
     $fileName = $entry->generateFileName(0, $ismVersion);
     // creates convert data
     $convertCollectionData = new kConvertCollectionJobData();
     $convertCollectionData->setSrcFileSyncLocalPath($localPath);
     $convertCollectionData->setSrcFileSyncRemoteUrl($remoteUrl);
     $convertCollectionData->setDestFileName($fileName);
     $clipOffset = null;
     $clipDuration = null;
     // look for clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutput) {
         $clipOffset = $flavorParamsOutput->getClipOffset();
         $clipDuration = $flavorParamsOutput->getClipDuration();
         if (isset($clipOffset) || isset($clipDuration)) {
             KalturaLog::log("Found clipping params: clipOffset({$clipOffset}),clipDuration({$clipDuration})");
             break;
         }
     }
     $bitrates = array();
     $finalFlavorParamsOutputs = array();
     // check bitrates duplications & update clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutputIndex => $flavorParamsOutput) {
         if (!isset($bitrates[$flavorParamsOutput->getVideoBitrate()])) {
             $bitrates[$flavorParamsOutput->getVideoBitrate()] = array();
         }
         // if one of clip params exsits - update the object and db
         if (isset($clipOffset)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipOffset($clipOffset);
         }
         if (isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipDuration($clipDuration);
         }
         if (isset($clipOffset) || isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->save();
         }
         $bitrates[$flavorParamsOutput->getVideoBitrate()][] = $flavorParamsOutput->getId();
         $finalFlavorParamsOutputs[$flavorParamsOutput->getId()] = $flavorParamsOutput;
     }
     foreach ($bitrates as $bitrate => $flavorParamsOutputIds) {
         if (count($flavorParamsOutputIds) == 1) {
             // no bitrate dupliaction
             continue;
         }
         $tempFlavorParamsOutputs = array();
         foreach ($flavorParamsOutputIds as $index => $flavorParamsOutputId) {
             $tempFlavorParamsOutputs[] = $finalFlavorParamsOutputs[$flavorParamsOutputId];
         }
         // sort the flavors by height
         usort($tempFlavorParamsOutputs, array('kBusinessConvertDL', 'compareFlavorsByHeight'));
         // increment the bitrate so it will be a bit different for each flavor
         $index = 0;
         foreach ($tempFlavorParamsOutputs as $flavorParamsOutput) {
             $finalFlavorParamsOutputs[$flavorParamsOutput->getId()]->setVideoBitrate($bitrate + $index++);
         }
     }
     foreach ($finalFlavorParamsOutputs as $flavorParamsOutput) {
         $convertCollectionFlavorData = new kConvertCollectionFlavorData();
         $convertCollectionFlavorData->setFlavorAssetId($flavorParamsOutput->getFlavorAssetId());
         $convertCollectionFlavorData->setFlavorParamsOutputId($flavorParamsOutput->getId());
         $convertCollectionFlavorData->setReadyBehavior($flavorParamsOutput->getReadyBehavior());
         $convertCollectionFlavorData->setVideoBitrate($flavorParamsOutput->getVideoBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionData->addFlavor($convertCollectionFlavorData);
     }
     $currentConversionEngine = conversionEngineType::EXPRESSION_ENCODER3;
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     if (!$dbConvertCollectionJob) {
         // creats a child convert job
         if ($parentJob) {
             $dbConvertCollectionJob = $parentJob->createChild();
             KalturaLog::log("Created from parent convert job with entry id [" . $dbConvertCollectionJob->getEntryId() . "]");
         } else {
             $dbConvertCollectionJob = new BatchJob();
             $dbConvertCollectionJob->setEntryId($entry->getId());
             $dbConvertCollectionJob->setPartnerId($entry->getPartnerId());
             $dbConvertCollectionJob->save();
             KalturaLog::log("Created from convert collection job with entry id [" . $dbConvertCollectionJob->getEntryId() . "]");
         }
     }
     KalturaLog::log("Calling CDLProceessFlavorsForCollection with [" . count($finalFlavorParamsOutputs) . "] flavor params");
     $xml = KDLWrap::CDLProceessFlavorsForCollection($finalFlavorParamsOutputs);
     $xml = str_replace(KDLCmdlinePlaceholders::OutFileName, $fileName, $xml);
     $syncKey = $dbConvertCollectionJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
     kFileSyncUtils::file_put_contents($syncKey, $xml);
     $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     $remoteUrl = $fileSync->getExternalUrl($entry->getId());
     $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     $commandLines = array(conversionEngineType::EXPRESSION_ENCODER3 => KDLCmdlinePlaceholders::InFileName . ' ' . KDLCmdlinePlaceholders::ConfigFileName);
     $commandLinesStr = flavorParamsOutput::buildCommandLinesStr($commandLines);
     $convertCollectionData->setInputXmlLocalPath($localPath);
     $convertCollectionData->setInputXmlRemoteUrl($remoteUrl);
     $convertCollectionData->setCommandLinesStr($commandLinesStr);
     $dbConvertCollectionJob->setFileSize(kFile::fileSize($convertCollectionData->getSrcFileSyncLocalPath()));
     return kJobsManager::addJob($dbConvertCollectionJob, $convertCollectionData, BatchJobType::CONVERT_COLLECTION, $currentConversionEngine);
 }
 private function setConfFileImpl($v, $file_suffix = null, $isClone = false)
 {
     //		$file_name = $this->getConfFilePath($file_suffix );
     if ($this->getCreationMode() == self::UI_CONF_CREATION_MODE_MANUAL) {
         throw new Exception("Should not edit MANUAL ui_confs via the API!! Only via the SVN");
     }
     if ($file_suffix) {
         $sync_key = $this->getSyncKey(self::FILE_SYNC_UICONF_SUB_TYPE_FEATURES);
     } else {
         $sync_key = $this->getSyncKey(self::FILE_SYNC_UICONF_SUB_TYPE_DATA);
     }
     $this->setUpdatedAt(time());
     // make sure will be updated in the DB
     if (version_compare($this->getSwfUrlVersion(), "2.5", ">=")) {
         $v = str_replace('.entryName}', '.name}', $v);
     }
     // This is only called on Save, after parent::save(), so ID is present.
     kFileSyncUtils::file_put_contents($sync_key, $v);
     //replaced__setFileContent
 }
Esempio n. 16
0
 public static function modifyEntryMetadataWithText($entry, $text, $duration = 6, $override = false)
 {
     KalturaLog::log("modifyEntryMetadataWithText:\n{$text}");
     $content = myContentStorage::getFSContentRootPath();
     if (!$override) {
         // this will reset the data and increment the count
         $entry->setData(".xml");
     }
     $targetFileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
     // doesn't require kFileSyncUtils change - this is a static template that should not be represented as row in the table
     $source = $content . myContentStorage::getGeneralEntityPath("entry/data", 0, 0, "&metadata_text.xml");
     if ($override || !kFileSyncUtils::file_exists($targetFileSyncKey)) {
         //			KalturaLog::log ( "modifyEntryMetadataWithText\n$str_before\n$str_after\n" );
         $template_str = file_get_contents($source);
         $template_str = str_replace(array("__TEXT_PLACEHOLDER__", "__SLIDE_LENGTH_IN_SECS_PLACEHOLDER__"), array($text, $duration), $template_str);
         kFileSyncUtils::file_put_contents($targetFileSyncKey, $template_str);
         //	 		KalturaLog::log ( "modifyEntryMetadataWithText:\n$text");
         $entry->save();
     }
 }
Esempio n. 17
0
 /**
  * addConvertIsmCollectionJob creates a convert collection job 
  * 
  * @param string $tag 
  * @param FileSyncKey $srcSyncKey
  * @param entry $entry
  * @param BatchJob $parentJob
  * @param array<flavorParamsOutput> $flavorParamsOutputs
  * @return BatchJob
  */
 public static function addConvertIsmCollectionJob($tag, FileSyncKey $srcSyncKey, entry $entry, BatchJob $parentJob = null, array $flavorParamsOutputs, $sameRoot = null)
 {
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     $srcFileSyncDescriptor = new kSourceFileSyncDescriptor();
     if ($fileSync) {
         if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $srcFileSyncDescriptor->setFileSyncLocalPath($fileSync->getFullPath());
         }
         $srcFileSyncDescriptor->setFileSyncRemoteUrl($fileSync->getExternalUrl($entry->getId()));
         $srcFileSyncDescriptor->setAssetId($fileSync->getObjectId());
         $srcFileSyncDescriptor->setFileSyncObjectSubType($srcSyncKey->getObjectSubType());
     }
     // increment entry version
     $ismVersion = $entry->incrementIsmVersion();
     $entry->save();
     $fileName = $entry->generateFileName(0, $ismVersion);
     // creates convert data
     $convertCollectionData = new kConvertCollectionJobData();
     $convertCollectionData->setSrcFileSyncs(array($srcFileSyncDescriptor));
     $convertCollectionData->setDestFileName($fileName);
     $clipOffset = null;
     $clipDuration = null;
     // look for clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutput) {
         $clipOffset = $flavorParamsOutput->getClipOffset();
         $clipDuration = $flavorParamsOutput->getClipDuration();
         if (isset($clipOffset) || isset($clipDuration)) {
             KalturaLog::log("Found clipping params: clipOffset({$clipOffset}),clipDuration({$clipDuration})");
             break;
         }
     }
     // check bitrates duplications & update clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutputIndex => $flavorParamsOutput) {
         // if one of clip params exsits - update the object and db
         if (isset($clipOffset)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipOffset($clipOffset);
         }
         if (isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipDuration($clipDuration);
         }
         if (isset($clipOffset) || isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->save();
         }
     }
     /*
      * Put together all separted flavor XML's into a single Smooth Streaming preset file
      */
     KalturaLog::log("Calling CDLProceessFlavorsForCollection with [" . count($flavorParamsOutputs) . "] flavor params");
     $presetXml = KDLWrap::CDLProceessFlavorsForCollection($flavorParamsOutputs);
     $presetXml = str_replace(KDLCmdlinePlaceholders::OutFileName, $fileName, $presetXml);
     foreach ($flavorParamsOutputs as $flavorParamsOutput) {
         /*
          * Save in case that videoBitrate was changed by the FlavorsForCollection (see above)
          */
         $flavorParamsOutput->save();
         $convertCollectionFlavorData = new kConvertCollectionFlavorData();
         $convertCollectionFlavorData->setFlavorAssetId($flavorParamsOutput->getFlavorAssetId());
         $convertCollectionFlavorData->setFlavorParamsOutputId($flavorParamsOutput->getId());
         $convertCollectionFlavorData->setReadyBehavior($flavorParamsOutput->getReadyBehavior());
         $convertCollectionFlavorData->setVideoBitrate($flavorParamsOutput->getVideoBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionData->addFlavor($convertCollectionFlavorData);
     }
     $currentConversionEngine = conversionEngineType::EXPRESSION_ENCODER3;
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     if ($sameRoot == null) {
         // creats a child convert job
         if ($parentJob) {
             $dbConvertCollectionJob = $parentJob->createChild(BatchJobType::CONVERT_COLLECTION, $currentConversionEngine);
             KalturaLog::log("Created from parent convert job with entry id [" . $dbConvertCollectionJob->getEntryId() . "]");
         } else {
             $dbConvertCollectionJob = new BatchJob();
             $dbConvertCollectionJob->setEntryId($entry->getId());
             $dbConvertCollectionJob->setPartnerId($entry->getPartnerId());
             $dbConvertCollectionJob->setJobType(BatchJobType::CONVERT_COLLECTION);
             $dbConvertCollectionJob->setJobSubType($currentConversionEngine);
         }
     } else {
         $dbConvertCollectionJob = $parentJob->createChild(BatchJobType::CONVERT_COLLECTION, $currentConversionEngine, false);
     }
     $dbConvertCollectionJob->setObjectId($entry->getId());
     $dbConvertCollectionJob->setObjectType(BatchJobObjectType::ENTRY);
     $dbConvertCollectionJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $dbConvertCollectionJob = kJobsManager::addJob($dbConvertCollectionJob, $convertCollectionData, BatchJobType::CONVERT_COLLECTION, $currentConversionEngine);
     $syncKey = $dbConvertCollectionJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
     kFileSyncUtils::file_put_contents($syncKey, $presetXml);
     $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     $remoteUrl = $fileSync->getExternalUrl($entry->getId());
     $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     $commandLines = array(conversionEngineType::EXPRESSION_ENCODER3 => KDLCmdlinePlaceholders::InFileName . ' ' . KDLCmdlinePlaceholders::ConfigFileName);
     $commandLinesStr = flavorParamsOutput::buildCommandLinesStr($commandLines);
     $convertCollectionData->setInputXmlLocalPath($localPath);
     $convertCollectionData->setInputXmlRemoteUrl($remoteUrl);
     $convertCollectionData->setCommandLinesStr($commandLinesStr);
     $dbConvertCollectionJob->setData($convertCollectionData);
     return kJobsManager::updateBatchJob($dbConvertCollectionJob, BatchJob::BATCHJOB_STATUS_PENDING);
 }
Esempio n. 18
0
 public function postSave(PropelPDO $con = null)
 {
     if ($this->wasObjectSaved() && $this->setPost) {
         $key = $this->getSyncKey(self::FILE_SYNC_POST);
         kFileSyncUtils::file_put_contents($key, $this->setPost);
         $this->cachedPost = $this->setPost;
         $this->setPost = null;
         kEventsManager::raiseEvent(new kObjectDataChangedEvent($this, $this->postPreviousVersion));
     }
     return parent::postSave($con);
 }
Esempio n. 19
0
 private function saveConfFileToDisk($v, $file_suffix = null, $isClone = false)
 {
     if ($this->getCreationMode() == self::UI_CONF_CREATION_MODE_MANUAL) {
         throw new Exception("Should not edit MANUAL ui_confs via the API!! Only via the SVN");
     }
     $subType = $this->getSubTypeBySuffix($file_suffix);
     $this->incrementVersion($subType);
     $sync_key = $this->getSyncKey($subType);
     $this->setUpdatedAt(time());
     // make sure will be updated in the DB
     if (version_compare($this->getSwfUrlVersion(), "2.5", ">=")) {
         $v = str_replace('.entryName}', '.name}', $v);
     }
     // This is only called on Save, after parent::save(), so ID is present.
     kFileSyncUtils::file_put_contents($sync_key, $v);
     //replaced__setFileContent
 }
 /**
  * Add results transform file to generic distribution provider action
  * 
  * @action addResultsTransform
  * @param int $id the id of the generic distribution provider action
  * @param string $transformData transformation data xsl, xPath or regex
  * @return KalturaGenericDistributionProviderAction
  * @throws ContentDistributionErrors::GENERIC_DISTRIBUTION_PROVIDER_ACTION_NOT_FOUND
  */
 function addResultsTransformAction($id, $transformData)
 {
     $dbGenericDistributionProviderAction = GenericDistributionProviderActionPeer::retrieveByPK($id);
     if (!$dbGenericDistributionProviderAction) {
         throw new KalturaAPIException(ContentDistributionErrors::GENERIC_DISTRIBUTION_PROVIDER_ACTION_NOT_FOUND, $id);
     }
     $dbGenericDistributionProviderAction->incrementResultsTransformerVersion();
     $dbGenericDistributionProviderAction->save();
     $key = $dbGenericDistributionProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_RESULTS_TRANSFORMER);
     kFileSyncUtils::file_put_contents($key, $transformData);
     $genericDistributionProviderAction = new KalturaGenericDistributionProviderAction();
     $genericDistributionProviderAction->fromObject($dbGenericDistributionProviderAction);
     return $genericDistributionProviderAction;
 }
 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;
 }
Esempio n. 22
0
 /**
  * @param int $metadataProfileId
  * @param int $srcVersion
  * @param int $destVersion
  * @param string $xsl
  *
  * @return BatchJob
  */
 private static function addTransformMetadataJob($partnerId, $metadataProfileId, $srcVersion, $destVersion, $xsl = null)
 {
     // check if any metadata objects require the transform
     $c = new Criteria();
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $metadataProfileId);
     $c->add(MetadataPeer::METADATA_PROFILE_VERSION, $destVersion, Criteria::LESS_THAN);
     $c->add(MetadataPeer::STATUS, Metadata::STATUS_VALID);
     $metadataCount = MetadataPeer::doCount($c);
     if (!$metadataCount) {
         return null;
     }
     $job = new BatchJob();
     $job->setJobType(BatchJobType::METADATA_TRANSFORM);
     $job->setPartnerId($partnerId);
     $job->setObjectId($metadataProfileId);
     $job->setObjectType(kPluginableEnumsManager::apiToCore('BatchJobObjectType', MetadataBatchJobObjectType::METADATA_PROFILE));
     $data = new kTransformMetadataJobData();
     if ($xsl) {
         $job->save();
         $key = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
         kFileSyncUtils::file_put_contents($key, $xsl);
         $xslPath = kFileSyncUtils::getLocalFilePathForKey($key);
         $data->setSrcXslPath($xslPath);
     }
     $data->setMetadataProfileId($metadataProfileId);
     $data->setSrcVersion($srcVersion);
     $data->setDestVersion($destVersion);
     return kJobsManager::addJob($job, $data, BatchJobType::METADATA_TRANSFORM);
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param kDistributionDeleteJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function onDistributionDeleteJobUpdated(BatchJob $dbBatchJob, kDistributionDeleteJobData $data, BatchJob $twinJob = null)
 {
     if ($data->getResults() || $data->getSentData()) {
         $entryDistribution = EntryDistributionPeer::retrieveByPK($data->getEntryDistributionId());
         if (!$entryDistribution) {
             KalturaLog::err("Entry distribution [" . $data->getEntryDistributionId() . "] not found");
             return $dbBatchJob;
         }
         if ($data->getResults()) {
             $entryDistribution->incrementDeleteResultsVersion();
         }
         if ($data->getSentData()) {
             $entryDistribution->incrementDeleteDataVersion();
         }
         $entryDistribution->save();
         if ($data->getResults()) {
             $key = $entryDistribution->getSyncKey(EntryDistribution::FILE_SYNC_ENTRY_DISTRIBUTION_DELETE_RESULTS);
             kFileSyncUtils::file_put_contents($key, $data->getResults());
             $data->setResults(null);
         }
         if ($data->getSentData()) {
             $key = $entryDistribution->getSyncKey(EntryDistribution::FILE_SYNC_ENTRY_DISTRIBUTION_DELETE_DATA);
             kFileSyncUtils::file_put_contents($key, $data->getSentData());
             $data->setSentData(null);
         }
         $dbBatchJob->setData($data);
         $dbBatchJob->save();
     }
     switch ($dbBatchJob->getStatus()) {
         case BatchJob::BATCHJOB_STATUS_PENDING:
             return self::onDistributionDeleteJobPending($dbBatchJob, $data, $twinJob);
         case BatchJob::BATCHJOB_STATUS_FINISHED:
             return self::onDistributionDeleteJobFinished($dbBatchJob, $data, $twinJob);
         case BatchJob::BATCHJOB_STATUS_FAILED:
         case BatchJob::BATCHJOB_STATUS_FATAL:
             return self::onDistributionDeleteJobFailed($dbBatchJob, $data, $twinJob);
         default:
             return $dbBatchJob;
     }
 }
Esempio n. 24
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);
     }
 }
 /**
  * Add the data to the flavor asset conversion log, creates it if doesn't exists
  * 
  * @action logConversion
  * @param string $flavorAssetId
  * @param string $data
  * @throws KalturaErrors::INVALID_FLAVOR_ASSET_ID
  */
 function logConversionAction($flavorAssetId, $data)
 {
     $flavorAsset = assetPeer::retrieveById($flavorAssetId);
     // verifies that flavor asset exists
     if (!$flavorAsset) {
         throw new KalturaAPIException(KalturaErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $flavorAsset->incLogFileVersion();
     $flavorAsset->save();
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $log = kFileSyncUtils::file_get_contents($syncKey, true, false);
     $log .= $data;
     kFileSyncUtils::file_put_contents($syncKey, $log, false);
 }
 /**
  * Update Conversion Profile by ID
  * 
  * @action update
  * @param int $id
  * @param KalturaConversionProfile $conversionProfile
  * @return KalturaConversionProfile
  */
 public function updateAction($id, KalturaConversionProfile $conversionProfile)
 {
     $conversionProfileDb = conversionProfile2Peer::retrieveByPK($id);
     if (!$conversionProfileDb) {
         throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $id);
     }
     $conversionProfile->toUpdatableObject($conversionProfileDb);
     $conversionProfileDb->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_KMC);
     if ($conversionProfile->xslTransformation) {
         $conversionProfileDb->incrementXslVersion();
     }
     $conversionProfileDb->save();
     if ($conversionProfile->flavorParamsIds !== null) {
         $this->deleteFlavorParamsRelation($conversionProfileDb, $conversionProfile->flavorParamsIds);
         $this->addFlavorParamsRelation($conversionProfileDb, $conversionProfile->getFlavorParamsAsArray());
     }
     if ($conversionProfile->xslTransformation) {
         $xsl = html_entity_decode($conversionProfile->xslTransformation);
         $key = $conversionProfileDb->getSyncKey(conversionProfile2::FILE_SYNC_MRSS_XSL);
         kFileSyncUtils::file_put_contents($key, $xsl);
     }
     $conversionProfile->fromObject($conversionProfileDb);
     // load flavor params id with the same connection (master connection) that was used for insert
     $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_MASTER);
     $conversionProfile->loadFlavorParamsIds($conversionProfileDb, $con);
     return $conversionProfile;
 }
 public function postSave(PropelPDO $con = null)
 {
     parent::postSave($con);
     if ($this->xslModified && $this->xsl && $this->getFeedId()) {
         $podcastFeed = syndicationFeedPeer::retrieveByPK($this->getFeedId());
         if ($podcastFeed && $podcastFeed instanceof genericSyndicationFeed) {
             $podcastFeed->setType(syndicationFeedType::KALTURA_XSLT);
             $podcastFeed->incrementVersion();
             $podcastFeed->save();
             $syncKey = $podcastFeed->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
             kFileSyncUtils::file_put_contents($syncKey, $this->xsl, false);
             $this->xslModified = false;
         }
     }
 }
Esempio n. 28
0
 public static function setMetadata($content, $kshow, $show_entry, $ignore_current = false, $version_info = null)
 {
     $xml_content = "";
     $show_entry_data_key = $show_entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
     $current_content = $show_entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW ? "" : kFileSyncUtils::file_get_contents($show_entry_data_key);
     if ($ignore_current) {
         $current_content = "";
     }
     $update_kshow = false;
     // compare the content and store only if different
     if ($content != $current_content) {
         $show_entry->setData("metadata.xml");
         // re-create data key (to get latest version)
         $show_entry_data_key = $show_entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         //$version = myContentStorage::getVersion($file_name);
         //$comments = "file path: " . $file_name . "\n";
         $comments = "version: " . $show_entry_data_key->version . "\n";
         $total_duration = 0;
         $editor_type = null;
         $content = myFlvStreamer::fixMetadata($content, $show_entry_data_key->version, $total_duration, $editor_type);
         // TODO - make fixMetadata a more generic funciton to return the editorType as well
         // save info file about the version
         if (isset($version_info)) {
             $content = self::addVersionInfo($content, $version_info);
         }
         //fixme $content = myFlvStreamer::modifiedByKeditor ( $content );
         // total_duration is in seconds with 2 digits after the decimal point
         $show_entry->setLengthInMsecs($total_duration * 1000);
         $show_entry->setMediaType(entry::ENTRY_MEDIA_TYPE_SHOW);
         $show_entry->setEditorType($editor_type);
         $show_entry->setModifiedAt(time());
         // update the modified_at date
         $show_entry->save();
         kFileSyncUtils::file_put_contents($show_entry_data_key, $content, true);
         $xml_content = kFileSyncUtils::file_get_contents($show_entry_data_key);
         // replaced__getFileContent
         $update_kshow = true;
         $show_entry_id = $show_entry->getId();
         // update the roughcut_entry table
         $all_entries_for_roughcut = self::getAllEntries($content);
         roughcutEntry::updateRoughcut($show_entry->getId(), $show_entry->getVersion(), $show_entry->getKshowId(), $all_entries_for_roughcut);
         $xml_content = $content;
     } else {
         $xml_content = $current_content;
         $comments = "old and new files are the same";
     }
     if (!$kshow->getHasRoughcut() && $kshow->getIntroId() != $show_entry->getId()) {
         $kshow->setHasRoughcut(true);
         $update_kshow = true;
     }
     myStatisticsMgr::incKshowUpdates($kshow);
     $kshow->save();
     return array($xml_content, $comments, $update_kshow);
 }
Esempio n. 29
0
 public function fixMetadata($increment_version = true, $content = null, $total_duration = null, $specific_version = null)
 {
     // check that the file of the desired version really exists
     $content_dir = myContentStorage::getFSContentRootPath();
     if (!$content) {
         $content = $this->getMetadata($specific_version);
     }
     if ($increment_version) {
         // 	increment the counter of the file
         $this->setData(parent::getData());
     }
     $file_name = kFileSyncUtils::getLocalFilePathForKey($this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $specific_version));
     // replaced__getDataPath
     $duration = $total_duration ? $total_duration : myMetadataUtils::getDuration($content);
     $this->setLengthInMsecs($duration * 1000);
     $total_duration = null;
     $editor_type = null;
     $version = myContentStorage::getVersion($file_name);
     $fixed_content = myFlvStreamer::fixMetadata($content, $version, $total_duration, $editor_type);
     $this->save();
     $sync_key = $this->getSyncKey(self::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version);
     kFileSyncUtils::file_put_contents($sync_key, $fixed_content, false);
     // replaced__setFileContent
     return $fixed_content;
 }
Esempio n. 30
0
 /**
  * Update an existing metadata object with new XML content
  * 
  * @action update
  * @param int $id 
  * @param string $xmlData XML metadata
  * @return KalturaMetadata
  * @throws KalturaErrors::INVALID_OBJECT_ID
  * @throws MetadataErrors::INVALID_METADATA_DATA
  */
 function updateAction($id, $xmlData = null)
 {
     $dbMetadata = MetadataPeer::retrieveByPK($id);
     if (!$dbMetadata) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     $previousVersion = null;
     if ($dbMetadata->getStatus() == Metadata::STATUS_VALID) {
         $previousVersion = $dbMetadata->getVersion();
     }
     if ($xmlData) {
         $dbMetadata->incrementVersion();
     }
     $dbMetadata->save();
     if ($xmlData) {
         $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
         kFileSyncUtils::file_put_contents($key, $xmlData);
         $errorMessage = '';
         $status = kMetadataManager::validateMetadata($dbMetadata, $errorMessage);
         kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata, $previousVersion));
         if ($status != KalturaMetadataStatus::VALID) {
             throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_DATA, $errorMessage);
         }
     }
     $metadata = new KalturaMetadata();
     $metadata->fromObject($dbMetadata);
     return $metadata;
 }