Merge pull request #2638 from aynsix/PHRAS-2098-save-in-technicaldata-table

PHRAS-2098 Sauvegarder les coordonnées GPS du forward geocoding dans le technicalData du record
This commit is contained in:
Nicolas Maillat
2018-06-13 18:26:42 +02:00
committed by GitHub
2 changed files with 35 additions and 0 deletions

View File

@@ -358,6 +358,10 @@ class EditController extends Controller
$this->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($record));
}
if (isset($rec['technicalsdatas']) && is_array($rec['technicalsdatas'])){
$record->insertOrUpdateTechnicalDatas($rec['technicalsdatas']);
}
$newstat = $record->getStatus();
$statbits = ltrim($statbits, 'x');
if (!in_array($statbits, ['', 'null'])) {

View File

@@ -1338,6 +1338,37 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $this;
}
/**
* Insert or update technical data
* $technicalDatas an array of name => value
*
* @param array $technicalDatas
*/
public function insertOrUpdateTechnicalDatas($technicalDatas)
{
$technicalFields = media_subdef::getTechnicalFieldsList();
$sqlValues = null;
foreach($technicalDatas as $name => $value){
if(array_key_exists($name, $technicalFields)){
if(is_null($value)){
$value = 0;
}
$sqlValues[] = [$this->getRecordId(), $name, $value, $value];
}
}
if($sqlValues){
$connection = $this->getDataboxConnection();
$connection->transactional(function (Connection $connection) use ($sqlValues) {
$statement = $connection->prepare('INSERT INTO technical_datas (record_id, name, value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = ?');
array_walk($sqlValues, [$statement, 'execute']);
});
$this->delete_data_from_cache(self::CACHE_TECHNICAL_DATA);
}
}
/**
* @param databox $databox
* @param string $sha256