From 923265f71b12304b3691cafb2c282f0d901fe216 Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Wed, 13 Jun 2018 11:06:24 +0400 Subject: [PATCH 1/2] insert or update in technical_data table --- .../Controller/Prod/EditController.php | 4 +++ lib/classes/record/adapter.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php index a050c6cd3a..849c5af046 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php @@ -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'])) { diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 2f1f3658ac..fc21b724ba 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -1338,6 +1338,35 @@ 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']); + }); + } + } + /** * @param databox $databox * @param string $sha256 From 3996f842a2479884f5b5485455c26d8521145b2c Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Wed, 13 Jun 2018 17:56:17 +0400 Subject: [PATCH 2/2] delete data from cache --- lib/classes/record/adapter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index fc21b724ba..c0167fdba2 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -1364,6 +1364,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $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); } }