summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-04-09 08:40:15 -0700
committerBrion Vibber <brion@pobox.com>2010-04-09 08:40:15 -0700
commit1f8451f4aa9128e55d4b274faf7f0cd19d56e2b8 (patch)
tree3b3d27baa6a9fce818e858073a37ba7f88524718 /scripts
parent857db1fabe8dc1d4420abad74d574c536b120ad5 (diff)
parent2be04e2a631ea9f373386bed792e7233418e2ee2 (diff)
Merge branch 'testing' into 0.9.x
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/fixup_blocks.php76
-rwxr-xr-xscripts/install_cli.php217
-rw-r--r--scripts/settag.php9
-rwxr-xr-xscripts/strip_geo.php116
4 files changed, 416 insertions, 2 deletions
diff --git a/scripts/fixup_blocks.php b/scripts/fixup_blocks.php
new file mode 100755
index 000000000..6b0255e72
--- /dev/null
+++ b/scripts/fixup_blocks.php
@@ -0,0 +1,76 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010 StatusNet, Inc.
+ *
+ * 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/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+$longoptions = array('dry-run', 'start=', 'end=');
+
+$helptext = <<<END_OF_HELP
+fixup_blocks.php [options]
+Finds profile blocks where the unsubscription didn't complete,
+and removes the offending subscriptions.
+
+ --dry-run look but don't touch
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+/**
+ * Fetch subscriptions that should be disallowed by a block
+ */
+function get_blocked_subs()
+{
+ $query = "SELECT subscription.* " .
+ "FROM subscription " .
+ "INNER JOIN profile_block " .
+ "ON blocker=subscribed " .
+ "AND blocked=subscriber";
+ $subscription = new Subscription();
+ $subscription->query($query);
+ return $subscription;
+}
+
+
+$dry = have_option('dry-run');
+$sub = get_blocked_subs();
+$count = $sub->N;
+while ($sub->fetch()) {
+ $subber = Profile::staticGet('id', $sub->subscriber);
+ $subbed = Profile::staticGet('id', $sub->subscribed);
+ if (!$subber || !$subbed) {
+ print "Bogus entry! $sub->subscriber subbed to $sub->subscribed\n";
+ continue;
+ }
+ print "$subber->nickname ($subber->id) blocked but subbed to $subbed->nickname ($subbed->id)";
+ if ($dry) {
+ print ": skipping; dry run\n";
+ } else {
+ Subscription::cancel($subber, $subbed);
+ print ": removed\n";
+ }
+}
+print "\n";
+
+if ($dry && $count > 0) {
+ print "Be sure to run without --dry-run to remove the bad entries!\n";
+} else {
+ print "done.\n";
+}
diff --git a/scripts/install_cli.php b/scripts/install_cli.php
new file mode 100755
index 000000000..61fbe18ef
--- /dev/null
+++ b/scripts/install_cli.php
@@ -0,0 +1,217 @@
+#!/usr/bin/env php
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * 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/>.
+ *
+ * @category Installation
+ * @package Installation
+ *
+ * @author Brion Vibber <brion@status.net>
+ * @license GNU Affero General Public License http://www.gnu.org/licenses/
+ * @version 0.9.x
+ * @link http://status.net
+ */
+
+if (php_sapi_name() !== 'cli') {
+ exit(1);
+}
+
+define('INSTALLDIR', dirname(dirname(__FILE__)));
+set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
+
+require_once INSTALLDIR . '/lib/installer.php';
+require_once 'Console/Getopt.php';
+
+class CliInstaller extends Installer
+{
+ public $verbose = true;
+
+ /**
+ * Go for it!
+ * @return boolean success
+ */
+ function main()
+ {
+ if (!$this->checkPrereqs()) {
+ return false;
+ }
+ if ($this->prepare()) {
+ return $this->handle();
+ } else {
+ $this->showHelp();
+ return false;
+ }
+ }
+
+ /**
+ * Get our input parameters...
+ * @return boolean success
+ */
+ function prepare()
+ {
+ $shortoptions = 'qvh';
+ $longoptions = array('quiet', 'verbose', 'help', 'skip-config');
+ $map = array(
+ '-s' => 'server',
+ '--server' => 'server',
+ '-p' => 'path',
+ '--path' => 'path',
+ '--sitename' => 'sitename',
+ '--fancy' => 'fancy',
+
+ '--dbtype' => 'dbtype',
+ '--host' => 'host',
+ '--database' => 'database',
+ '--username' => 'username',
+ '--password' => 'password',
+
+ '--admin-nick' => 'adminNick',
+ '--admin-pass' => 'adminPass',
+ '--admin-email' => 'adminEmail',
+ '--admin-updates' => 'adminUpdates'
+ );
+ foreach ($map as $arg => $target) {
+ if (substr($arg, 0, 2) == '--') {
+ $longoptions[] = substr($arg, 2) . '=';
+ } else {
+ $shortoptions .= substr($arg, 1) . ':';
+ }
+ }
+
+ $parser = new Console_Getopt();
+ $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
+ if (PEAR::isError($result)) {
+ $this->warning($result->getMessage());
+ return false;
+ }
+ list($options, $args) = $result;
+
+ // defaults
+ $this->dbtype = 'mysql';
+ $this->adminUpdates = true;
+ $this->verbose = true;
+
+ foreach ($options as $option) {
+ $arg = $option[0];
+ if (isset($map[$arg])) {
+ $var = $map[$arg];
+ $this->$var = $option[1];
+ if ($var == 'adminUpdates' || $arg == '--fancy') {
+ $this->$var = ($option[1] != 'false') && ($option[1] != 'no');
+ }
+ } else if ($arg == '--skip-config') {
+ $this->skipConfig = true;
+ } else if ($arg == 'q' || $arg == '--quiet') {
+ $this->verbose = false;
+ } else if ($arg == 'v' || $arg == '--verbose') {
+ $this->verbose = true;
+ } else if ($arg == 'h' || $arg == '--help') {
+ // will go back to show help
+ return false;
+ }
+ }
+
+ $fail = false;
+ if (empty($this->server)) {
+ $this->updateStatus("You must specify a web server for the site.", true);
+ // path is optional though
+ $fail = true;
+ }
+
+ if (!$this->validateDb()) {
+ $fail = true;
+ }
+
+ if (!$this->validateAdmin()) {
+ $fail = true;
+ }
+
+ return !$fail;
+ }
+
+ function handle()
+ {
+ return $this->doInstall();
+ }
+
+ function showHelp()
+ {
+ echo <<<END_HELP
+install_cli.php - StatusNet command-line installer
+
+ -s --server=<name> Use <name> as server name (required)
+ -p --path=<path> Use <path> as path name
+ --sitename User-friendly site name (required)
+ --fancy Whether to use fancy URLs (default no)
+
+ --dbtype 'mysql' (default) or 'pgsql'
+ --host Database hostname (required)
+ --database Database/schema name (required)
+ --username Database username (required)
+ --password Database password (required)
+
+ --admin-nick Administrator nickname (required)
+ --admin-pass Initial password for admin user (required)
+ --admin-email Initial email address for admin user
+ --admin-updates 'yes' (default) or 'no', whether to subscribe
+ admin to update@status.net (default yes)
+
+ --skip-config Don't write a config.php -- use with caution,
+ requires a global configuration file.
+
+ General options:
+
+ -q --quiet Quiet (little output)
+ -v --verbose Verbose (lots of output)
+ -h --help Show this message and quit.
+
+END_HELP;
+ }
+
+ function warning($message, $submessage='')
+ {
+ print $this->html2text($message) . "\n";
+ if ($submessage != '') {
+ print " " . $this->html2text($submessage) . "\n";
+ }
+ print "\n";
+ }
+
+ function updateStatus($status, $error=false)
+ {
+ if ($this->verbose || $error) {
+ if ($error) {
+ print "ERROR: ";
+ }
+ print $this->html2text($status);
+ print "\n";
+ }
+ }
+
+ private function html2text($html)
+ {
+ // break out any links for text legibility
+ $breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
+ '\2 &lt;\1&gt;',
+ $html);
+ return html_entity_decode(strip_tags($breakout));
+ }
+}
+
+$installer = new CliInstaller();
+$ok = $installer->main();
+exit($ok ? 0 : 1);
diff --git a/scripts/settag.php b/scripts/settag.php
index e91d5eb50..d1b06ff10 100644
--- a/scripts/settag.php
+++ b/scripts/settag.php
@@ -33,13 +33,12 @@ END_OF_SETTAG_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
-if (count($args) != 2) {
+if (count($args) < 1) {
show_help();
exit(1);
}
$nickname = $args[0];
-$tag = strtolower($args[1]);
$sn = Status_network::memGet('nickname', $nickname);
@@ -50,6 +49,12 @@ if (empty($sn)) {
$tags = $sn->getTags();
+if (count($args) == 1) {
+ print(implode(', ', $tags) . "\n");
+ exit(0);
+}
+$tag = $args[1];
+
$i = array_search($tag, $tags);
if ($i !== false) {
diff --git a/scripts/strip_geo.php b/scripts/strip_geo.php
new file mode 100755
index 000000000..010fb31f5
--- /dev/null
+++ b/scripts/strip_geo.php
@@ -0,0 +1,116 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2009-2010, StatusNet, Inc.
+ *
+ * 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/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+$shortoptions = 'i::n::y';
+$longoptions = array('id=', 'nickname=', 'yes', 'dry-run');
+
+$helptext = <<<END_OF_HELP
+strip_geo.php [options]
+Removes geolocation info from the given user's notices.
+
+ -i --id ID of the user (may be a remote profile)
+ -n --nickname nickname of the user
+ -y --yes do not wait for confirmation
+ --dry-run list affected notices without deleting
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (have_option('i', 'id')) {
+ $id = get_option_value('i', 'id');
+ $profile = Profile::staticGet('id', $id);
+ if (empty($profile)) {
+ print "Can't find local or remote profile with ID $id\n";
+ exit(1);
+ }
+} else if (have_option('n', 'nickname')) {
+ $nickname = get_option_value('n', 'nickname');
+ $user = User::staticGet('nickname', $nickname);
+ if (empty($user)) {
+ print "Can't find local user with nickname '$nickname'\n";
+ exit(1);
+ }
+ $profile = $user->getProfile();
+} else {
+ print "You must provide either an ID or a nickname.\n\n";
+ show_help();
+ exit(1);
+}
+
+if (!have_option('y', 'yes') && !have_option('--dry-run')) {
+ print "About to PERMANENTLY remove geolocation data from user '{$profile->nickname}' ({$profile->id})'s notices. Are you sure? [y/N] ";
+ $response = fgets(STDIN);
+ if (strtolower(trim($response)) != 'y') {
+ print "Aborting.\n";
+ exit(0);
+ }
+}
+
+// @fixme for a very prolific poster this could be too many.
+print "Finding notices with geolocation data...";
+$notice = new Notice();
+$notice->profile_id = $profile->id;
+$notice->whereAdd("lat != ''");
+$notice->find();
+
+if ($notice->N) {
+ print " $notice->N found.\n";
+ while ($notice->fetch()) {
+ print "notice id $notice->id ";
+ if (have_option('v') || have_option('--verbose')) {
+ print "({$notice->lat},{$notice->lon}) ";
+ if ($notice->location_ns) {
+ print "ns {$notice->location_ns} id {$notice->location_id} ";
+ }
+ }
+ if (have_option('--dry-run')) {
+ // sucka
+ echo "(skipped)";
+ } else {
+ // note: setting fields to null and calling update() doesn't save the nulled fields
+ $orig = clone($notice);
+ $update = clone($notice);
+
+ // In theory we could hit a chunk of notices at once in the UPDATE,
+ // but we're going to have to decache them individually anyway and
+ // it doesn't hurt to make sure we don't hold up replication with
+ // what might be a very slow single UPDATE.
+ $query = sprintf('UPDATE notice ' .
+ 'SET lat=NULL,lon=NULL,location_ns=NULL,location_id=NULL ' .
+ 'WHERE id=%d', $notice->id);
+ $ok = $update->query($query);
+ if ($ok) {
+ // And now we decache him manually, as query() doesn't know what we're doing...
+ $orig->blow();
+ echo "(removed)";
+ } else {
+ echo "(failed?)";
+ }
+ }
+ print "\n";
+ }
+} else {
+ print " none found.\n";
+}
+
+print "DONE.\n";