diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Property.php b/lib/Alchemy/Phrasea/Controller/Prod/Property.php index 1cd991b716..925a6485a1 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Property.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Property.php @@ -244,6 +244,7 @@ class Property implements ControllerProviderInterface public function changeType(Application $app, Request $request) { $typeLst = $request->request->get('types', array()); + $mimeLst = $request->request->get('mimes', array()); $records = RecordsRequest::fromRequest($app, $request, false, array('canmodifrecord')); $forceType = $request->request->get('force_types', ''); $updated = array(); @@ -251,10 +252,16 @@ class Property implements ControllerProviderInterface foreach ($records as $record) { try { $recordType = !empty($forceType) ? $forceType : (isset($typeLst[$record->get_serialize_key()]) ? $typeLst[$record->get_serialize_key()] : null); + $mimeType = isset($mimeLst[$record->get_serialize_key()]) ? $mimeLst[$record->get_serialize_key()] : null; if ($recordType) { $record->set_type($recordType); - $updated[$record->get_serialize_key()] = $recordType; + $updated[$record->get_serialize_key()]['record_type'] = $recordType; + } + + if ($mimeType) { + $record->set_mime($mimeType); + $updated[$record->get_serialize_key()]['mime_type'] = $mimeType; } } catch (\Exception $e) { diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 03ebc4bde4..d2a0b6a81c 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -319,6 +319,32 @@ class record_adapter implements record_Interface, cache_cacheableInterface return $this; } + public function set_mime($mime) + { + $old_mime = $this->get_mime(); + + // see http://lists.w3.org/Archives/Public/xml-dist-app/2003Jul/0064.html + if (!preg_match("/^[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+\/[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+$/", $mime)) { + throw new \Exception(sprintf('Unrecognized mime type %s', $mime)); + } + + $connection = connection::getPDOConnection($this->app, $this->get_sbas_id()); + + $sql = 'UPDATE record SET mime = :mime WHERE record_id = :record_id'; + $stmt = $connection->prepare($sql); + $stmt->execute(array(':mime' => $mime, ':record_id' => $this->get_record_id())); + $stmt->closeCursor(); + + if ($mime !== $old_mime) { + $this->rebuild_subdefs(); + } + + $this->mime = $mime; + $this->delete_data_from_cache(); + + return $this; + } + /** * Return true if the record is a grouping * @@ -1176,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'; diff --git a/templates/web/prod/actions/Property/type.html.twig b/templates/web/prod/actions/Property/type.html.twig index 591db4ead2..e58827087b 100644 --- a/templates/web/prod/actions/Property/type.html.twig +++ b/templates/web/prod/actions/Property/type.html.twig @@ -28,13 +28,14 @@
{{ thumbnail.format(record.get_thumbnail(), 160, 120, "", false, false) }}
-
{{ record.get_title() }}
+
{{ record.get_title() }}

- {% for option in typesEnum %} {% endfor %} +