aboutsummaryrefslogtreecommitdiff
path: root/mod/garbagecollector/start.php
blob: e3f8c030fecaa1ebb4b339445db4174045827c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
	/**
	 * Elgg garbage collector.
	 *
	 * @package ElggGarbageCollector
	 */

	/**
	 * 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;

		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 = get_plugin_setting('period','garbagecollector');
		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');
	}

	// Initialise plugin
	register_elgg_event_handler('init','system','garbagecollector_init');
?>