aboutsummaryrefslogtreecommitdiff
path: root/mod/garbagecollector
diff options
context:
space:
mode:
Diffstat (limited to 'mod/garbagecollector')
-rw-r--r--mod/garbagecollector/languages/en.php25
-rw-r--r--mod/garbagecollector/manifest.xml17
-rw-r--r--mod/garbagecollector/start.php63
-rw-r--r--mod/garbagecollector/views/default/plugins/garbagecollector/settings.php28
4 files changed, 133 insertions, 0 deletions
diff --git a/mod/garbagecollector/languages/en.php b/mod/garbagecollector/languages/en.php
new file mode 100644
index 000000000..b32670a0c
--- /dev/null
+++ b/mod/garbagecollector/languages/en.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Elgg garbage collector language pack.
+ *
+ * @package ElggGarbageCollector
+ */
+
+$english = array(
+ '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..5aafebf38
--- /dev/null
+++ b/mod/garbagecollector/manifest.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Garbage Collector</name>
+ <author>Core developers</author>
+ <version>1.5</version>
+ <category>bundled</category>
+ <category>admin</category>
+ <description>Perform some database cleanup tasks</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</copyright>
+ <license>GNU General Public License version 2</license>
+ <requires>
+ <type>elgg_release</type>
+ <version>1.8</version>
+ </requires>
+ <activate_on_install>true</activate_on_install>
+</plugin_manifest>
diff --git a/mod/garbagecollector/start.php b/mod/garbagecollector/start.php
new file mode 100644
index 000000000..c7bd20053
--- /dev/null
+++ b/mod/garbagecollector/start.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Elgg garbage collector.
+ *
+ * @package ElggGarbageCollector
+ */
+
+elgg_register_event_handler('init', 'system', 'garbagecollector_init');
+
+function garbagecollector_init() {
+ $period = elgg_get_plugin_setting('period', 'garbagecollector');
+ switch ($period) {
+ case 'weekly':
+ case 'monthly':
+ case 'yearly':
+ break;
+ default:
+ $period = 'monthly';
+ }
+
+ // Register cron hook
+ elgg_register_plugin_hook_handler('cron', $period, 'garbagecollector_cron');
+}
+
+/**
+ * Cron job
+ */
+function garbagecollector_cron($hook, $entity_type, $returnvalue, $params) {
+
+ echo elgg_echo('garbagecollector');
+
+ // Garbage collect metastrings
+ echo elgg_echo('garbagecollector:gc:metastrings');
+
+ if (delete_orphaned_metastrings() !== false) {
+ echo elgg_echo('garbagecollector:ok');
+ } else {
+ echo elgg_echo('garbagecollector:error');
+ }
+
+ echo "\n";
+
+ // Now, because we are nice, trigger a plugin hook to let other plugins do some GC
+ $rv = true;
+ $period = elgg_get_plugin_setting('period','garbagecollector');
+ elgg_trigger_plugin_hook('gc', 'system', array('period' => $period));
+
+ // Now we optimize all tables
+ $tables = get_db_tables();
+ foreach ($tables as $table) {
+ echo elgg_echo('garbagecollector:optimize', array($table));
+
+ if (optimize_table($table) !== false) {
+ echo elgg_echo('garbagecollector:ok');
+ } else {
+ echo elgg_echo('garbagecollector:error');
+ }
+
+ echo "\n";
+ }
+
+ echo elgg_echo('garbagecollector:done');
+}
diff --git a/mod/garbagecollector/views/default/plugins/garbagecollector/settings.php b/mod/garbagecollector/views/default/plugins/garbagecollector/settings.php
new file mode 100644
index 000000000..3ade780f9
--- /dev/null
+++ b/mod/garbagecollector/views/default/plugins/garbagecollector/settings.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Elgg garbage collector plugin settings.
+ *
+ * @package ElggGarbageCollector
+ */
+
+$period = $vars['entity']->period;
+if (!$period) {
+ $period = 'monthly';
+}
+
+?>
+<div>
+ <?php echo elgg_echo('garbagecollector:period'); ?>
+
+ <?php
+ echo elgg_view('input/dropdown', array(
+ 'name' => 'params[period]',
+ 'options_values' => array(
+ 'weekly' => elgg_echo('garbagecollector:weekly'),
+ 'monthly' => elgg_echo('garbagecollector:monthly'),
+ 'yearly' => elgg_echo('garbagecollector:yearly'),
+ ),
+ 'value' => $period
+ ));
+ ?>
+</div>