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

[ljcom] r11483: LJSUP-11276: Return proper owner of the ...

Committer: vtroitsky
LJSUP-11276: Return proper owner of the communities
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2012-02-16 13:16:46 UTC (rev 11482)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2012-02-16 13:58:46 UTC (rev 11483)
@@ -58,13 +58,23 @@
     # return $promo_object->owner;
     my ($self) = @_;
 
-    #my $promo_object = LJ::Pay::SelfPromo::Promo->create_from_item($self);
-    # return $promo_object->url;
+    #my $promo_object = LJ::Pay::SelfPromo::Promo->create_from_item($self);   #cache object creation
+    # return $promo_object->owner;
 
     my $object = $self->get_object;
     return unless $object;
     my $sp_type = $self->get_prop('selfpromo');
-    return  ($sp_type eq 'entry' ? $object->poster : $sp_type eq 'community' ? $object : $object); 
+
+    return $object->poster if $sp_type eq 'entry';
+    return $object if $sp_type eq 'journal';
+
+    if ($sp_type eq 'community') {
+        my $super_maintainers = LJ::load_rel_user_cache($object->{userid}, 'S') || LJ::load_rel_user_cache($object->{userid}, 'A') || [];
+
+        return $object unless scalar(@$super_maintainers);
+        return LJ::load_userid(shift @$super_maintainers);   # approxation in case of absense supermaintainer
+    }
+    return;
 }
 
 #sub get_entry_url {
@@ -276,7 +286,7 @@
         $email_subject = $ml->("selfpromo.$class_type.notification.activate.subject");
  
         LJ::Pay::SelfPromo->debug_msg("generating the emails");
-        # Need to send second email if entry poster and recipient are different
+        # Need to send second email if object owner and recipient are different
         unless ( LJ::u_equals($owner, $rcpt_u) ) {
             $email_body = $ml->(
                 "selfpromo.$class_type.notification.activate.body",

Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-02-16 13:16:46 UTC (rev 11482)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-02-16 13:58:46 UTC (rev 11483)
@@ -18,7 +18,7 @@
 
 BEGIN {
     $errors = {
-        ERROR_OBJECT_INELIGIBLE          => 1,
+        ERROR_OBJECT_INELIGIBLE         => 1,
         ERROR_PRICE_INSUFFICIENT        => 2,
         ERROR_INVALID_PRICE             => 3,
         ERROR_WALLET_INSUFFICIENT_FUNDS => 4,
@@ -118,7 +118,7 @@
     # TODO: Translate exception to SelfPromo Error!
     my $lock = $class->lock;    # actually use the lock specific for that class, lock()
 
-    #$class->raise_error( ERROR_BIDS_HAVE_CHANGED ) unless $lock;
+    $class->raise_error( ERROR_BIDS_HAVE_CHANGED ) unless $lock;
  
     ## check object that we are going to promote
       do {
@@ -223,8 +223,8 @@
     #   2. 
  
     do {
-        LJ::Pay::SelfPromo->debug_msg("delivering the cart/items");
-        LJ::Pay::SelfPromo->debug_msg( "payid=" . $cart->get_payid );
+        $class->debug_msg("delivering the cart/items");
+        $class->debug_msg( "payid=" . $cart->get_payid );
 
         my ($item) = $cart->get_items;
 
@@ -240,13 +240,13 @@
 
         local $SIG{'__WARN__'} = sub {
             my @messages = @_;
-            LJ::Pay::SelfPromo->debug_msg( "delivery warning: ", @messages );
+            $class->debug_msg( "delivery warning: ", @messages );
             warn @messages;
         };
 
         my $deliver_res = $item->deliver( $cart, time, sub { } );
         unless ($deliver_res) {
-            LJ::Pay::SelfPromo->debug_msg("delivery failed");
+            $class->debug_msg("delivery failed");
             die "delivering item failed, see error log for details";
         }
     };
@@ -505,13 +505,13 @@
     # Acquire lock to exclusive change promotion status
     # TODO: Perform error processing in case we can't acquire the lock during default timeout.
     my $lock = $class->lock;
-    #return unless $lock;
+  #  return unless $lock;
   
     my $promo = $class->current_promo_info( undef, 'require_db' => 1 );
     return unless $promo;    # everything's fine if nothing's promoted
   
     my $object = $promo->object;            # promoted object: entry / user(community/journal)
-    my $owner  = $promo->owner;            # owner of the promoted object: user 
+    my $owner  = $promo->owner;             # owner of the promoted object: user 
     my $promoter = $promo->promoter;        # promoter: user
     my $object_url = $promo->object_url;
 
@@ -791,9 +791,9 @@
             'jitemid'   => $object->jitemid,                # entry specific
             'ditemid'   => $object->ditemid,                # entry specific
         ) : (
-            'journalid' => $object->{userid},
-            'posterid'  => $object->{userid},
-            'jitemid'   => 0,
+            'journalid' => $object->{userid},               # journal / community
+            'posterid'  => $object->{userid},               # journal / 
+            'jitemid'   => 0,                               
             'ditemid'   => 0, 
         ),
         'started'   => time,
@@ -1173,7 +1173,13 @@
 
 sub ownerid {
     my ($self) = @_;
-    return ($self->type eq 'entry' ? $self->posterid : $self->journalid);
+    if ($self->type eq 'community') {
+        my $super_maintainers = LJ::load_rel_user_cache($self->journalid, 'S') || LJ::load_rel_user_cache($self->journalid, 'A') || [];
+        return $self->journalid unless scalar(@$super_maintainers);
+        return shift @$super_maintainers;   # appoximation in case of absence the supermaintainer in community
+    } else {
+        return ($self->type eq 'entry' ? $self->posterid : $self->journalid);
+    }
 }
 
 # owner of the promoted object:

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