mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
bug 2825: add maintenance action to clean the database and avoid integrity errors
git-svn-id: http://piwigo.org/svn/trunk@20544 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -484,6 +484,34 @@ SELECT DISTINCT id
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check and repair images integrity
|
||||
*
|
||||
* TODO see delete_elements function to check all linked tables
|
||||
*/
|
||||
function images_integrity()
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
image_id
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
LEFT JOIN '.IMAGES_TABLE.' ON id = image_id
|
||||
WHERE id IS NULL
|
||||
;';
|
||||
$result = pwg_query($query);
|
||||
$orphan_image_ids = array_from_query($query, 'image_id');
|
||||
|
||||
if (count($orphan_image_ids) > 0)
|
||||
{
|
||||
$query = '
|
||||
DELETE
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE image_id IN ('.implode(',', $orphan_image_ids).')
|
||||
;';
|
||||
pwg_query($query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array containing sub-directories which can be a category,
|
||||
* recursive by default
|
||||
|
||||
Reference in New Issue
Block a user