aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2013-02-04 11:28:03 +0000
committerplegall <plg@piwigo.org>2013-02-04 11:28:03 +0000
commitb267aea0e2821cd411530511bbb2698bc5e9b121 (patch)
tree2e952ed810d4219abd9f14c9111196d796e28f25 /admin/include
parentb39b4e0f398c205676004352bb1c7316f809bea2 (diff)
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
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index c1a3db22c..03bce26cc 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -485,6 +485,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
*