Add consistency check on caption field values

This commit is contained in:
Romain Neutron
2012-03-21 11:58:24 +01:00
parent 0ecb391e8d
commit a43d764f3d
5 changed files with 127 additions and 34 deletions

View File

@@ -108,7 +108,7 @@ class cache_databox
$record = new \record_adapter($sbas_id, $row['value']);
$record->get_caption()->delete_data_from_cache();
foreach ($record->get_caption()->get_fields() as $field)
foreach ($record->get_caption()->get_fields(null, true) as $field)
{
$field->delete_data_from_cache();
}

View File

@@ -309,13 +309,18 @@ class caption_Field_Value
);
$all_datas = array();
foreach ($this->record->get_caption()->get_fields() as $field)
foreach ($this->record->get_caption()->get_fields(null, true) as $field)
{
if (!$field->is_indexable())
{
continue;
}
$all_datas[] = $field->get_serialized_values();
}
$all_datas = implode(' ', $all_datas);
$all_datas = implode(' ', $all_datas);
$sphinx_rt->replace_in_documents(
"docs_realtime" . $sbas_crc, //$this->id,
@@ -335,6 +340,35 @@ class caption_Field_Value
{
$connbas = $databox_field->get_connection();
/**
* Check consistency
*/
if (!$databox_field->is_multi())
{
try
{
$field = $record->get_caption()->get_field($databox_field->get_name());
$caption_field_value = array_pop($field->get_values());
/* @var $value \caption_Field_Value */
$caption_field_value->set_value($value);
if (!$vocabulary || !$vocabularyId)
{
$caption_field_value->removeVocabulary();
}
else
{
$caption_field_value->setVocab($vocabulary, $vocabularyId);
}
return $caption_field_value;
}
catch (\Exception $e)
{
}
}
$sql_ins = 'INSERT INTO metadatas
(id, record_id, meta_struct_id, value, VocabularyType, VocabularyId)
VALUES

View File

@@ -70,6 +70,7 @@ class caption_field
/**
* TRIGG CORRECTION;
*/
throw new \Exception('Inconsistency detected');
}
foreach ($rs as $row)
@@ -337,6 +338,77 @@ class caption_field
return;
}
public static function merge_all_metadatas(databox_field $databox_field)
{
$sql = 'SELECT record_id, id, value FROM metadatas
WHERE meta_struct_id = :meta_struct_id ORDER BY record_id';
$params = array(
':meta_struct_id' => $databox_field->get_id()
);
$stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
$current_record_id = null;
$values = $current_metadatas = array();
foreach ($rs as $row)
{
if ($current_record_id && $current_record_id != $row['record_id'])
{
try
{
$record = $databox_field->get_databox()->get_record($current_record_id);
$record->set_metadatas($current_metadatas);
$record->set_metadatas(array(array(
'meta_id' => null
, 'meta_struct_id' => $databox_field->get_id()
, 'value' => implode(' ; ', $values)
)));
unset($record);
}
catch (Exception $e)
{
}
$values = $current_metadatas = array();
}
$current_record_id = $row['record_id'];
$current_metadatas[] = array(
'meta_id' => $row['id']
, 'meta_struct_id' => $databox_field->get_id()
, 'value' => ''
);
$values[] = $row['value'];
}
try
{
$record = $databox_field->get_databox()->get_record($current_record_id);
$record->set_metadatas($current_metadatas);
$record->set_metadatas(array(array(
'meta_id' => null
, 'meta_struct_id' => $databox_field->get_id()
, 'value' => implode(' ; ', $values)
)));
unset($record);
}
catch (Exception $e)
{
}
return;
}
public static function delete_all_metadatas(databox_field $databox_field)
{
$sql = 'SELECT count(id) as count_id FROM metadatas

View File

@@ -104,6 +104,7 @@ class databox_field implements cache_cacheableInterface
*/
protected $Business;
protected $renamed = false;
protected $metaToMerge = false;
/**
*
@@ -378,6 +379,12 @@ class databox_field implements cache_cacheableInterface
$this->renamed = false;
}
if ($this->metaToMerge)
{
caption_field::merge_all_metadatas($this);
$this->metaToMerge = false;
}
$dom_struct = $this->databox->get_dom_structure();
$xp_struct = $this->databox->get_xpath_structure();
@@ -583,7 +590,14 @@ class databox_field implements cache_cacheableInterface
*/
public function set_multi($multi)
{
$this->multi = !!$multi;
$multi = !!$multi;
if($this->multi !== $multi && !$multi)
{
$this->metaToMerge = true;
}
$this->multi = $multi;
return $this;
}
@@ -651,35 +665,6 @@ class databox_field implements cache_cacheableInterface
return $this;
}
/**
*
* @param string $attr
* @return databox_field
*/
protected function set_reg_attr($attr)
{
try
{
$sql = 'UPDATE metadatas_structure SET reg' . $attr . ' = null';
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'UPDATE metadatas_structure SET reg' . $attr . '= 1 WHERE id= :id';
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $this->id));
$stmt->closeCursor();
}
catch (Exception $e)
{
}
return $this;
}
/**
*
* @return string

View File

@@ -632,8 +632,10 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$rs = $res['results'];
$res = array_shift($rs);
if (! isset($res['xml']))
{
return array();
}
$sxe = simplexml_load_string($res['xml']);
foreach ($fields as $name => $field)