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

[livejournal] r19156: LJSV-1375 (Style Reverts to Generator/Na...

Committer: ailyin
LJSV-1375 (Style Reverts to Generator/Nautical)
U   trunk/cgi-bin/LJ/Customize.pm
U   trunk/cgi-bin/LJ/S2.pm
U   trunk/htdocs/customize/index.bml
U   trunk/htdocs/customize/index.bml.text
U   trunk/htdocs/customize/options.bml
A   trunk/htdocs/customize/reset_style.bml
A   trunk/htdocs/customize/reset_style.bml.text
Modified: trunk/cgi-bin/LJ/Customize.pm
===================================================================
--- trunk/cgi-bin/LJ/Customize.pm	2011-05-27 07:47:17 UTC (rev 19155)
+++ trunk/cgi-bin/LJ/Customize.pm	2011-05-27 08:00:49 UTC (rev 19156)
@@ -89,25 +89,11 @@
     my $style = LJ::S2::load_style($u->prop('s2_style'));
 
     unless ( $style && $style->{layer}->{layout} ) {
-        # we have no layout layer for this style, which causes errors in
-        # the customization interface
-        # undef current style and force them to use the site defaults
-        $u->set_prop( s2_style => 0 );
-        $style = undef;
+        # unless they have a valid style, return back an undef so that
+        # the caller can error out
+        return;
     }
 
-    unless ($style && $style->{'userid'} == $u->{'userid'}) {
-        my $theme;
-        if ($LJ::DEFAULT_STYLE->{theme}) {
-            $theme = LJ::S2Theme->load_by_uniq($LJ::DEFAULT_STYLE->{theme});
-        } else {
-            $theme = LJ::S2Theme->load_default_of($LJ::DEFAULT_STYLE->{layout});
-        }
-
-        LJ::Customize->apply_theme($u, $theme);
-        $style = LJ::S2::load_style($u->prop('s2_style')); # reload style
-    }
-
     return $style;
 }
 

Modified: trunk/cgi-bin/LJ/S2.pm
===================================================================
--- trunk/cgi-bin/LJ/S2.pm	2011-05-27 07:47:17 UTC (rev 19155)
+++ trunk/cgi-bin/LJ/S2.pm	2011-05-27 08:00:49 UTC (rev 19156)
@@ -655,6 +655,8 @@
     }
 
     unless ($have_style) {
+        die "LJ::S2: style $styleid seems to be empty";
+
         my $public = get_public_layers();
         while (my ($layer, $name) = each %$LJ::DEFAULT_STYLE) {
             next unless $name ne "";
@@ -1166,30 +1168,24 @@
 
     my %stylay;
 
-    my $fetch = sub {
-        my ($db, $qry, @args) = @_;
+    my $udbh = LJ::get_cluster_master($u);
+    local $udbh->{'RaiseError'} = 1;
 
-        my $sth = $db->prepare($qry);
-        $sth->execute(@args);
-        die "ERROR: " . $sth->errstr if $sth->err;
-        while (my ($type, $s2lid) = $sth->fetchrow_array) {
-            $stylay{$type} = $s2lid;
-        }
-        return 0 unless %stylay;
-        return 1;
-    };
+    my $rows = $udbh->selectall_arrayref( qq{
+        SELECT type, s2lid FROM s2stylelayers2
+        WHERE userid=? AND styleid=?
+    }, { 'Slice' => {} }, $u->userid, $styleid );
 
-    unless ($fetch->($u, "SELECT type, s2lid FROM s2stylelayers2 " .
-                     "WHERE userid=? AND styleid=?", $u->{userid}, $styleid)) {
-        my $dbh = LJ::get_db_writer();
-        if ($fetch->($dbh, "SELECT type, s2lid FROM s2stylelayers WHERE styleid=?",
-                     $styleid)) {
-            LJ::S2::set_style_layers_raw($u, $styleid, %stylay);
-        }
+    foreach my $row (@$rows) {
+        $stylay{ $row->{'type'} } = $row->{'s2lid'};
     }
 
-    # set in memcache
-    LJ::MemCache::set($memkey, \%stylay);
+    # set in memcache, provided that we actually have something
+    # to store (empty styles is a rare case)
+    if (%stylay) {
+        LJ::MemCache::set($memkey, \%stylay);
+    }
+
     $LJ::S2::REQ_CACHE_STYLE_ID{$styleid} = \%stylay;
     return \%stylay;
 }

Modified: trunk/htdocs/customize/index.bml
===================================================================
--- trunk/htdocs/customize/index.bml	2011-05-27 07:47:17 UTC (rev 19155)
+++ trunk/htdocs/customize/index.bml	2011-05-27 08:00:49 UTC (rev 19156)
@@ -31,6 +31,17 @@
     # make sure there's a style set and load it
     my $style = LJ::Customize->verify_and_load_style($u);
 
+    unless ($style) {
+        my $ml_var = $u->get_cap('s2styles')
+                   ? '/customize/index.bml.error.invalid_style'
+                   : '/customize/index.bml.error.invalid_style.basic';
+
+        return LJ::Lang::ml( $ml_var, {
+            'siteroot' => $LJ::SITEROOT,
+            'journal'  => $u->username,
+        } );
+    }
+
     # lazy migration of style name
     LJ::Customize->migrate_current_style($u);
 

Modified: trunk/htdocs/customize/index.bml.text
===================================================================
--- trunk/htdocs/customize/index.bml.text	2011-05-27 07:47:17 UTC (rev 19155)
+++ trunk/htdocs/customize/index.bml.text	2011-05-27 08:00:49 UTC (rev 19156)
@@ -25,6 +25,10 @@
 
 .error.fail_create_style=Failed to create new style.
 
+.error.invalid_style=Could not retrieve information about your style, or the data appears to be corrupt. Please wait a couple minutes and try again. If the error persists, please try <a href="[[siteroot]]/customize/advanced/styles.bml?authas=[[journal]]">selecting another style</a> using the advanced interface, <a href="[[siteroot]]/customize/reset_style.bml?authas=[[journal]]">resetting the style</a> to the default selection, or <a href="[[siteroot]]/support/submit.bml?category=styles">contact our Support team</a> for assistance.
+
+.error.invalid_style.basic=Could not retrieve information about your style, or the data appears to be corrupt. Please wait a couple minutes and try again. If the error persists, please try <a href="[[siteroot]]/customize/reset_style.bml?authas=[[journal]]">resetting the style</a> to the default selection, or <a href="[[siteroot]]/support/submit.bml?category=styles">contact our Support team</a> for assistance.
+
 .error.not_your_layout=Not your layout.
 
 .error.not_your_layout2=Not your layout. <a [[aopts]]>Choose another layout.</a>

Modified: trunk/htdocs/customize/options.bml
===================================================================
--- trunk/htdocs/customize/options.bml	2011-05-27 07:47:17 UTC (rev 19155)
+++ trunk/htdocs/customize/options.bml	2011-05-27 08:00:49 UTC (rev 19156)
@@ -33,6 +33,17 @@
     # make sure there's a style set and load it
     my $style = LJ::Customize->verify_and_load_style($u);
 
+    unless ($style) {
+        my $ml_var = $u->get_cap('s2styles')
+                   ? '/customize/index.bml.error.invalid_style'
+                   : '/customize/index.bml.error.invalid_style.basic';
+
+        return LJ::Lang::ml( $ml_var, {
+            'siteroot' => $LJ::SITEROOT,
+            'journal'  => $u->username,
+        } );
+    }
+
     # lazy migration of style name
     LJ::Customize->migrate_current_style($u);
 

Added: trunk/htdocs/customize/reset_style.bml
===================================================================
--- trunk/htdocs/customize/reset_style.bml	                        (rev 0)
+++ trunk/htdocs/customize/reset_style.bml	2011-05-27 08:00:49 UTC (rev 19156)
@@ -0,0 +1,61 @@
+<?_code {
+#line 3
+
+use strict;
+use warnings;
+
+my $remote = LJ::get_remote();
+
+unless ($remote) {
+    return LJ::needlogin_redirect();
+}
+
+my $journal = $remote;
+if ( defined ( my $authas_username = LJ::Request->get_param('authas') ) ) {
+    $journal = LJ::get_authas_user($authas_username);
+
+    unless ($journal) {
+        return BML::render_page({
+            'title' => LJ::Lang::ml('Error'),
+            'body'  => LJ::Lang::ml('error.invalidauth'),
+        });
+    }
+}
+
+my $default_theme = $LJ::DEFAULT_STYLE->{'theme'};
+
+my $ml_params = {
+    'siteroot' => $LJ::SITEROOT,
+    'journal_ljuser' => $journal->ljuser_display,
+    'style' => $default_theme,
+    'journal' => $journal->username,
+};
+
+if ( LJ::Request->did_post ) {
+    unless ( LJ::check_form_auth() ) {
+        return BML::render_page({
+            'title' => LJ::Lang::ml('Error'),
+            'body'  => LJ::Lang::ml('error.invalidform'),
+        });
+    }
+
+    my @themes = LJ::S2Theme->load_by_uniq($default_theme);
+    LJ::Customize->apply_theme( $journal, $themes[0] );
+
+    return BML::render_page({
+        'title' => LJ::Lang::ml('.title'),
+        'body'  => LJ::Lang::ml( '.message.success', $ml_params ),
+    });
+}
+
+my $form = '<form action="" method="post">'
+         . LJ::form_auth()
+         . LJ::Lang::ml( '.form.content', $ml_params )
+         . '</form>';
+
+return BML::render_page({
+    'title' => LJ::Lang::ml('.title'),
+    'body'  => $form,
+});
+
+} _code?>

Added: trunk/htdocs/customize/reset_style.bml.text
===================================================================
--- trunk/htdocs/customize/reset_style.bml.text	                        (rev 0)
+++ trunk/htdocs/customize/reset_style.bml.text	2011-05-27 08:00:49 UTC (rev 19156)
@@ -0,0 +1,13 @@
+.form.content<<
+<p>You are going to reset journal style for [[journal_ljuser]] to <strong>[[style]]</strong>. Press this button to confirm:</p>
+<p><button type="submit">Reset</button></p>
+<p><a href="[[siteroot]]/customize/?authas=[[journal]]">Go back</a></p>
+.
+
+.message.success<<
+<p>Journal style for [[journal_ljuser]] has been successfully reset to <strong>[[style]]</strong>.</p>
+<p><a href="[[siteroot]]/customize/?authas=[[journal]]">Go back</a></p>
+.
+
+.title=Reset Journal Style
+

Tags: andy, bml, livejournal, pm, text
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