PHRAS-374 Add command to rebuild subdefs

This commit is contained in:
Nicolas Le Goff
2015-01-15 13:22:37 +01:00
parent e43036aaf1
commit 10c3869ca3
6 changed files with 222 additions and 47 deletions

View File

@@ -1202,7 +1202,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*
* @return record_adapter
*/
public function rebuild_subdefs()
public function rebuild_subdefs()
{
$connbas = connection::getPDOConnection($this->app, $this->get_sbas_id());
$sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id';
@@ -1213,6 +1213,38 @@ class record_adapter implements record_Interface, cache_cacheableInterface
return $this;
}
public function get_missing_subdefs()
{
$databox = $this->get_databox();
try {
$this->get_hd_file();
} catch (\Exception $e) {
return array();
}
$subDefDefinitions = $databox->get_subdef_structure()->getSubdefGroup($this->get_type());
if (!$subDefDefinitions) {
return array();
}
$record = $this;
$wanted_subdefs = array_map(function($subDef) {
return $subDef->get_name();
}, array_filter($subDefDefinitions, function($subDef) use ($record) {
return !$record->has_subdef($subDef->get_name());
}));
$missing_subdefs = array_map(function($subDef) {
return $subDef->get_name();
}, array_filter($this->get_subdefs(), function($subdef) {
return !$subdef->is_physically_present();
}));
return array_values(array_merge($wanted_subdefs, $missing_subdefs));
}
/**
*
* @return record_adapter