mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-08-02 23:13:20 +02:00
fix #663, batch manager, avoid SQL error with duplicates
* when searching duplicates on md5sum, only consider md5sum not null * in case the GROUP_CONCAT returns on truncated string, remove the trailing "," * add a TODO to find a better algorithm, avoiding the GROUP_CONCAT limit to 1024 chars
This commit is contained in:
+16
-1
@@ -406,10 +406,24 @@ SELECT
|
|||||||
$duplicates_on_fields[] = 'height';
|
$duplicates_on_fields[] = 'height';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO improve this algorithm, because GROUP_CONCAT is truncated at
|
||||||
|
// 1024 chars. So if you have more than ~250 duplicates for a given
|
||||||
|
// combination of "duplicates_on_fields" you won't get all the
|
||||||
|
// duplicates.
|
||||||
|
|
||||||
$query = '
|
$query = '
|
||||||
SELECT
|
SELECT
|
||||||
GROUP_CONCAT(id) AS ids
|
GROUP_CONCAT(id) AS ids
|
||||||
FROM '.IMAGES_TABLE.'
|
FROM '.IMAGES_TABLE;
|
||||||
|
|
||||||
|
if (in_array('md5sum', $duplicates_on_fields))
|
||||||
|
{
|
||||||
|
$query.= '
|
||||||
|
WHERE md5sum IS NOT NULL
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$query.= '
|
||||||
GROUP BY '.implode(',', $duplicates_on_fields).'
|
GROUP BY '.implode(',', $duplicates_on_fields).'
|
||||||
HAVING COUNT(*) > 1
|
HAVING COUNT(*) > 1
|
||||||
;';
|
;';
|
||||||
@@ -419,6 +433,7 @@ SELECT
|
|||||||
|
|
||||||
foreach ($array_of_ids_string as $ids_string)
|
foreach ($array_of_ids_string as $ids_string)
|
||||||
{
|
{
|
||||||
|
$ids_string = rtrim($ids_string,',');
|
||||||
$ids = array_merge($ids, explode(',', $ids_string));
|
$ids = array_merge($ids, explode(',', $ids_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user