sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[ljcom] r12413: LJSUP-12403: Console commands with comme...

Committer: vtroitsky
LJSUP-12403: Console commands with commercial promo
U   trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
Modified: trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm	2012-08-03 12:00:41 UTC (rev 12412)
+++ trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm	2012-08-03 12:15:55 UTC (rev 12413)
@@ -14,8 +14,8 @@
 }
 
 sub usage {
-    return '<cmd> <object> [region] [norefund] <reason>';
-}
+    return '<cmd> <object> [promo] [region] [norefund] <reason>';
+} 
 
 sub args_desc {
     return [
@@ -25,6 +25,10 @@
             'For "cancel", "ban" and "unban", either the entry URL or ' .
             'the username to cancel promotion or to ban or unban.',
 
+        'promo' =>
+            'Promo type to perform cmd for. Default value "*" that means it apply for all promos. ' .
+            'Available values: *, '.join(', ', PROMO_SELF(), PROMO_COMMERCIAL(), PROMO_NOTIFICATIONS()).'.',
+
         'region' =>
             'For "cancel" only, an optional flag that specifies ' .
             'region of the promo. Available regions are: [' . 
@@ -105,11 +109,16 @@
     }
     $type = $object->type;
 
+    my $promo_class = 'all'; # [ PROMO_SELF(), PROMO_COMMERCIAL(), PROMO_NOTIFICATIONS() ];
     my $country = PROMO_REGION_DEFAULT();
     
     my ($norefund, $reason) = 0;
     if (@args_remainder) {
         my ($arg) = @args_remainder;
+        if ($arg =~ /^(selfpromo|commercial|notifications)/) {
+            $promo_class = $1;
+            shift @args_remainder;
+        }
 
         if ( $arg =~ /^ua$/ ) {
             $country = $arg;
@@ -127,30 +136,35 @@
     unless ( $reason ) {
         return $self->error("Insufficient arguments");
     }
+warn "PROMO_CLASS: $promo_class";
+warn "Reason: $reason";
+    my @promo_classes = $promo_class eq 'all' ? (PROMO_SELF(), PROMO_COMMERCIAL(), PROMO_NOTIFICATIONS() ) : ($promo_class);
 
-
     if ( $cmd eq 'cancel' ) {
         #if ( $type =~ /^journal|community$/ ) {
         #    return $self->error('"cancel" requires personal journal or community') unless ($object->is_community || $object->is_personal);
         #    $type = $object->is_community ? 'community' : 'journal';
         #}
+        foreach my $pc (@promo_classes) {
+            my $slot = LJ::Pay::PromotionSlot->find_slot(class => $pc, type => $type, country => $country);
+            $slot->check_current_promotion;
+            my $current_promotion = $slot->current_promotion;
 
-        my $slot = LJ::Pay::PromotionSlot->find_slot(class => PROMO_SELF(), type => $type, country => $country);
-        $slot->check_current_promotion;
-        my $current_promotion = $slot->current_promotion;
+            unless ($current_promotion) {
+                $self->info("No $type currently promoted in $pc $country promo");
+                next;
+            }
 
-        unless ($current_promotion) {
-            return $self->error("No $type currently promoted in $country promo");
-        }
+            unless ($current_promotion->is_promoting($object)) {
+                $self->info(
+                    $object_orig . " is not the $type currently promoted in $pc $country promo" );
+                next;
+            }
 
-        unless ($current_promotion->is_promoting($object)) {
-            return $self->error(
-                $object_orig . " is not the $type currently promoted in $country promo" );
+            $self->_cancel_object( 'slot' => $slot, 'type' => $type, 'object' => $object, 'refund' => !$norefund, 'reason' => $reason );
         }
 
-        $self->_cancel_object( 'slot' => $slot, 'type' => $type, 'object' => $object, 'refund' => !$norefund, 'reason' => $reason );
-
-        $self->info( "$object_orig cancelled successfully from $country promo" );
+        $self->info( "$object_orig cancelled successfully from $promo_class $country promo" . ($promo_class eq 'all' ? 's' : '') . '.' );
         return 1;
     }
 
@@ -158,47 +172,51 @@
         if ( $type ne PROMO_OBJECT_TYPE_ENTRY() ) {  # ensure we get users as object
             my $u = $object->object;    # LJ::User
             # check all current promotions
-            foreach my $cc (LJ::Pay::PromotionSlot->get_all_regions()) {
-                foreach my $ptype qw(entry journal community) {
-                    my $slot = LJ::Pay::PromotionSlot->find_slot(class => PROMO_SELF(), type => $ptype, country => $cc);
-                    $slot->check_current_promotion;
-                    my $current_promo = $slot->current_promotion();
+            foreach my $pc (@promo_classes) {
+                foreach my $cc (LJ::Pay::PromotionSlot->get_all_regions($pc)) {
+                    foreach my $ptype (LJ::Pay::PromotionSlot->get_all_types($pc,$cc)) {
+                        my $slot = LJ::Pay::PromotionSlot->find_slot(class => $pc, type => $ptype, country => $cc);
+                        $slot->check_current_promotion;
+                        my $current_promo = $slot->current_promotion();
 
-                    if ( $current_promo && ( $current_promo->is_promoter($u) || $current_promo->is_promoting($u)) ) {   # $current_promo->is_owner($u) || 
-                        $self->info("The ban will affect the currently promoted $ptype in $cc promo, so cancelling that.");
-                        my $current_object = $current_promo->promoted_object();
-                        $self->_cancel_object( 'slot' => $slot, 'type' => $ptype, 'object' => $current_object, 'reason' => $reason );
+                        if ( $current_promo && ( $current_promo->is_promoter($u) || $current_promo->is_promoting($u)) ) {   # $current_promo->is_owner($u) || 
+                            $self->info("The ban will affect the currently promoted $ptype in $cc promo, so cancelling that.");
+                            my $current_object = $current_promo->promoted_object();
+                            $self->_cancel_object( 'slot' => $slot, 'type' => $ptype, 'object' => $current_object, 'reason' => $reason );
+                        }
                     }
                 }
             }
+            # TODO: Set ban scope!
             $u->set_prop( 'selfpromo_banned' => 1 );
             LJ::statushistory_add( $u, $admin, 'selfpromo', 'admin banned user. Reason: '. $reason );
 
-            $self->info( $u->display_name . ' banned successfully.');
+            $self->info( $u->display_name . " banned successfully from $promo_class promo" . ($promo_class eq 'all' ? 's' : '') . '.' );
             return 1;
         }
 
         if ( $type eq PROMO_OBJECT_TYPE_ENTRY() ) {
             my $entry = $object->object;
-
-            # check all regions
-            foreach my $cc (LJ::Pay::PromotionSlot->get_all_regions()) {
+            foreach my $pc (@promo_classes) {
+                # check all regions
+                foreach my $cc (LJ::Pay::PromotionSlot->get_all_regions($pc)) {
             
-                my $slot = LJ::Pay::PromotionSlot->find_slot(class => PROMO_SELF(), type => $type, country => $cc);
+                    my $slot = LJ::Pay::PromotionSlot->find_slot(class => PROMO_SELF(), type => $type, country => $cc);
 
-                $slot->check_current_promotion;
-                my $current_promo = $slot->current_promotion();
+                    $slot->check_current_promotion;
+                    my $current_promo = $slot->current_promotion();
 
-                if ( $current_promo && $current_promo->is_promoting($object) ) {
-                    $self->info("The ban will affect the currently promoted entry in $country promo, so cancelling that.");
-                    $self->_cancel_object( 'slot' => $slot, 'type' => $type, 'object' => $object, 'reason' => $reason );
+                    if ( $current_promo && $current_promo->is_promoting($object) ) {
+                        $self->info("The ban will affect the currently promoted entry in $country promo, so cancelling that.");
+                        $self->_cancel_object( 'slot' => $slot, 'type' => $type, 'object' => $object, 'reason' => $reason );
+                    }
                 }
             }
-
+            # TODO: Set ban scope!
             $entry->set_prop( 'selfpromo_banned' => 1 );
             LJ::statushistory_add( $entry->journal, $admin, 'selfpromo', 'admin banned entry: '. $entry->url .'. Reason: '. $reason );
 
-            $self->info( $entry->url . ' banned successfully.');
+            $self->info( $entry->url . " banned successfully from $promo_class promo" . ($promo_class eq 'all' ? 's' : '') . '.' );
             return 1;
         }
 
@@ -208,15 +226,17 @@
     if ( $cmd eq 'unban' ) {
         if ( $object->type ne PROMO_OBJECT_TYPE_ENTRY() ) {
             my $user = $object->object;
+            # TODO: Clean ban scope only!
             $user->clear_prop('selfpromo_banned');
             LJ::statushistory_add( $user, $admin, 'selfpromo', 'admin unbanned user. Reason: '. $reason );
-            $self->info( $user->display_name . ' unbanned successfully.');
+            $self->info( $user->display_name . " unbanned successfully from $promo_class promo" . ($promo_class eq 'all' ? 's' : '') . '.' );
             return 1;
         } else {  # entry
             my $entry = $object->object;
+            # TODO: Clean ban scope only!
             $entry->set_prop( 'selfpromo_banned' => undef );
             LJ::statushistory_add( $object->journal, $admin, 'selfpromo', 'admin unbanned entry: '. $object->url .'. Reason: '. $reason );
-            $self->info( $object->url . ' unbanned successfully.');
+            $self->info( $object->url . " unbanned successfully from $promo_class promo" . ($promo_class eq 'all' ? 's' : '') . '.' );
             return 1;
         }
 

Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-08-03 12:00:41 UTC (rev 12412)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-08-03 12:15:55 UTC (rev 12413)
@@ -481,7 +481,8 @@
 }
 
 =item admin_cancel_promo
-   Admin function to cancel current promo        
+   Admin function to cancel current promo
+    NOTE: Implementation of the base function
 =cut
 sub admin_cancel_promo {
     my ( $class, %args ) = @_;

Tags: ljcom, pm, sunnyman, vtroitsky
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments