summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormark <mark>2010-06-11 04:14:23 +0000
committermark <mark>2010-06-11 04:14:23 +0000
commitb02e2d439440c8069879e87adaacc5d9c9147080 (patch)
tree5b314b47a617cb9f648fcd07f3ff8f40097dcfdf /bin
parent859931335736a18340a12fdbbd5c04085581ba4f (diff)
RT#8691: script to merge usernums
Diffstat (limited to 'bin')
-rwxr-xr-xbin/apache.export8
-rwxr-xr-xbin/merge-user64
2 files changed, 72 insertions, 0 deletions
diff --git a/bin/apache.export b/bin/apache.export
index 82eb6d6..124a3c5 100755
--- a/bin/apache.export
+++ b/bin/apache.export
@@ -47,6 +47,14 @@ foreach my $export ( @exports ) {
use vars qw($zone $username $dir $email $config);
$zone = $svc_www->domain_record->zone;
$config = $svc_www->config;
+ my $template;
+ my $cust_pkg = $svc_www->cust_svc->cust_pkg;
+ if ( $cust_pkg->getfield('susp') or $cust_pkg->getfield('cancel') ) {
+ $template = $export->option('template_inactive');
+ }
+ # Use the regular template if the pkg is live
+ # or if template_inactive doesn't exist.
+ $template ||= $export->option('template');
if ( $svc_www->svc_acct ) {
$username = $svc_www->svc_acct->username;
$dir = $svc_www->svc_acct->dir;
diff --git a/bin/merge-user b/bin/merge-user
new file mode 100755
index 0000000..4aca9a4
--- /dev/null
+++ b/bin/merge-user
@@ -0,0 +1,64 @@
+#!/usr/bin/perl -w
+
+use strict;
+use FS::UID qw(adminsuidsetup dbh);
+use FS::Schema;
+use FS::Record qw(qsearch qsearchs);
+
+my $DRY_RUN = 1;
+$FS::UID::AutoCommit = 0;
+
+my ($user, $from_usernum, $to_usernum, $go) = @ARGV;
+die usage() if not ($user and $from_usernum and $to_usernum);
+$DRY_RUN = 0 if $go eq 'go';
+
+my $dbh = adminsuidsetup($user);
+
+# Sanity checks.
+die "Can't merge a user to itself." if $from_usernum == $to_usernum;
+my $from_user = FS::access_user->by_key($from_usernum) or
+ die "Usernum '$from_usernum' not found.\n";
+my $to_user = FS::access_user->by_key($to_usernum) or
+ die "Usernum '$to_usernum' not found.\n";
+
+my $tables = FS::Schema::tables_hashref;
+foreach my $table (keys %$tables) {
+ next if $table =~ /^access/; # Don't try to merge these.
+ if( grep /^usernum$/, FS::Record::real_fields($table) ) {
+ foreach ($table, "h_$table") {
+ print "$_: ";
+ my $sql =
+ "UPDATE $_ SET usernum = $to_usernum WHERE usernum = $from_usernum";
+ #print $sql;
+ my $sth = $dbh->prepare($sql);
+ $sth->execute;
+ if($dbh->err) {
+ print $dbh->errstr."\n";
+ $dbh->rollback;
+ exit(1);
+ }
+ print $sth->rows, "\n";
+ }
+ }
+}
+
+if($DRY_RUN) {
+ warn "Dry run complete. Reverting all changes.\n";
+ $dbh->rollback;
+}
+else {
+# Warning: access_user->delete does not transactionize because of
+# htpasswd issues.
+ print "Deleting merged user.\n";
+ my $error = $from_user->delete;
+ die $error if $error;
+
+ warn "Committing changes.\n";
+ $dbh->commit;
+}
+exit(0);
+
+sub usage {
+ "Usage:\n merge-user admin_user from_usernum to_usernum [ 'go' ]\n
+ (Specify 'go' to actually apply changes.)\n\n";
+}