Commit dc160e56 authored by lindonb's avatar lindonb

[ENH] Add ability to refresh metadata in file gallery listings, either...

[ENH] Add ability to refresh metadata in file gallery listings, either individually or selected files.
parent e1511eb0
......@@ -1362,6 +1362,7 @@ img/icons/table_refresh.png -text
img/icons/table_sort.png -text
img/icons/tag_blue.png -text
img/icons/tag_blue_add.png -text
img/icons/tag_green.png -text
img/icons/tag_orange.png -text
img/icons/task_received.png -text
img/icons/task_shared.png -text
......
......@@ -2342,6 +2342,7 @@ class FileGalLib extends TikiLib
'tf.`is_reference`' => "'' as `is_reference`",
'tf.`hash`' => "'' as `hash`",
'tf.`search_data`' => 'tfg.`name` as `search_data`',
'tf.`metadata`' => "'' as `metadata`",
'tf.`lastModif` as `lastModif`' => 'tfg.`lastModif` as `lastModif`',
'tf.`lastModifUser` as `last_user`' => "'' as `last_user`",
'tf.`lockedby`' => "'' as `lockedby`",
......@@ -3688,21 +3689,29 @@ class FileGalLib extends TikiLib
}
/**
* Get file metadata from database column or, if that is empty, extract metadata from the file and update
* the database. Return an array of the data.
* Perform actions with file metadata stored in the database
*
* @param numeric $fileId fileId of the file in the file gallery
* @param numeric $fileId fileId of the file in the file gallery
* @param string $action action to perform regarding metadata
*
* @return array $metadata array of file metadata
* The following actions are handled:
* 'get_array' Get file metadata from database column or, if that is empty, extract metadata from the
* file, update the database and return an array of the data.
*
* 'refresh' Extract metadata from the file and update database - nothing is returned
*
* @return array $metadata array of metadata is returned is action is 'get_array'
*/
function getOrExtractMetadataArray($fileId)
function metadataAction($fileId, $action = 'get_array')
{
//get the tiki_files table
$filesTable = $this->table('tiki_files');
//get metadata for the file from the database
$metacol = $filesTable->fetchColumn('metadata', array('fileId' => $fileId));
//if metadata field is empty extract from the file
if (empty($metacol[0])) {
if ($action == 'get_array') {
//get metadata for the file from the database
$metacol = $filesTable->fetchColumn('metadata', array('fileId' => $fileId));
}
//if metadata field is empty, or if a refresh, extract from the file
if (($action == 'get_array' && empty($metacol[0])) || $action == 'refresh') {
//preparing parameters
$path = $filesTable->fetchColumn('path', array('fileId' => $fileId));
if (!empty($path[0])) {
......@@ -3721,8 +3730,10 @@ class FileGalLib extends TikiLib
} else {
$metadata = $metacol[0];
}
//return metadata as an array
return json_decode($metadata, true);
if ($action == 'get_array') {
//return metadata as an array
return json_decode($metadata, true);
}
}
}
$filegallib = new FileGalLib;
......@@ -127,33 +127,37 @@
{/if}
{if $files[$changes].perms.tiki_p_admin_file_galleries eq 'y' or !$files[$changes].locked or ($files[$changes].locked and $files[$changes].lockedby eq $user) or $gal_info.lockable ne 'y'}
{if $prefs.javascript_enabled eq 'y'}
{* if javascript is available on client, add a menu item that will directly open a file selector, automatically upload the file after selection and that replace the current file with the uploaded one *}
{if $menu_text neq 'y'}</div>{/if}
{if $prefs.fgal_display_replace eq 'y'}
<div class="upspan {if $menu_text eq 'y'}upspantext{/if}" style="display: inline; position:relative{if $menu_text eq 'y'}; position:absolute{else}; float:left{/if}; overflow:hidden" title="{$replace_action_title}">
<input type="file" style="position:absolute; z-index:1001; right:0; top:0; font-size:600px; opacity:0; -moz-opacity:0; filter:alpha(opacity=0); cursor:pointer" name="upfile{$files[$changes].id}" onchange="this.form.submit(); return false;"/>
<input type="hidden" name="fileId" value="{$files[$changes].fileId}" />
<a href="#">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='database_refresh' alt=$replace_action_title}</a>
</div>
{if $menu_text eq 'y'}
{* the line above is used to give enough space to the real 'Upload New Version' button *}
<a style="visibility: hidden">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='database_refresh' alt=$replace_action_title}</a>
{if $prefs.javascript_enabled eq 'y'}
{* if javascript is available on client, add a menu item that will directly open a file selector, automatically upload the file after selection and that replace the current file with the uploaded one *}
{if $menu_text neq 'y'}</div>{/if}
{if $prefs.fgal_display_replace eq 'y'}
<div class="upspan {if $menu_text eq 'y'}upspantext{/if}" style="display: inline; position:relative{if $menu_text eq 'y'}; position:absolute{else}; float:left{/if}; overflow:hidden" title="{$replace_action_title}">
<input type="file" style="position:absolute; z-index:1001; right:0; top:0; font-size:600px; opacity:0; -moz-opacity:0; filter:alpha(opacity=0); cursor:pointer" name="upfile{$files[$changes].id}" onchange="this.form.submit(); return false;"/>
<input type="hidden" name="fileId" value="{$files[$changes].fileId}" />
<a href="#">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='database_refresh' alt=$replace_action_title}</a>
</div>
{if $menu_text eq 'y'}
{* the line above is used to give enough space to the real 'Upload New Version' button *}
<a style="visibility: hidden">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='database_refresh' alt=$replace_action_title}</a>
{/if}
{/if}
{else}
{* for the moment, no-javascript version is simply a link to the edit page where you can also upload *}
<a href="tiki-upload_file.php?galleryId={$files[$changes].galleryId}&amp;fileId={$files[$changes].id}{if !empty($filegals_manager)}&amp;filegals_manager={$filegals_manager|escape}{/if}">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='database_refresh' alt="{tr}Upload New Version{/tr}"}</a>
{/if}
{if $prefs.fgal_display_properties eq 'y'}
<a href="tiki-upload_file.php?galleryId={$files[$changes].galleryId}&amp;fileId={$files[$changes].id}{if !empty($filegals_manager)}&amp;filegals_manager={$filegals_manager|escape}{/if}">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='page_edit' alt="{tr}Properties{/tr}"}</a>
{* using &amp; causes an error for some reason - therefore using plain & *}
<a href="tiki-upload_file.php?galleryId={$files[$changes].galleryId}&fileId={$files[$changes].id}&action=refresh_metadata">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='tag_green' alt="{tr}Refresh Metadata{/tr}"}</a>
{/if}
{else}
{* for the moment, no-javascript version is simply a link to the edit page where you can also upload *}
<a href="tiki-upload_file.php?galleryId={$files[$changes].galleryId}&amp;fileId={$files[$changes].id}{if !empty($filegals_manager)}&amp;filegals_manager={$filegals_manager|escape}{/if}">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='database_refresh' alt="{tr}Upload New Version{/tr}"}</a>
{/if}
{if $prefs.fgal_display_properties eq 'y'}
<a href="tiki-upload_file.php?galleryId={$files[$changes].galleryId}&amp;fileId={$files[$changes].id}{if !empty($filegals_manager)}&amp;filegals_manager={$filegals_manager|escape}{/if}">{icon _menu_text=$menu_text _menu_icon=$menu_icon _id='page_edit' alt="{tr}Properties{/tr}"}</a>
{/if}
{/if}
{if $gal_info.lockable eq 'y' and $files[$changes].isgal neq 1}
......
......@@ -95,6 +95,8 @@
{icon _id='cross' _tag='input_image' _confirm="{tr}Are you sure you want to delete the selected files?{/tr}" name='delsel' alt="{tr}Delete{/tr}" style='vertical-align: middle;'}
{/if}
{icon _id='tag_green' _tag='input_image' name='refresh_metadata' alt="{tr}Refresh Metadata{/tr}" style='vertical-align: middle;'}
{if $tiki_p_admin_file_galleries eq 'y'}
{icon _id='arrow_refresh' _tag='input_image' _confirm="{tr}Are you sure you want to reset the default gallery list table settings?{/tr}" name='defaultsel' alt="{tr}Reset to default gallery list table settings{/tr}" style='vertical-align: middle;'}
{/if}
......
......@@ -161,6 +161,12 @@ if ($tiki_p_admin_file_galleries == 'y') {
}
unset($_REQUEST['view']);
}
if (isset($_REQUEST['refresh_metadata_x'])) {
foreach (array_values($_REQUEST['file']) as $file) {
$filegallib->metadataAction($file, 'refresh');
}
}
}
if (isset($_REQUEST['zipsel_x']) && $tiki_p_upload_files == 'y') {
......
......@@ -124,6 +124,10 @@ if ( ! empty( $fileId ) ) {
}
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'refresh_metadata') {
$filegallib->metadataAction($_REQUEST['fileId'], 'refresh');
}
$smarty->assign('show', 'n');
if (!empty($_REQUEST['galleryId'][0]) && $prefs['feature_groupalert'] == 'y') {
$groupforalert = $groupalertlib->GetGroup('file gallery', (int)$_REQUEST['galleryId'][0]);
......@@ -203,7 +207,7 @@ if ( $prefs['fgal_limit_hits_per_file'] == 'y' ) {
}
if (!empty($fileInfo['fileId'])) {
$smarty->assign('metarray', $filegallib->getOrExtractMetadataArray($fileInfo['fileId']));
$smarty->assign('metarray', $filegallib->metadataAction($fileInfo['fileId']), 'get_array');
}
$cat_type = 'file';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment