aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-28 17:50:36 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-28 17:50:36 +0000
commit474144e6ba90c5cb5bb99ad03c81aba71ccfa8c1 (patch)
tree2b7a9a4c2227cf70033722e74b829810b1ab59d5 /mod
parent91f01f82dd59405598324501c7932bffde234979 (diff)
downloadelgg-474144e6ba90c5cb5bb99ad03c81aba71ccfa8c1.tar.gz
elgg-474144e6ba90c5cb5bb99ad03c81aba71ccfa8c1.tar.bz2
Introducing the Elgg garbage collector.
git-svn-id: https://code.elgg.org/elgg/trunk@2336 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod')
-rw-r--r--mod/garbagecollector/languages/en.php36
-rw-r--r--mod/garbagecollector/manifest.xml9
-rw-r--r--mod/garbagecollector/start.php80
-rw-r--r--mod/garbagecollector/views/default/settings/garbagecollector/edit.php20
4 files changed, 145 insertions, 0 deletions
diff --git a/mod/garbagecollector/languages/en.php b/mod/garbagecollector/languages/en.php
new file mode 100644
index 000000000..21d5288a6
--- /dev/null
+++ b/mod/garbagecollector/languages/en.php
@@ -0,0 +1,36 @@
+<?php
+ /**
+ * Elgg garbage collector language pack.
+ *
+ * @package ElggGarbageCollector
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ $english = array(
+
+ /**
+ * Menu items and titles
+ */
+
+ 'garbagecollector:period' => 'How often should the Elgg garbage collector run?',
+
+ 'garbagecollector:weekly' => 'Once a week',
+ 'garbagecollector:monthly' => 'Once a month',
+ 'garbagecollector:yearly' => 'Once a year',
+
+ 'garbagecollector' => "GARBAGE COLLECTOR\n",
+ 'garbagecollector:done' => "DONE\n",
+ 'garbagecollector:optimize' => "Optimizing %s ",
+
+ 'garbagecollector:error' => "ERROR",
+ 'garbagecollector:ok' => "OK",
+
+ 'garbagecollector:gc:metastrings' => 'Cleaning up unlinked metastrings: ',
+
+ );
+
+ add_translation("en",$english);
+?> \ No newline at end of file
diff --git a/mod/garbagecollector/manifest.xml b/mod/garbagecollector/manifest.xml
new file mode 100644
index 000000000..5533bc537
--- /dev/null
+++ b/mod/garbagecollector/manifest.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest>
+ <field key="author" value="Marcus Povey" />
+ <field key="version" value="1.0" />
+ <field key="description" value="Perform some database cleanup tasks" />
+ <field key="website" value="http://www.elgg.org/" />
+ <field key="copyright" value="(C) Curverider 2008" />
+ <field key="licence" value="GNU Public License version 2" />
+</plugin_manifest> \ No newline at end of file
diff --git a/mod/garbagecollector/start.php b/mod/garbagecollector/start.php
new file mode 100644
index 000000000..f92248cc0
--- /dev/null
+++ b/mod/garbagecollector/start.php
@@ -0,0 +1,80 @@
+<?php
+ /**
+ * Elgg garbage collector.
+ *
+ * @package ElggGarbageCollector
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ /**
+ * Initialise the plugin.
+ *
+ */
+ function garbagecollector_init()
+ {
+ $period = get_plugin_setting('period','garbagecollector');
+ switch ($period)
+ {
+ case 'weekly':
+ case 'monthly' :
+ case 'yearly' :
+ break;
+ default: $period = 'monthly';
+ }
+
+ // Register cron hook
+ register_plugin_hook('cron', $period, 'garbagecollector_cron');
+ }
+
+ /**
+ * Cron job
+ *
+ */
+ function garbagecollector_cron($hook, $entity_type, $returnvalue, $params)
+ {
+ global $CONFIG;
+
+ $resulttext = elgg_echo('garbagecollector');
+
+ // 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) {
+ $resulttext .= elgg_echo('garbagecollector:ok');
+ } else
+ $resulttext .= elgg_echo('garbagecollector:error');
+
+ $resulttext .= "\n";
+
+ // Now we optimize all tables
+ $tables = get_db_tables();
+ foreach ($tables as $table) {
+ $resulttext .= sprintf(elgg_echo('garbagecollector:optimize'), $table);
+
+ if (update_data("optimize table $table")!==false)
+ $resulttext .= elgg_echo('garbagecollector:ok');
+ else
+ $resulttext .= elgg_echo('garbagecollector:error');
+
+ $resulttext .= "\n";
+ }
+
+ $resulttext .= elgg_echo('garbagecollector:done');
+
+ return $returnvalue . $resulttext;
+ }
+
+ // Initialise plugin
+ register_elgg_event_handler('init','system','garbagecollector_init');
+?> \ No newline at end of file
diff --git a/mod/garbagecollector/views/default/settings/garbagecollector/edit.php b/mod/garbagecollector/views/default/settings/garbagecollector/edit.php
new file mode 100644
index 000000000..19ae3d245
--- /dev/null
+++ b/mod/garbagecollector/views/default/settings/garbagecollector/edit.php
@@ -0,0 +1,20 @@
+<?php
+ $period = $vars['entity']->period;
+ if (!$period) $period = 'monthly';
+
+?>
+<p>
+ <?php echo elgg_echo('garbagecollector:period'); ?>
+
+ <?php
+ echo elgg_view('input/pulldown', array(
+ 'internalname' => 'params[period]',
+ 'options_values' => array(
+ 'weekly' => elgg_echo('garbagecollector:weekly'),
+ 'monthly' => elgg_echo('garbagecollector:monthly'),
+ 'yearly' => elgg_echo('garbagecollector:yearly'),
+ ),
+ 'value' => $period
+ ));
+ ?>
+</p>