aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-31 10:33:20 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-31 10:33:20 +0000
commit4669a3e824915d3c8418de1f6b17a6811441c617 (patch)
treeb9c884cdce6a4e2e34e52f44f5d7e643d855ab23
parentf72baa4731cb98f42a21fe9737254c706e7ebcbf (diff)
downloadelgg-4669a3e824915d3c8418de1f6b17a6811441c617.tar.gz
elgg-4669a3e824915d3c8418de1f6b17a6811441c617.tar.bz2
Closes #493: Moved database queries out of module and in to core in line with best practice.
git-svn-id: https://code.elgg.org/elgg/trunk@2369 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/database.php12
-rw-r--r--engine/lib/metastrings.php21
-rw-r--r--mod/garbagecollector/start.php14
3 files changed, 35 insertions, 12 deletions
diff --git a/engine/lib/database.php b/engine/lib/database.php
index c46d6023f..e1f007399 100644
--- a/engine/lib/database.php
+++ b/engine/lib/database.php
@@ -368,7 +368,17 @@
return false;
return $tables;
- }
+ }
+
+ /**
+ * Run an optimize query on a mysql tables. Useful for executing after major data changes.
+ *
+ */
+ function optimize_table($table)
+ {
+ $table = sanitise_string($table);
+ return update_data("optimize table $table");
+ }
/**
* Get the last database error for a particular database link
diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php
index b6e3b431d..786e343ce 100644
--- a/engine/lib/metastrings.php
+++ b/engine/lib/metastrings.php
@@ -115,4 +115,25 @@
return $result;
}
+ /**
+ * Delete any orphaned entries in metastrings. This is run by the garbage collector.
+ *
+ */
+ function delete_orphaned_metastrings()
+ {
+ global $CONFIG;
+
+ $query = "
+ DELETE
+ from {$CONFIG->dbprefix}metastrings where
+ (
+ (id not in (select name_id from {$CONFIG->dbprefix}metadata)) AND
+ (id not in (select value_id from {$CONFIG->dbprefix}metadata)) AND
+ (id not in (select name_id from {$CONFIG->dbprefix}annotations)) AND
+ (id not in (select value_id from {$CONFIG->dbprefix}annotations))
+ )";
+
+ return delete_data($query);
+ }
+
?> \ No newline at end of file
diff --git a/mod/garbagecollector/start.php b/mod/garbagecollector/start.php
index f92248cc0..a3daf250e 100644
--- a/mod/garbagecollector/start.php
+++ b/mod/garbagecollector/start.php
@@ -41,16 +41,8 @@
// Garbage collect metastrings
$resulttext .= elgg_echo('garbagecollector:gc:metastrings');
- $query = "
- DELETE
- from {$CONFIG->dbprefix}metastrings where
- (
- (id not in (select name_id from {$CONFIG->dbprefix}metadata)) AND
- (id not in (select value_id from {$CONFIG->dbprefix}metadata)) AND
- (id not in (select name_id from {$CONFIG->dbprefix}annotations)) AND
- (id not in (select value_id from {$CONFIG->dbprefix}annotations))
- )";
- if (delete_data($query)!==false) {
+
+ if (delete_orphaned_metastrings()!==false) {
$resulttext .= elgg_echo('garbagecollector:ok');
} else
$resulttext .= elgg_echo('garbagecollector:error');
@@ -62,7 +54,7 @@
foreach ($tables as $table) {
$resulttext .= sprintf(elgg_echo('garbagecollector:optimize'), $table);
- if (update_data("optimize table $table")!==false)
+ if (optimize_table($table)!==false)
$resulttext .= elgg_echo('garbagecollector:ok');
else
$resulttext .= elgg_echo('garbagecollector:error');