use parent qw(Bugzilla::Extension);
use Bugzilla::Constants;
+use Bugzilla::Error;
use Bugzilla::Extension::PhabBugz::Constants;
+use Bugzilla::Extension::PhabBugz::Util qw(request);
our $VERSION = '0.01';
$files->{$scriptname} = {perms => Bugzilla::Install::Filesystem::WS_EXECUTE};
}
+sub merge_users_before {
+ my ($self, $args) = @_;
+ my $old_id = $args->{old_id};
+ my $force = $args->{force};
+
+ return if $force;
+
+ my $result = request('bugzilla.account.search', {ids => [$old_id]});
+
+ foreach my $user (@{$result->{result}}) {
+ next if !$user->{phid};
+ ThrowUserError('phabricator_merge_user_abort',
+ {user => Bugzilla::User->new({id => $old_id, cache => 1})});
+ }
+}
+
__PACKAGE__->NAME;
[% title = "Unauthorized User" %]
You do not have permission to use this endpoint.
+[% ELSIF error == "phabricator_merge_user_abort" %]
+ [% title = "Cannot Merge User" %]
+ ERROR: Cannot merge old user [% user.login FILTER html %] since old user
+ has a linked account in Phabricator and the user will no longer match the
+ account in [% terms.Bugzilla %]. User needs to create new user in Phabricator
+ and link it to the newer account in [% terms.Bugzilla %]. Then file a [% terms.bug %]
+ for a phabricator admin to fix the accounts in phabricator.
+ Instructions: https://mana.mozilla.org/wiki/display/EW/Phabricator+-+Renaming+a+user+account.
+ Once this is complete, re-run merge-users.pl using --force switch.
+
[% END %]
my $dbh = Bugzilla->dbh;
# Display the help if called with --help or -?.
-my $help = 0;
-my $result = GetOptions("help|?" => \$help);
+# Force swicth can be used by extension code.
+my $help = 0;
+my $force = 0;
+my $result = GetOptions("help|?" => \$help, "force|f" => \$force);
pod2usage(0) if $help;
-
# Make sure accounts were specified on the command line and exist.
my $old = $ARGV[0] || die "You must specify an old user account.\n";
my $old_id;
# BMO - pre-work hook
Bugzilla::Hook::process('merge_users_before',
- {old_id => $old_id, new_id => $new_id});
+ {force => $force, old_id => $old_id, new_id => $new_id});
# Delete old records from logincookies and tokens tables.
$dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id);
# BMO - post-work hook
Bugzilla::Hook::process('merge_users_after',
- {old_id => $old_id, new_id => $new_id});
+ {force => $force, old_id => $old_id, new_id => $new_id});
# Commit the transaction
$dbh->bz_commit_transaction();