Ejemplo n.º 1
0
 /**
  * @param Metadata $metadata
  * @param SimpleXMLElement $mrss
  * @return SimpleXMLElement
  */
 public function contributeMetadata(Metadata $metadata, SimpleXMLElement $mrss)
 {
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xml = kFileSyncUtils::file_get_contents($key, true, false);
     $metadataXml = new SimpleXMLElement($xml);
     $customData = $mrss->addChild('customData');
     $customData->addAttribute('metadataId', $metadata->getId());
     $customData->addAttribute('metadataVersion', $metadata->getVersion());
     $customData->addAttribute('metadataProfileId', $metadata->getMetadataProfileId());
     $customData->addAttribute('metadataProfileVersion', $metadata->getMetadataProfileVersion());
     $this->contributeMetadataObject($customData, $metadataXml);
 }
 /**
  * @param Metadata $metadata
  * @param SimpleXMLElement $mrss
  * @param kMrssParameters $mrssParams
  * @return SimpleXMLElement
  */
 public function contributeMetadata(Metadata $metadata, SimpleXMLElement $mrss, kMrssParameters $mrssParams = null)
 {
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xml = kFileSyncUtils::file_get_contents($key, true, false);
     if (is_null($xml)) {
         KalturaLog::alert("ready file sync was not found for key[{$key}]");
         return;
     }
     $metadataXml = new SimpleXMLElement($xml);
     $customData = $mrss->addChild('customData');
     $customData->addAttribute('metadataId', $metadata->getId());
     $customData->addAttribute('metadataVersion', $metadata->getVersion());
     $customData->addAttribute('metadataProfileId', $metadata->getMetadataProfileId());
     $customData->addAttribute('metadataProfileVersion', $metadata->getMetadataProfileVersion());
     $this->contributeMetadataObject($customData, $metadataXml, $mrssParams, '');
 }
Ejemplo n.º 3
0
 /**
  * @param Metadata $metadata
  * @return int affected records
  */
 protected function deleteOldVersions(Metadata $metadata)
 {
     $c = new Criteria();
     $c->add(MetadataPeer::OBJECT_ID, $metadata->getObjectId());
     $c->add(MetadataPeer::OBJECT_TYPE, $metadata->getObjectType());
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $metadata->getMetadataProfileId());
     $c->add(MetadataPeer::METADATA_PROFILE_VERSION, $metadata->getMetadataProfileVersion(), Criteria::LESS_THAN);
     $c->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED, Criteria::NOT_EQUAL);
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::doSelect($c);
     MetadataPeer::setUseCriteriaFilter(true);
     foreach ($metadatas as $metadata) {
         kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata));
     }
     $update = new Criteria();
     $update->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED);
     $con = Propel::getConnection(MetadataPeer::DATABASE_NAME);
     $count = BasePeer::doUpdate($c, $update, $con);
     return $count;
 }
Ejemplo n.º 4
0
 /**
  * Parse the XML and update the list of search values
  *
  * @param Metadata $metadata
  * @param array $searchValues
  *
  * @return array
  */
 public static function getDataSearchValues(Metadata $metadata, $searchValues = array())
 {
     KalturaLog::debug("Parsing metadata [" . $metadata->getId() . "] search values");
     $searchTexts = array();
     if (isset($searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)])) {
         foreach ($searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)] as $DataSerachValue) {
             $searchTexts[] = $DataSerachValue;
         }
     }
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xmlPath = kFileSyncUtils::getLocalFilePathForKey($key);
     try {
         $xml = new KDOMDocument();
         $xml->load($xmlPath);
         $xPath = new DOMXPath($xml);
     } catch (Exception $ex) {
         KalturaLog::err('Could not load metadata xml [' . $xmlPath . '] - ' . $ex->getMessage());
         return '';
     }
     $profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($metadata->getMetadataProfileId());
     $searchItems = array();
     $textItems = array();
     foreach ($profileFields as $profileField) {
         /* @var  $profileField MetadataProfileField */
         $nodes = $xPath->query($profileField->getXpath());
         if (!$nodes->length) {
             continue;
         }
         if ($profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE || $profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_INT) {
             $node = $nodes->item(0);
             if (!isset($searchValues[MetadataPlugin::SPHINX_DYNAMIC_ATTRIBUTES])) {
                 $searchValues[MetadataPlugin::SPHINX_DYNAMIC_ATTRIBUTES] = array();
             }
             $fieldName = MetadataPlugin::getSphinxFieldName($profileField->getId());
             $searchValues[MetadataPlugin::SPHINX_DYNAMIC_ATTRIBUTES][$fieldName] = intval($node->nodeValue);
             continue;
         }
         $searchItemValues = array();
         foreach ($nodes as $node) {
             $searchItemValues[] = $node->nodeValue;
         }
         if (!count($searchItemValues)) {
             continue;
         }
         if ($profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_TEXT || $profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_METADATA_OBJECT) {
             $textItems[] = implode(' ', $searchItemValues);
             $searchItems[$profileField->getId()] = array();
             foreach ($searchItemValues as $searchItemValue) {
                 if (iconv_strlen($searchItemValue, 'UTF-8') >= 128) {
                     continue;
                 }
                 $searchItems[$profileField->getId()][] = $searchItemValue;
             }
             if ($profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_METADATA_OBJECT && $profileField->getRelatedMetadataProfileId()) {
                 $subMetadataProfileId = $profileField->getRelatedMetadataProfileId();
                 $subMetadataProfile = MetadataProfilePeer::retrieveByPK($subMetadataProfileId);
                 if (!$subMetadataProfile) {
                     KalturaLog::err('Sub metadata profile ' . $subMetadataProfileId . ' was not found');
                     continue;
                 }
                 $subMetadataObjects = MetadataPeer::retrieveByObjects($subMetadataProfileId, $subMetadataProfile->getObjectType(), $searchItemValues);
                 foreach ($subMetadataObjects as $subMetadataObject) {
                     /** @var Metadata $subMetadataObject */
                     KalturaLog::debug("Found metadata object for profile {$subMetadataProfileId} and id {$subMetadataObject->getObjectId()}, extracting search data");
                     $subSearchTextsResult = self::getDataSearchValues($subMetadataObject);
                     $subSearchTexts = $subSearchTextsResult[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)];
                     foreach ($subSearchTexts as $subSearchText) {
                         $searchTexts[] = $subSearchText;
                     }
                 }
             }
         } else {
             $searchItems[$profileField->getId()] = $searchItemValues;
         }
     }
     foreach ($searchItems as $key => $searchItem) {
         foreach ($searchItem as $searchPhrase) {
             $searchTexts[] = MetadataPlugin::PLUGIN_NAME . '_' . "{$key} {$searchPhrase} " . kMetadataManager::SEARCH_TEXT_SUFFIX . '_' . $key;
         }
     }
     if (count($textItems)) {
         $searchTexts['text'] = MetadataSearchFilter::createSphinxSearchCondition($metadata->getPartnerId(), implode(' ', $textItems), true);
     }
     $ret = array();
     foreach ($searchTexts as $index => $value) {
         if (is_int($index)) {
             $ret[$index] = $value;
         }
     }
     if (isset($searchTexts['text'])) {
         $ret['text'] = $searchTexts['text'];
     }
     $searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)] = $ret;
     return $searchValues;
 }
Ejemplo n.º 5
0
 /**
  * Validate the XML against the profile XSD and set the metadata status
  * 
  * @param Metadata $metadata
  * 
  * returns metadata status
  */
 public static function validateMetadata(Metadata $metadata, &$errorMessage)
 {
     KalturaLog::debug('Validating metadata [' . $metadata->getId() . ']');
     $metadataProfile = $metadata->getMetadataProfile();
     if (!$metadataProfile) {
         $errorMessage = 'Metadata profile [' . $metadata->getMetadataProfileId() . '] not found';
         KalturaLog::err($errorMessage);
         return self::setMetadataStatus($metadata, Metadata::STATUS_INVALID);
     }
     $metadataKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xmlPath = kFileSyncUtils::getLocalFilePathForKey($metadataKey);
     if (!file_exists($xmlPath)) {
         $errorMessage = "Metadata xml [{$xmlPath}] not found";
         KalturaLog::err($errorMessage);
         return self::setMetadataStatus($metadata, Metadata::STATUS_INVALID);
     }
     $metadataProfileKey = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     $xsdPath = kFileSyncUtils::getLocalFilePathForKey($metadataProfileKey);
     if (!file_exists($xsdPath)) {
         $errorMessage = "Metadata profile xsd [{$xsdPath}] not found";
         KalturaLog::err($errorMessage);
         return self::setMetadataStatus($metadata, Metadata::STATUS_INVALID);
     }
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xml = new DOMDocument();
     $xml->load($xmlPath);
     if ($xml->schemaValidate($xsdPath)) {
         KalturaLog::debug("Metadata is valid");
         return self::setMetadataStatus($metadata, Metadata::STATUS_VALID, $metadataProfile->getVersion());
     }
     $errorMessage = kXml::getLibXmlErrorDescription(file_get_contents($xmlPath));
     KalturaLog::debug("Metadata is invalid:\n{$errorMessage}");
     return self::setMetadataStatus($metadata, Metadata::STATUS_INVALID);
 }
 /**
  * Parse the XML and update the list of search values
  * 
  * @param Metadata $metadata
  * @param array $searchValues
  * 
  * @return array
  */
 public static function getDataSearchValues(Metadata $metadata, $searchValues = array())
 {
     KalturaLog::debug("Parsing metadata [" . $metadata->getId() . "] search values");
     $searchTexts = array();
     if (isset($searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)])) {
         foreach ($searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)] as $DataSerachValue) {
             $searchTexts[] = $DataSerachValue;
         }
     }
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xmlPath = kFileSyncUtils::getLocalFilePathForKey($key);
     try {
         $xml = new KDOMDocument();
         $xml->load($xmlPath);
         $xPath = new DOMXPath($xml);
     } catch (Exception $ex) {
         KalturaLog::err('Could not load metadata xml [' . $xmlPath . '] - ' . $ex->getMessage());
         return '';
     }
     $profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($metadata->getMetadataProfileId());
     $searchItems = array();
     $textItems = array();
     foreach ($profileFields as $profileField) {
         /* @var  $profileField MetadataProfileField */
         $nodes = $xPath->query($profileField->getXpath());
         if (!$nodes->length) {
             continue;
         }
         if ($profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE || $profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_INT) {
             foreach ($nodes as $node) {
                 if (!is_null($profileField->getSearchIndex())) {
                     $searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPENDER_FIELD_INT) . $profileField->getSearchIndex()] = $node->nodeValue;
                 }
                 break;
             }
             continue;
         }
         $searchItemValues = array();
         foreach ($nodes as $node) {
             $searchItemValues[] = $node->nodeValue;
         }
         if (!count($searchItemValues)) {
             continue;
         }
         if ($profileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_TEXT) {
             $textItems[] = implode(' ', $searchItemValues);
             $searchItems[$profileField->getId()] = array();
             foreach ($searchItemValues as $searchItemValue) {
                 if (iconv_strlen($searchItemValue, 'UTF-8') >= 128) {
                     continue;
                 }
                 $searchItems[$profileField->getId()][] = $searchItemValue;
             }
         } else {
             $searchItems[$profileField->getId()] = $searchItemValues;
         }
     }
     foreach ($searchItems as $key => $searchItem) {
         foreach ($searchItem as $searchPhrase) {
             $searchTexts[] = MetadataPlugin::PLUGIN_NAME . '_' . "{$key} {$searchPhrase} " . kMetadataManager::SEARCH_TEXT_SUFFIX . '_' . $key;
         }
     }
     if (count($textItems)) {
         if (!isset($searchTexts['text'])) {
             $searchTexts['text'] = MetadataPlugin::PLUGIN_NAME . '_text';
         }
         $searchTexts['text'] .= ' ' . implode(' ', $textItems);
         $searchTexts['text'] .= ' ' . kMetadataManager::SEARCH_TEXT_SUFFIX . '_text';
     }
     $ret = array();
     foreach ($searchTexts as $index => $value) {
         if (is_int($index)) {
             $ret[$index] = $value;
         }
     }
     if (isset($searchTexts['text'])) {
         $ret['text'] = $searchTexts['text'];
     }
     $searchValues[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA)] = $ret;
     return $searchValues;
 }