Committer: gprochaev
LJSUP-7716. Add 3.6. Admin/stats toolsA trunk/cgi-bin/LJ/Console/Command/SetOwner.pm A trunk/htdocs/admin/comm/ A trunk/htdocs/admin/comm/elections.bml
Added: trunk/cgi-bin/LJ/Console/Command/SetOwner.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/SetOwner.pm (rev 0) +++ trunk/cgi-bin/LJ/Console/Command/SetOwner.pm 2011-01-18 06:00:28 UTC (rev 18038) @@ -0,0 +1,58 @@ +package LJ::Console::Command::SetOwner; + +use strict; +use base qw(LJ::Console::Command); +use Carp qw(croak); + +sub cmd { "set_owner" } + +sub desc { "Set user as supermaintainer for community." } + +sub args_desc { [ + 'community' => "The community for which to set supermaintainer", + 'username' => "The username of the account to set as supermaintainer", + 'reason' => "Why you're setting the account as supermaintainer.", + ] } + +sub usage { '<community> <username> <reason>' } + +sub can_execute { + my $remote = LJ::get_remote(); + return LJ::check_priv($remote, "siteadmin", "elections"); +} + +sub execute { + my ($self, $comm, $user, $reason, @args) = @_; + + return $self->error("This command takes two arguments. Consult the reference.") + unless $comm && $user && scalar(@args) == 0; + + my $remote = LJ::get_remote(); + my $c = LJ::load_user($comm); + my $u = LJ::load_user($user); + + unless ($u) { + $self->error("Unable to load '$user'"); + next; + } + + unless ($c) { + $self->error("Unable to load '$comm'"); + next; + } + + #LJ::statushistory_add($u, $remote, "suspend", $reason); + my $s_maints = LJ::load_rel_user($c->{userid}, 'S'); + my $s_maint_u = @$s_maints ? LJ::load_userid($s_maints->[0]) : undef; + if ($s_maint_u) { + LJ::clear_rel($c->{userid}, $s_maint_u->{userid}, 'S'); + } + + LJ::set_rel($c->{userid}, $u->{userid}, 'S'); + + $self->print("User '$user' setted as supermaintainer for '$comm'."); + + return 1; +} + +1; Added: trunk/htdocs/admin/comm/elections.bml =================================================================== --- trunk/htdocs/admin/comm/elections.bml (rev 0) +++ trunk/htdocs/admin/comm/elections.bml 2011-01-18 06:00:28 UTC (rev 18038) @@ -0,0 +1,117 @@ +<?page +body<= +<?_code +{ + use strict; + use vars qw(%GET %POST $title $headextra @errors @warnings); + + use POSIX qw/strftime/; + + my $remote = LJ::get_remote(); + + return "<?needlogin?>" + unless $remote; + + return "You are not allowed to view this page" + unless LJ::check_priv($remote, 'siteadmin', 'elections') || $LJ::IS_DEV_SERVER; + + my $ret = ""; + $title = 'Supermaintainer elections'; + + $ret .= "<form method='POST'>\n"; + $ret .= LJ::form_auth(); + + $ret .= "Find election: "; + my $comm_name = $POST{'comm_name'} ? $POST{'comm_name'} : ''; + $ret .= "<input type='text' name='comm_name' value='$comm_name'>"; + + $ret .= " " . LJ::html_submit('search', 'Search') . "</p>"; + + $ret .= "</form>"; + + if (LJ::did_post()) { + push @errors, "Invalid form submission" unless LJ::check_form_auth(); + + { + my $comm = LJ::load_user($POST{'comm_name'}); + unless ($comm) { + push @errors, $POST{'comm_name'}." user is not exist"; + next; + } + + my $poll_id = $comm->prop('election_poll_id'); + unless ($poll_id) { + push @errors, "No election poll for ".LJ::ljuser($comm->user)." community"; + next; + } + + my $poll = LJ::Poll->new ($poll_id); + + unless ($poll->is_closed) { + my $create = LJ::TimeUtil->mysqldate_to_time($poll->prop('createdate')); + my $delta = time - $create; + my $create_time = strftime "%B %e %Y", localtime ($create); + my $close_time = strftime "%B %e %Y", localtime (int(($delta / (21 * 86400)) + 1) * (21 * 86400) + $create); + + my @qs = $poll->questions; + my @items = $qs[0]->items; + + $ret .= "Active election:<br/>"; + $ret .= "Election period: from $create_time to $close_time<br/><br/>"; + + my $maintainers = LJ::load_rel_user($comm->{userid}, 'A'); + my $users = LJ::load_userids(@$maintainers); + my @alive_mainteiners; + foreach my $u (values %$users) { + if ($u && $u->is_visible && $u->can_manage($comm) && $u->check_activity(90)) { + push @alive_mainteiners, $u; + } + } + + $ret .= "Maintainers (participants of the election): " . @alive_mainteiners . "<br/>"; + + my $sth; + my $dbr = LJ::get_db_reader(); + if ($poll->is_clustered) { + $sth = $poll->journal->prepare("SELECT value, userid FROM pollresult2 WHERE pollid=? AND pollqid=? AND journalid=?"); + $sth->execute($poll->pollid, 1, $poll->journalid); + } else { + $sth = $dbr->prepare("SELECT value, userid FROM pollresult WHERE pollid=? AND pollqid=?"); + $sth->execute($poll->pollid, 1); + } + + my %result = (); + my %result_users = (); + my $i = 0; + while (my @row = $sth->fetchrow_array) { + $result{$row[0]}++; + $result_users{$row[1]} = $row[0]; + $i++; + } + + $ret .= "Maintainers (voted already): " . $i . "<br/>"; + + $ret .= "<br/>Current state of election: <br/>"; + foreach my $u (values %$users) { + my $vote_for = $items[$result_users{$u->userid} - 1]->{item}; + LJ::Poll->clean_poll(\$vote_for); + $ret .= LJ::ljuser($u) . " - " . ( $result_users{$u->userid} ? " voted for " . $vote_for : " not voted yet ") . "<br/>"; + } + + $ret .= ""; + + } + + next if @errors; + } + } + + return "<body>$ret</body>"; +} +_code?> +<=body +title=><?_code return $title; _code?> +head<= +<?_code return $headextra; _code?> +<=head +page?>