[commits] [Wiki] changed: DatabaseCleanup
Wiki Guest
wikiguest at horde.org
Wed May 15 14:02:31 UTC 2013
guest [62.178.78.156] Wed, 15 May 2013 14:02:31 +0000
Modified page: http://wiki.horde.org/DatabaseCleanup
New Revision: 10
Change log: manuel at mausz.at
@@ -309,8 +309,50 @@
}
$cli->message(' ' . $user . ' removed', 'cli.success');
}
+}
+
+$db->disconnect();
+
+?>
+</code>
+
+cleanup_rampage.php cron
+<code>
+#!/usr/bin/env php
+<?php
+
+require_once 'PEAR/Config.php';
+require_once PEAR_Config::singleton()
+ ->get('horde_dir', null, 'pear.horde.org') . '/lib/Application.php';
+Horde_Registry::appInit('horde', array('cli' => true, 'user_admin' => true));
+
+try
+{
+ $db =
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('horde',
'removeUser');
+}
+catch(Horde_Db_Exception $e)
+{
+ $cli->fatal('Unable to connect to the database: ' . $e);
+}
+
+try
+{
+ # delete objects that don't have any tags
+ # this will delete A LOT of objects that still exists
+ # but we've no other way to remove orphans and existing
+ # objects will be created again anyway
+ $db->execute(
+ 'DELETE FROM ro USING rampage_objects ro ' .
+ 'LEFT OUTER JOIN rampage_tagged rtd ' .
+ ' ON (ro.object_id = rtd.object_id) ' .
+ 'WHERE rtd.object_id IS NULL'
+ );
+}
+catch (Horde_Db_Exception $e)
+{
+ $cli->fatal('Unable to execute query: ' . $e);
}
$db->disconnect();
More information about the commits
mailing list