Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r9950: LJINT-362 (Comments for side projects)

Committer: ailyin
LJINT-362 (Comments for side projects)
U   trunk/cgi-bin/LJ/PartnerSite.pm
Modified: trunk/cgi-bin/LJ/PartnerSite.pm
===================================================================
--- trunk/cgi-bin/LJ/PartnerSite.pm	2011-01-26 11:41:31 UTC (rev 9949)
+++ trunk/cgi-bin/LJ/PartnerSite.pm	2011-01-27 09:00:44 UTC (rev 9950)
@@ -298,6 +298,30 @@
 
 =item *
 
+$partner->insert_mapping( $entry, $docid ): record that the given
+entry corresponds to the given docid.
+
+=cut
+
+sub insert_mapping {
+    my ( $self, $entry, $docid ) = @_;
+
+    my $dbh = LJ::get_db_writer();
+    $dbh->do( qq{
+        INSERT IGNORE INTO external_sites_articles_map
+        SET
+            partnerid = ?,
+            docid_hash = ?,
+            docid = ?,
+            jitemid = ?
+    }, undef, $self->id, _hashfunc($docid), $docid, $entry->jitemid );
+
+    my $memc_key = 'extarticlesmap_jitemid:' . $self->id . ':' . $docid;
+    LJ::MemCache::delete( $memc_key );
+}
+
+=item *
+
 $partner->find_entry_by_docid( $docid, { %opts } ): return an entry
 corresponding to this docid.
 
@@ -319,6 +343,7 @@
     my $memc_key = 'extarticlesmap_jitemid:' . $self->id . ':' . $docid;
 
     my $jitemid = LJ::MemCache::get($memc_key);
+    my $entry;
 
     if ($jitemid) {
         # an entry exists, we pulled it from memcache, so let's return
@@ -337,7 +362,9 @@
     }, undef, $self->id, _hashfunc($docid), $docid );
 
     if ($row) {
-        $jitemid = $row->{'jitemid'};
+        $entry = LJ::Entry->new( $self->journal,
+                                 'jitemid' => $row->{'jitemid'} );
+
     } elsif ( $opts->{'nocreate'} ) {
         # database didn't find an entry for us, and we don't wish to create
         # one, so let's return undef, but first, memcache that there
@@ -380,22 +407,15 @@
                         "; error details: $err_out";
         }
 
-        $jitemid = $protocol_res->{'itemid'};
+        $entry = LJ::Entry->new( $self->journal,
+                                 'jitemid' => $protocol_res->{'itemid'} );
 
-        my $dbh = LJ::get_db_writer();
-        $dbh->do( qq{
-            INSERT IGNORE INTO external_sites_articles_map
-            SET
-                partnerid = ?,
-                docid_hash = ?,
-                docid = ?,
-                jitemid = ?
-        }, undef, $self->id, _hashfunc($docid), $docid, $jitemid );
+        $self->insert_mapping( $entry, $docid );
     }
 
-    LJ::MemCache::set( $memc_key, $jitemid );
+    LJ::MemCache::set( $memc_key, $entry->jitemid );
 
-    return LJ::Entry->new( $self->journal, 'jitemid' => $jitemid );
+    return $entry;
 }
 
 =item *
@@ -504,7 +524,7 @@
     
             function checkDomain(href, trustedDomains) {
                 var currentDomain = href.match(] .q{/(http\:\/\/)([^\/]*)/} . qq[)[2].split('.').slice(-2).join('.'),
-					currentRegExp = new RegExp(currentDomain.replace('.', '\\.') + '\$');
+					currentRegExp = new RegExp(currentDomain.replace('.', '\\\\.') + '\$');
                 
                 for (var i = 0, l = trustedDomains.length; i < l; i++) {
                     if (trustedDomains[i].search(currentRegExp) != -1) {
@@ -530,10 +550,10 @@
             } else {
                 window.location.href = 'about:blank';
             }
-
+			
             function checkDomain(href, trustedDomains) {
                 var currentDomain = href.match(] .q{/(http\:\/\/)([^\/]*)/} . qq[)[2].split('.').slice(-2).join('.'),
-					currentRegExp = new RegExp(currentDomain.replace('.', '\\.') + '\$');					
+					currentRegExp = new RegExp(currentDomain.replace('.', '\\\\.') + '\$');
                 
                 for (var i = 0, l = trustedDomains.length; i < l; i++) {
                     if (trustedDomains[i].search(currentRegExp) != -1) {

Tags: andy, ljcom, 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