madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[ljcom] r11001: LJSV-1566: Added notification and discon...

Committer: sbelyaev
LJSV-1566: Added notification and disconnect with facebook.
U   trunk/bin/upgrading/en_LJ.dat
U   trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm
Modified: trunk/bin/upgrading/en_LJ.dat
===================================================================
--- trunk/bin/upgrading/en_LJ.dat	2011-09-14 03:40:45 UTC (rev 11000)
+++ trunk/bin/upgrading/en_LJ.dat	2011-09-14 05:35:56 UTC (rev 11001)
@@ -2401,6 +2401,10 @@
 
 facebookconnect.untitled.comment=(Untitled)
 
+facebook.email.error_disconnect.subject=You have been disconnected from facebook
+
+facebook.email.error_disconnect.body=You have been disconnected from Facebook becouse of error: [[errortext]]
+
 fcklang.videoprompt=Please enter a video URL:
 
 find|staleness=1

Modified: trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm
===================================================================
--- trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm	2011-09-14 03:40:45 UTC (rev 11000)
+++ trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm	2011-09-14 05:35:56 UTC (rev 11001)
@@ -12,6 +12,7 @@
 
 use base qw(LJ::Worker::Repost);
 use LJ::Text;
+use JSON;
 
 sub work {
     my ($class, $job) = @_;
@@ -96,9 +97,75 @@
     $data->{'description'} = $event;
 
     my $ua      = LJ::get_useragent( 'role' => 'facebook_auth' );
-    $ua->post('https://graph.facebook.com/me/feed', $data);
+    my $retdata = $ua->post('https://graph.facebook.com/me/feed', $data);
+    if ($retdata) {
+        my $content = $retdata->decoded_content or '';
+        eval {
+            __process_return_data( $poster, $content);
+        };
+    }
 
     return $job->completed;
 }
 
+sub __process_return_data {
+    my ($poster, $content) = @_;
+
+    my $decoded = from_json($content);
+    my $error = $decoded->{'error'};
+
+    if ( $error ) {
+        __send_error( $poster, $error->{'message'} );
+        __destroy_link($poster);
+        
+    }
+    return;
+}
+
+sub __destroy_link {
+    my ($u) = @_;
+
+    my @pros = qw( facebook_access_token facebook_name facebook_link );
+    foreach  my $prop (@pros) {
+        $u->clear_prop($prop);
+    }
+    return;
+}
+
+sub __send_error {
+    my ( $poster, $fb_error ) = @_;
+    my $email = $poster->email_raw;
+
+    my $subject =  LJ::Lang::get_text($poster->prop('browselang'),
+                                      'facebook.email.error_disconnect.subject');
+
+    my $error =  LJ::Lang::get_text($poster->prop('browselang'),
+                                    'facebook.email.error_disconnect.body',
+                                    undef,
+                                    {
+                                        sitename    => $LJ::SITENAME,
+                                        siteroot    => $LJ::SITEROOT,
+                                        errortext    => $fb_error,
+                                    });
+
+    LJ::send_mail({
+        'to' => $email,
+        'from' => $LJ::ADMIN_EMAIL,
+        'fromname' => $LJ::SITENAME,
+        'charset' => 'utf-8',
+        'subject' => $subject,
+        'body' => $error,
+        { subject => $subject, reason => $error },
+    });
+
+    return __log_statushistory( $poster, $error );
+}
+
+sub __log_statushistory {
+    my ( $poster, $notes ) = @_;
+
+    my $sys_uid   = LJ::get_userid("system");
+    return LJ::statushistory_add($poster->userid, $sys_uid, 'facebook_connect', $notes);
+}
+
 1;

Tags: dat, ljcom, madeon, pm
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