コード例 #1
0
 /**
  * @test
  */
 public function shouldBeAbleToCreateMetadata()
 {
     // given
     $m = new Metadata('White');
     // then
     $this->assertNotNull($m->getId());
 }
 /**
  * @param Metadata $metadata
  */
 protected function metadataDeleted(Metadata $metadata)
 {
     $this->syncableDeleted($metadata->getId(), FileSyncObjectType::METADATA);
     // updated in the indexing server (sphinx)
     $object = kMetadataManager::getObjectFromPeer($metadata);
     if ($object && $object instanceof IIndexable) {
         kEventsManager::raiseEvent(new kObjectUpdatedEvent($object));
     }
 }
コード例 #3
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, '');
 }
コード例 #5
0
 public function setMetadataKey($key)
 {
     $m = new Metadata($key);
     $this->setValue('metadata_id', $m->getId());
 }
 /**
  * @param Metadata $metadata
  */
 public static function onMetadataChanged(Metadata $metadata, $previousVersion)
 {
     if (!ContentDistributionPlugin::isAllowedPartner($metadata->getPartnerId())) {
         return true;
     }
     if ($metadata->getObjectType() != MetadataObjectType::ENTRY) {
         return true;
     }
     KalturaLog::log("Metadata [" . $metadata->getId() . "] for entry [" . $metadata->getObjectId() . "] changed");
     $syncKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xmlPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     if (!$xmlPath) {
         KalturaLog::log("Entry metadata xml not found");
         return true;
     }
     $xml = new KDOMDocument();
     $xml->load($xmlPath);
     $previousXml = null;
     if ($previousVersion) {
         $syncKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA, $previousVersion);
         $xmlPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
         if ($xmlPath) {
             $previousXml = new KDOMDocument();
             $previousXml->load($xmlPath);
         } else {
             KalturaLog::log("Entry metadata previous version xml not found");
         }
     }
     $entryDistributions = EntryDistributionPeer::retrieveByEntryId($metadata->getObjectId());
     foreach ($entryDistributions as $entryDistribution) {
         if ($entryDistribution->getStatus() != EntryDistributionStatus::QUEUED && $entryDistribution->getStatus() != EntryDistributionStatus::PENDING && $entryDistribution->getStatus() != EntryDistributionStatus::READY) {
             continue;
         }
         $distributionProfileId = $entryDistribution->getDistributionProfileId();
         $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId);
         if (!$distributionProfile) {
             KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] profile [{$distributionProfileId}] not found");
             continue;
         }
         $distributionProvider = $distributionProfile->getProvider();
         if (!$distributionProvider) {
             KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProfile->getProviderType() . "] not found");
             continue;
         }
         if ($entryDistribution->getStatus() == EntryDistributionStatus::PENDING || $entryDistribution->getStatus() == EntryDistributionStatus::QUEUED) {
             $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT);
             $entryDistribution->setValidationErrorsArray($validationErrors);
             $entryDistribution->save();
             if ($entryDistribution->getStatus() == EntryDistributionStatus::QUEUED) {
                 if ($entryDistribution->getDirtyStatus() != EntryDistributionDirtyStatus::SUBMIT_REQUIRED) {
                     self::submitAddEntryDistribution($entryDistribution, $distributionProfile);
                 }
             }
             continue;
         }
         if ($entryDistribution->getStatus() == EntryDistributionStatus::READY) {
             if ($entryDistribution->getDirtyStatus() == EntryDistributionDirtyStatus::UPDATE_REQUIRED) {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] already flaged for updating");
                 //					continue;
             }
             if (!$distributionProvider->isUpdateEnabled()) {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update");
                 continue;
             }
             $updateRequiredMetadataXPaths = $distributionProvider->getUpdateRequiredMetadataXPaths($distributionProfileId);
             $updateRequired = false;
             foreach ($updateRequiredMetadataXPaths as $updateRequiredMetadataXPath) {
                 $xPath = new DOMXpath($xml);
                 $newElements = $xPath->query($updateRequiredMetadataXPath);
                 $oldElements = null;
                 if ($previousXml) {
                     $xPath = new DOMXpath($previousXml);
                     $oldElements = $xPath->query($updateRequiredMetadataXPath);
                 }
                 if (is_null($newElements) && is_null($oldElements)) {
                     continue;
                 }
                 if (is_null($newElements) xor is_null($oldElements)) {
                     $updateRequired = true;
                 } elseif ($newElements->length == $oldElements->length) {
                     for ($index = 0; $index < $newElements->length; $index++) {
                         $newValue = $newElements->item($index)->textContent;
                         $oldValue = $oldElements->item($index)->textContent;
                         if ($newValue != $oldValue) {
                             $updateRequired = true;
                             break;
                         }
                     }
                 }
                 if ($updateRequired) {
                     break;
                 }
             }
             $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::UPDATE);
             $entryDistribution->setValidationErrorsArray($validationErrors);
             $entryDistribution->save();
             if (!$updateRequired) {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] update not required");
                 continue;
             }
             if (!count($validationErrors) && $distributionProfile->getUpdateEnabled() == DistributionProfileActionStatus::AUTOMATIC) {
                 self::submitUpdateEntryDistribution($entryDistribution, $distributionProfile);
             } else {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] should not be updated automatically");
                 $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::UPDATE_REQUIRED);
                 $entryDistribution->save();
                 continue;
             }
         }
     }
     return true;
 }
コード例 #7
0
ファイル: BaseMetadataPeer.php プロジェクト: DBezemer/server
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Metadata $value A Metadata object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Metadata $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('MetadataPeer');
         }
     }
 }
コード例 #8
0
ファイル: MetadataPlugin.php プロジェクト: richhl/kalturaCE
 /**
  * @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);
     }
 }
コード例 #9
0
ファイル: kMetadataManager.php プロジェクト: AdiTal/server
 /**
  * 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;
 }
コード例 #10
0
ファイル: BaseMetadataPeer.php プロジェクト: richhl/kalturaCE
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Metadata $value A Metadata object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Metadata $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #11
0
ファイル: kMetadataManager.php プロジェクト: richhl/kalturaCE
 /**
  * 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;
 }