2009-06-22 23:29:24 +01:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-26 08:33:43 +01:00
|
|
|
* StatusNet - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
2009-06-22 23:29:24 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// -*- mode: php -*-
|
|
|
|
|
|
|
|
# Abort if called from a web server
|
|
|
|
|
|
|
|
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
|
|
|
print "This script must be run from the command line\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2009-08-26 08:33:43 +01:00
|
|
|
define('STATUSNET', true);
|
2009-10-13 18:34:28 +01:00
|
|
|
define('LACONICA', true); // compatibility
|
2009-06-22 23:29:24 +01:00
|
|
|
|
|
|
|
// Set various flags so we don't time out on long-running processes
|
|
|
|
|
|
|
|
ini_set("max_execution_time", "0");
|
|
|
|
ini_set("max_input_time", "0");
|
|
|
|
set_time_limit(0);
|
|
|
|
mb_internal_encoding('UTF-8');
|
|
|
|
|
|
|
|
// Add extlib to our path so we can get Console_Getopt
|
|
|
|
|
|
|
|
$_extra_path = array(INSTALLDIR.'/extlib/');
|
|
|
|
|
|
|
|
set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path());
|
|
|
|
|
|
|
|
require_once 'Console/Getopt.php';
|
|
|
|
|
|
|
|
// Note: $shortoptions and $longoptions should be pre-defined!
|
|
|
|
|
|
|
|
$_default_shortoptions = 'qvhc:s:p:';
|
|
|
|
|
|
|
|
$_default_longoptions = array('quiet', 'verbose', 'help', 'conf=', 'server=', 'path=');
|
|
|
|
|
|
|
|
if (isset($shortoptions)) {
|
|
|
|
$shortoptions .= $_default_shortoptions;
|
|
|
|
} else {
|
|
|
|
$shortoptions = $_default_shortoptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($longoptions)) {
|
|
|
|
$longoptions = array_merge($longoptions, $_default_longoptions);
|
|
|
|
} else {
|
|
|
|
$longoptions = $_default_longoptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
$parser = new Console_Getopt();
|
|
|
|
|
2009-06-28 21:15:17 +01:00
|
|
|
$result = $parser->getopt($argv, $shortoptions, $longoptions);
|
|
|
|
|
|
|
|
if (PEAR::isError($result)) {
|
2009-06-28 21:55:19 +01:00
|
|
|
print $result->getMessage()."\n";
|
|
|
|
exit(1);
|
2009-06-28 21:15:17 +01:00
|
|
|
} else {
|
2009-06-28 21:55:19 +01:00
|
|
|
list($options, $args) = $result;
|
2009-06-28 21:15:17 +01:00
|
|
|
}
|
2009-06-22 23:29:24 +01:00
|
|
|
|
2009-06-23 00:00:05 +01:00
|
|
|
function show_help()
|
|
|
|
{
|
|
|
|
global $helptext;
|
|
|
|
|
|
|
|
$_default_help_text = <<<END_OF_DEFAULT
|
2009-06-28 21:55:19 +01:00
|
|
|
General options:
|
2009-06-23 00:00:05 +01:00
|
|
|
|
|
|
|
-q --quiet Quiet (little output)
|
|
|
|
-v --verbose Verbose (lots of output)
|
|
|
|
-c --conf=<filename> Use <filename> as config file
|
|
|
|
-s --server=<name> Use <name> as server name
|
|
|
|
-p --path=<path> Use <path> as path name
|
|
|
|
-h --help Show this message and quit.
|
|
|
|
|
|
|
|
END_OF_DEFAULT;
|
2009-06-28 21:55:19 +01:00
|
|
|
if (isset($helptext)) {
|
|
|
|
print $helptext;
|
|
|
|
}
|
|
|
|
print $_default_help_text;
|
|
|
|
exit(0);
|
2009-06-23 00:00:05 +01:00
|
|
|
}
|
|
|
|
|
2009-06-22 23:29:24 +01:00
|
|
|
foreach ($options as $option) {
|
|
|
|
|
|
|
|
switch ($option[0]) {
|
|
|
|
case '--server':
|
2009-06-23 00:44:29 +01:00
|
|
|
case 's':
|
2009-06-22 23:29:24 +01:00
|
|
|
$server = $option[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '--path':
|
2009-06-23 00:44:29 +01:00
|
|
|
case 'p':
|
2009-06-22 23:29:24 +01:00
|
|
|
$path = $option[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '--conf':
|
2009-06-23 00:44:29 +01:00
|
|
|
case 'c':
|
2009-06-22 23:29:24 +01:00
|
|
|
$conffile = $option[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '--help':
|
2009-06-23 00:44:29 +01:00
|
|
|
case 'h':
|
2009-06-23 00:00:05 +01:00
|
|
|
show_help();
|
2009-06-22 23:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/common.php';
|
2009-06-22 23:41:52 +01:00
|
|
|
|
|
|
|
set_error_handler('common_error_handler');
|
|
|
|
|
2010-04-20 11:06:54 +01:00
|
|
|
// Set up the language infrastructure so we can localize anything that
|
|
|
|
// needs to be sent out to users, such as mail notifications.
|
|
|
|
common_init_language();
|
|
|
|
|
2009-06-28 22:02:31 +01:00
|
|
|
function _make_matches($opt, $alt)
|
2009-06-22 23:41:52 +01:00
|
|
|
{
|
2009-06-28 21:55:19 +01:00
|
|
|
$matches = array();
|
|
|
|
|
|
|
|
if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
|
|
|
|
$matches[] = '--'.$opt;
|
|
|
|
} else {
|
|
|
|
$matches[] = $opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($alt)) {
|
|
|
|
if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
|
|
|
|
$matches[] = '--'.$alt;
|
|
|
|
} else {
|
|
|
|
$matches[] = $alt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:02:31 +01:00
|
|
|
return $matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
function have_option($opt, $alt=null)
|
|
|
|
{
|
|
|
|
global $options;
|
|
|
|
|
|
|
|
$matches = _make_matches($opt, $alt);
|
|
|
|
|
2009-06-28 21:55:19 +01:00
|
|
|
foreach ($options as $option) {
|
|
|
|
if (in_array($option[0], $matches)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-06-22 23:41:52 +01:00
|
|
|
}
|
|
|
|
|
2009-06-28 22:02:31 +01:00
|
|
|
function get_option_value($opt, $alt=null)
|
2009-06-22 23:41:52 +01:00
|
|
|
{
|
2009-06-28 21:55:19 +01:00
|
|
|
global $options;
|
|
|
|
|
2009-06-28 22:02:31 +01:00
|
|
|
$matches = _make_matches($opt, $alt);
|
2009-06-28 21:55:19 +01:00
|
|
|
|
|
|
|
foreach ($options as $option) {
|
|
|
|
if (in_array($option[0], $matches)) {
|
|
|
|
return $option[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2010-09-15 21:00:00 +01:00
|
|
|
|
2010-09-21 11:12:43 +01:00
|
|
|
class NoUserArgumentException extends Exception
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-15 21:00:00 +01:00
|
|
|
function getUser()
|
|
|
|
{
|
|
|
|
$user = null;
|
|
|
|
|
|
|
|
if (have_option('i', 'id')) {
|
|
|
|
$id = get_option_value('i', 'id');
|
|
|
|
$user = User::staticGet('id', $id);
|
|
|
|
if (empty($user)) {
|
|
|
|
throw new Exception("Can't find user with id '$id'.");
|
|
|
|
}
|
|
|
|
} else if (have_option('n', 'nickname')) {
|
|
|
|
$nickname = get_option_value('n', 'nickname');
|
|
|
|
$user = User::staticGet('nickname', $nickname);
|
|
|
|
if (empty($user)) {
|
|
|
|
throw new Exception("Can't find user with nickname '$nickname'");
|
|
|
|
}
|
|
|
|
} else {
|
2010-09-21 11:12:43 +01:00
|
|
|
throw new NoUserArgumentException("No user argument specified.");
|
2010-09-15 21:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
2010-09-21 19:06:39 +01:00
|
|
|
|
|
|
|
/** "Printf not quiet" */
|
|
|
|
|
|
|
|
function printfnq()
|
|
|
|
{
|
|
|
|
if (have_option('q', 'quiet')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cargs = func_num_args();
|
|
|
|
|
|
|
|
if ($cargs == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
$format = array_shift($args);
|
|
|
|
|
|
|
|
return vprintf($format, $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** "Print when verbose" */
|
|
|
|
|
|
|
|
function printfv()
|
|
|
|
{
|
|
|
|
if (!have_option('v', 'verbose')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cargs = func_num_args();
|
|
|
|
|
|
|
|
if ($cargs == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
$format = array_shift($args);
|
|
|
|
|
|
|
|
return vprintf($format, $args);
|
|
|
|
}
|