mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
feature 1453 added: ability to check for uniqueness on filename. No change on
the default behavior: uniqueness is set on md5sum. git-svn-id: http://piwigo.org/svn/branches/2.0@4953 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -322,6 +322,10 @@ $conf['default_redirect_method'] = 'http';
|
||||
// Define using double password type in admin's users management panel
|
||||
$conf['double_password_type_in_admin'] = false;
|
||||
|
||||
// how should we check for unicity when adding a photo. Can be 'md5sum' or
|
||||
// 'filename'
|
||||
$conf['uniqueness_mode'] = 'md5sum';
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | metadata |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
@@ -1204,11 +1204,20 @@ function ws_images_add($params, &$service)
|
||||
}
|
||||
|
||||
// does the image already exists ?
|
||||
if ('md5sum' == $conf['uniqueness_mode'])
|
||||
{
|
||||
$where_clause = "md5sum = '".$params['original_sum']."'";
|
||||
}
|
||||
if ('filename' == $conf['uniqueness_mode'])
|
||||
{
|
||||
$where_clause = "file = '".$params['original_filename']."'";
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
COUNT(*) AS counter
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE md5sum = \''.$params['original_sum'].'\'
|
||||
WHERE '.$where_clause.'
|
||||
;';
|
||||
list($counter) = mysql_fetch_row(pwg_query($query));
|
||||
if ($counter != 0) {
|
||||
@@ -1597,37 +1606,76 @@ function ws_tags_add($params, &$service)
|
||||
|
||||
function ws_images_exist($params, &$service)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (!is_admin() or is_adviser())
|
||||
{
|
||||
return new PwgError(401, 'Access denied');
|
||||
}
|
||||
|
||||
// search among photos the list of photos already added, based on md5sum
|
||||
// list
|
||||
$md5sums = preg_split(
|
||||
'/[\s,;\|]/',
|
||||
$params['md5sum_list'],
|
||||
-1,
|
||||
PREG_SPLIT_NO_EMPTY
|
||||
$split_pattern = '/[\s,;\|]/';
|
||||
|
||||
if ('md5sum' == $conf['uniqueness_mode'])
|
||||
{
|
||||
// search among photos the list of photos already added, based on md5sum
|
||||
// list
|
||||
$md5sums = preg_split(
|
||||
$split_pattern,
|
||||
$params['md5sum_list'],
|
||||
-1,
|
||||
PREG_SPLIT_NO_EMPTY
|
||||
);
|
||||
|
||||
$query = '
|
||||
$query = '
|
||||
SELECT
|
||||
id,
|
||||
md5sum
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE md5sum IN (\''.implode("','", $md5sums).'\')
|
||||
;';
|
||||
$id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');
|
||||
$id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');
|
||||
|
||||
$result = array();
|
||||
$result = array();
|
||||
|
||||
foreach ($md5sums as $md5sum)
|
||||
{
|
||||
$result[$md5sum] = null;
|
||||
if (isset($id_of_md5[$md5sum]))
|
||||
foreach ($md5sums as $md5sum)
|
||||
{
|
||||
$result[$md5sum] = $id_of_md5[$md5sum];
|
||||
$result[$md5sum] = null;
|
||||
if (isset($id_of_md5[$md5sum]))
|
||||
{
|
||||
$result[$md5sum] = $id_of_md5[$md5sum];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ('filename' == $conf['uniqueness_mode'])
|
||||
{
|
||||
// search among photos the list of photos already added, based on
|
||||
// filename list
|
||||
$filenames = preg_split(
|
||||
$split_pattern,
|
||||
$params['filename_list'],
|
||||
-1,
|
||||
PREG_SPLIT_NO_EMPTY
|
||||
);
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
id,
|
||||
file
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE file IN (\''.implode("','", $filenames).'\')
|
||||
;';
|
||||
$id_of_filename = simple_hash_from_query($query, 'file', 'id');
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($filenames as $filename)
|
||||
{
|
||||
$result[$filename] = null;
|
||||
if (isset($id_of_filename[$filename]))
|
||||
{
|
||||
$result[$filename] = $id_of_filename[$filename];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user