Fix caption record cache invalidation when Databox structure DCES settings are modified

This commit is contained in:
Romain Neutron
2013-05-24 11:45:20 +02:00
parent 8a28ff16bc
commit f146d6725a
3 changed files with 21 additions and 10 deletions

View File

@@ -38,7 +38,6 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @var record
*/
protected $record;
protected $dces_elements = array();
protected $databox;
protected $app;
@@ -179,10 +178,6 @@ class caption_record implements caption_interface, cache_cacheableInterface
$metadata = new caption_field($this->app, $databox_meta_struct, $this->record);
$rec_fields[$databox_meta_struct->get_id()] = $metadata;
$dces_element = $metadata->get_databox_field()->get_dces_element();
if ($dces_element instanceof databox_Field_DCESAbstract) {
$this->dces_elements[$dces_element->get_label()] = $databox_meta_struct->get_id();
}
}
$this->fields = $rec_fields;
@@ -240,8 +235,11 @@ class caption_record implements caption_interface, cache_cacheableInterface
public function get_dc_field($label)
{
$fields = $this->retrieve_fields();
if (isset($this->dces_elements[$label])) {
return $fields[$this->dces_elements[$label]];
if (null !== $field = $this->databox->get_meta_structure()->get_dces_field($label)) {
if (isset($fields[$field->get_id()])) {
return $fields[$field->get_id()];
}
}
return null;

View File

@@ -109,6 +109,19 @@ class databox_descriptionStructure implements IteratorAggregate
return null;
}
public function get_dces_field($label)
{
foreach ($this->elements as $field) {
if (null !== $dces_element = $field->get_dces_element()) {
if ($label === $dces_element->get_label()) {
return $field;
}
}
}
return null;
}
/**
*
* @param string $id

View File

@@ -170,7 +170,7 @@ class caption_recordTest extends PhraseanetPHPUnitAbstract
break;
}
if (!$meta) {
if (!$field) {
$this->markTestSkipped('Unable to set a DC field');
}
@@ -180,7 +180,7 @@ class caption_recordTest extends PhraseanetPHPUnitAbstract
self::$DI['record_1']->set_metadatas(array(
array(
'meta_id' => null,
'meta_struct_id' => $meta->get_id(),
'meta_struct_id' => $field->get_id(),
'value' => array('HELLO MO !'),
)
));