mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
PHRAS-372 Allow user to change mime type of a record
This commit is contained in:
@@ -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) {
|
||||
|
||||
|
@@ -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';
|
||||
|
@@ -28,13 +28,14 @@
|
||||
<div class="thumbnail" style="min-height:205px">
|
||||
{{ thumbnail.format(record.get_thumbnail(), 160, 120, "", false, false) }}
|
||||
<div class="caption">
|
||||
<h5>{{ record.get_title() }}</h5>
|
||||
<h5 style="word-break:break-all;">{{ record.get_title() }}</h5>
|
||||
<p>
|
||||
<select name="types[{{record.get_serialize_key()}}]" style="width:100%">
|
||||
<select name="types[{{record.get_serialize_key()}}]" class="input-block-level">
|
||||
{% for option in typesEnum %}
|
||||
<option value="{{ option }}" {{ record.is_grouping() ? "disabled='disabled'": "" }} {{ option == record.get_type() ? "selected='selected'" : '' }}>{{ option }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input class="input-block-level" type="text" name="mimes[{{record.get_serialize_key()}}]" value="{{ record.get_mime }}" style="width:100%">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user