Added run_task script from horde-support
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 19 Feb 2010 06:59:00 +0000 (23:59 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 19 Feb 2010 06:59:00 +0000 (23:59 -0700)
horde/bin/run_task [new file with mode: 0755]

diff --git a/horde/bin/run_task b/horde/bin/run_task
new file mode 100755 (executable)
index 0000000..67e70e7
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Script to run a Horde_LoginTasks task and/or system task.
+ *
+ * Usage: run_task -a [app] -t [taskname] -u [username]
+ *   Taskname is the name of the file in the application's SystemTask/Task
+ *   directory - this script will automatically build the full class name.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ */
+
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true));
+
+$c = new Console_Getopt();
+$argv = $c->readPHPArgv();
+array_shift($argv);
+$options = $c->getopt2($argv, 'a:t:u:');
+if ($options instanceof PEAR_Error) {
+    $cli->fatal($options->getMessage());
+    exit;
+}
+
+foreach ($options[0] as $val) {
+    switch ($val[0]) {
+    case 'a':
+        $app = $val[1];
+        break;
+
+    case 't':
+        $taskname = $val[1];
+        break;
+
+    case 'u':
+        $username = $val[1];
+        break;
+    }
+}
+
+if (empty($app)) {
+    $cli->fatal('Missing argument to -a.');
+    exit;
+}
+
+if (empty($taskname)) {
+    $cli->fatal('Missing argument to -t.');
+    exit;
+}
+
+if (empty($username)) {
+    $cli->fatal('Missing argument to -u.');
+    exit;
+}
+
+Horde_Auth::setAuth($username, array());
+$registry->pushApp($app, array('check_perms' => false));
+
+$class = $app . '_LoginTasks_SystemTask_' . $taskname;
+if (!class_exists($class)) {
+    $class = $app . '_LoginTasks_Task_' . $taskname;
+    if (!class_exists($class)) {
+        $cli->fatal('Could not find task "' . $taskname . '".');
+    }
+}
+
+
+$ob = new $class();
+$ob->execute();
+
+$cli->message('Completed task.', 'cli.success');