mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 11:49:56 +03:00
fixes #860 detect duplicates during upload
This commit is contained in:
parent
14e8ba664b
commit
439f275d4e
7 changed files with 106 additions and 37 deletions
|
@ -49,6 +49,7 @@ $main_checkboxes = array(
|
|||
'history_guest',
|
||||
'show_mobile_app_banner_in_gallery',
|
||||
'show_mobile_app_banner_in_admin',
|
||||
'upload_detect_duplicate',
|
||||
);
|
||||
|
||||
$sizes_checkboxes = array(
|
||||
|
|
|
@ -141,10 +141,7 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
|
|||
//
|
||||
// 3) register in database
|
||||
|
||||
// TODO
|
||||
// * check md5sum (already exists?)
|
||||
|
||||
global $conf, $user;
|
||||
global $conf, $user, $logger;
|
||||
|
||||
if (!is_null($original_filename))
|
||||
{
|
||||
|
@ -160,6 +157,33 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
|
|||
$md5sum = md5_file($source_filepath);
|
||||
}
|
||||
|
||||
// we only try to detect duplicate on a new image, not when updating an existing image
|
||||
if (!isset($image_id) and conf_get_param('upload_detect_duplicate', false))
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
id
|
||||
FROM '. IMAGES_TABLE .'
|
||||
WHERE md5sum = \''.$md5sum.'\'
|
||||
;';
|
||||
$images_found = query2array($query);
|
||||
|
||||
if (count($images_found) > 0)
|
||||
{
|
||||
$image_id = $images_found[0]['id'];
|
||||
$logger->info('['.__FUNCTION__.'] image already exist #'.$image_id.', we delete the newly uploaded file : '.$source_filepath);
|
||||
unlink($source_filepath);
|
||||
|
||||
// if the destination category is already linked to this photo, no worry,
|
||||
// associate_images_to_categories perfectly handles this case
|
||||
add_uploaded_file_add_to_categories($image_id, $categories);
|
||||
|
||||
// TODO should we update level? If yes, then we should invalidate_user_cache
|
||||
|
||||
return $image_id;
|
||||
}
|
||||
}
|
||||
|
||||
$file_path = null;
|
||||
|
||||
if (isset($image_id))
|
||||
|
@ -262,7 +286,6 @@ SELECT
|
|||
// pwg_representative file.
|
||||
$representative_ext = trigger_change('upload_file', null, $file_path);
|
||||
|
||||
global $logger;
|
||||
$logger->info("Handling " . (string)$file_path . " got " . (string)$representative_ext);
|
||||
|
||||
// If it is set to either true (the file didn't need a
|
||||
|
@ -360,6 +383,45 @@ SELECT
|
|||
pwg_activity('photo', $image_id, 'add');
|
||||
}
|
||||
|
||||
add_uploaded_file_add_to_categories($image_id, $categories);
|
||||
|
||||
// update metadata from the uploaded file (exif/iptc)
|
||||
if ($conf['use_exif'] and !function_exists('exif_read_data'))
|
||||
{
|
||||
$conf['use_exif'] = false;
|
||||
}
|
||||
sync_metadata(array($image_id));
|
||||
|
||||
// cache a derivative
|
||||
$query = '
|
||||
SELECT
|
||||
id,
|
||||
path,
|
||||
representative_ext
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id = '.$image_id.'
|
||||
;';
|
||||
$image_infos = pwg_db_fetch_assoc(pwg_query($query));
|
||||
$src_image = new SrcImage($image_infos);
|
||||
|
||||
set_make_full_url();
|
||||
// in case we are on uploadify.php, we have to replace the false path
|
||||
$derivative_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::url(IMG_MEDIUM, $src_image));
|
||||
unset_make_full_url();
|
||||
|
||||
$logger->info(__FUNCTION__.' : force cache generation, derivative_url = '.$derivative_url);
|
||||
|
||||
fetchRemote($derivative_url, $dest);
|
||||
|
||||
trigger_notify('loc_end_add_uploaded_file', $image_infos);
|
||||
|
||||
return $image_id;
|
||||
}
|
||||
|
||||
function add_uploaded_file_add_to_categories($image_id, $categories)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (!isset($conf['lounge_active']))
|
||||
{
|
||||
conf_update_param('lounge_active', false, true);
|
||||
|
@ -387,42 +449,10 @@ SELECT
|
|||
}
|
||||
}
|
||||
|
||||
// update metadata from the uploaded file (exif/iptc)
|
||||
if ($conf['use_exif'] and !function_exists('exif_read_data'))
|
||||
{
|
||||
$conf['use_exif'] = false;
|
||||
}
|
||||
sync_metadata(array($image_id));
|
||||
|
||||
if (!$conf['lounge_active'])
|
||||
{
|
||||
invalidate_user_cache();
|
||||
}
|
||||
|
||||
// cache a derivative
|
||||
$query = '
|
||||
SELECT
|
||||
id,
|
||||
path,
|
||||
representative_ext
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id = '.$image_id.'
|
||||
;';
|
||||
$image_infos = pwg_db_fetch_assoc(pwg_query($query));
|
||||
$src_image = new SrcImage($image_infos);
|
||||
|
||||
set_make_full_url();
|
||||
// in case we are on uploadify.php, we have to replace the false path
|
||||
$derivative_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::url(IMG_MEDIUM, $src_image));
|
||||
unset_make_full_url();
|
||||
|
||||
$logger->info(__FUNCTION__.' : force cache generation, derivative_url = '.$derivative_url);
|
||||
|
||||
fetchRemote($derivative_url, $dest);
|
||||
|
||||
trigger_notify('loc_end_add_uploaded_file', $image_infos);
|
||||
|
||||
return $image_id;
|
||||
}
|
||||
|
||||
function add_format($source_filepath, $format_ext, $format_of)
|
||||
|
|
|
@ -242,6 +242,17 @@ jQuery("input[name='email_admin_on_new_user_filter']").change(function() {
|
|||
<span class="icon-help-circled tiptip-with-img show-mobile-app-banner-tooltip" title="{'Displays a banner to install or open the official Piwigo app'|translate}<br><img src='admin/themes/default/images/piwigo_app_banner.jpg' style='width:100%;margin-top:5px;'>" style="cursor:help"></span>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label class="font-checkbox">
|
||||
<span class="icon-check"></span>
|
||||
<input type="checkbox" name="upload_detect_duplicate" {if ($main.upload_detect_duplicate)}checked="checked"{/if}>
|
||||
{'Detect and avoid duplicates during upload'|translate}
|
||||
</label>
|
||||
|
||||
<span class="icon-help-circled tiptip" title="{'During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file'|translate}" style="cursor:help"></span>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<label>{'Mail theme'|translate}</label>
|
||||
|
||||
|
|
|
@ -77,3 +77,4 @@ INSERT INTO piwigo_config (param,value) VALUES ('show_mobile_app_banner_in_admin
|
|||
INSERT INTO piwigo_config (param,value) VALUES ('show_mobile_app_banner_in_gallery','false');
|
||||
INSERT INTO piwigo_config (param,value) VALUES ('index_search_in_set_button','true');
|
||||
INSERT INTO piwigo_config (param,value) VALUES ('index_search_in_set_action','true');
|
||||
INSERT INTO piwigo_config (param,value) VALUES ('upload_detect_duplicate','true');
|
||||
|
|
22
install/db/170-database.php
Normal file
22
install/db/170-database.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | This file is part of Piwigo. |
|
||||
// | |
|
||||
// | For copyright and license information, please view the COPYING.txt |
|
||||
// | file that was distributed with this source code. |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
if (!defined('PHPWG_ROOT_PATH'))
|
||||
{
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
$upgrade_description = 'add config parameter to handle duplicate on upload';
|
||||
|
||||
// we set it to false in this upgrade script, as opposed to the default value
|
||||
// for a new installation, because it was the default behavior before Piwigo 14
|
||||
conf_update_param('upload_detect_duplicate', false);
|
||||
|
||||
echo "\n".$upgrade_description."\n";
|
||||
|
||||
?>
|
|
@ -1348,4 +1348,6 @@ $lang['Unlock it'] = 'Unlock it';
|
|||
$lang['All admins'] = 'All admins';
|
||||
$lang['Only admins in a specific group'] = 'Only admins in a specific group';
|
||||
$lang['Activate button "%s"'] = 'Activate button "%s"';
|
||||
$lang['Detect and avoid duplicates during upload'] = 'Detect and avoid duplicates during upload';
|
||||
$lang['During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file'] = 'During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file';
|
||||
// Leave this line empty
|
||||
|
|
|
@ -1348,4 +1348,6 @@ $lang['Unlock it'] = 'Le déverrouiller';
|
|||
$lang['All admins'] = 'Tous les administrateurs';
|
||||
$lang['Only admins in a specific group'] = 'Uniquement les administrations d\'un groupe spécifique';
|
||||
$lang['Activate button "%s"'] = 'Afficher le bouton "%s"';
|
||||
$lang['Detect and avoid duplicates during upload'] = 'Détecter et éviter les doublons à l\'import';
|
||||
$lang['During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file'] = 'Pendant l\'ajout de photo, si Piwigo détecte que la photo existe déjà, associer la photo existante à l\'album de destination, sans dupliquer le fichier.';
|
||||
// Leave this line empty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue