Switchtheme does not work more than once

franc23 - January 28, 2009 - 00:06
Project:Switchtheme
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

With the latest snapshot, switchtheme recognizes browser and presents correct theme(browscap). However, switching theme using the block does not work more than once. Caching is disabled and still no effect for both logged in and anonymous users.

Switchtheme works as expected using the 6.x.1.0 version, it's the dev code that makes it get stuck on one theme.

#1

himerus - June 6, 2009 - 18:07

I'm having the same issue.
Just switched to the 6.x-dev version to allow for the browscap integration, and that works, and IS presenting garland to the crappy browsers that can't handle my new theme, BUT it is not allowing me to switch themes using the form anymore.

It was listed on the main project page that the 6.x-1.1 release integrated the browscap, but there is still no official release to match that version number. Is this project still being maintaned?? This is a HUGE module for my future purposes, even if simply for presenting a simple theme to poor browsers like IE. I'd be happy to take over maintaining it, and work out the issues if no one is still working on it.

#2

himerus - June 6, 2009 - 18:14

Oddly enough, after a bit more testing... it appears that it IS still working fine for anonymous and "normal" authenticated users. But logged in as admin it is breaking, and not switching themes.

I've flushed all caches several times, I will investigate further, and review the code behind the module to see if I can find the issue.
If you are having this issue, test it out with multiple accounts, and as anonymous to see if it is having the same effect.

I will post more when I have discovered the issue.

#3

kingandy - June 19, 2009 - 11:26

I was encountering this too - it went away once I had gone to my user account page and saved it with a non-default theme selected. Still occurring for anonymous users though.

At a guess I'd say it's not interacting properly with whatever functionality gets the theme if the user has never picked on (ie it has trouble working out the 'default' setting)...?

#4

danielhonrade - July 26, 2009 - 07:35

it works fine when I am in the admin and in the local setup, but doesn't work on the 3rd time of switching as anonymous on production sites. Is it because many are using it on production sites?

#5

gilgabar - August 3, 2009 - 18:50

I upgraded from 6.x-1.0 to 6.x-1.1 and encountered similar problems. Using the form block the theme would appear to not switch. It looks like the change is that in 1.0 it relied on a session variable to set a user's theme while in 1.1 it lets drupal core's theme handling do the work of changing the theme. It still uses the session variable for anonymous users and it appears that the session variable is still set from using the 1.0 version and 1.1 is still using it to display the theme, but 1.1 no longer changes the session variable, so it appears to not change even though you can see the theme selection change in the default drupal theme changing widget on the user account page.

The solution was to remove all the cookies for the site and log back in again. It all works as expected now.

#6

FiNeX - August 7, 2009 - 16:07

Cleaning both Drupal and browser cache didn't work on my situation: I've tried both 6.x-1.0 and 6.x-1.1 (on another website I've 6.x-1.0 which works correctly, the server is the same with the same configuration)

#7

gilgabar - August 7, 2009 - 18:15

Clearing either cache shouldn't be any help. You need to specifically delete the cookies for the site in question from your browser. Ask google or refer to the documentation for your browser if you need help deleting cookies.

#8

FiNeX - August 8, 2009 - 15:45

Even deleting cookies from the browser still doesn't work: anonymous users are able to see the combo box, but clicking "switch" reloads the website with the same default theme. Very very very strange

#9

FiNeX - August 8, 2009 - 16:21

I've found the bug on my website: the user "0" didn't have "0" on the uid field, but "3"... I don't know why.

I'm sorry.

#10

sun - August 11, 2009 - 00:18
Status:active» needs review

Please test attached patch.

AttachmentSize
switchtheme-HEAD.multi-switch.patch 2.48 KB

#11

antrophos - August 19, 2009 - 19:08

I installed the patch but it didn't solve my problem.

On some pages the toggle works, however on some not.

http://www.visualimpression

Theme switch buttons are the sqares in black and white in the lower right.

Themes switching works for:

/aktuelles -> /node
/kontakt -> /contact

does not work for other nodes like:

http://www.visualimpression.de/visualisierung/aussen (some node with cck)

Could anyone help?
Could anyone give a hint how to help?

#12

antrophos - August 22, 2009 - 06:53
Status:needs review» needs work

I'm very sorry but I only understand little about the internals of drupal codin so I can't provide a patch but I was examining the behavior and I can tell, there are 2 major bugs.

1. If it's a signed in user and if he is allowed to switch theme, the theme doesn't switch instantly but on the second page reload.
2. If it's not a known user or he's not allowed, than the module works fine on non-node pages but doesn't work on node pages for me.

#13

tsavino - August 25, 2009 - 11:06

Its not not working for me ether 1.0 or 1.1

#14

danielhonrade - August 27, 2009 - 09:35

It's just an observation, non-switching usually happens on the live site
and when the browser waits for the new theme, if it waits for too long,

It loads the old theme from the cache of the browser,
probably, switchtheme should require to get new theme from the server
and not from the client's browser save files.

[Edited by KiamLaLuno in order to show the last sentence in normal style rather than bold style]

#15

kingandy - August 27, 2009 - 10:06

Good thinking. Unfortunately themes do not work that way.

The "theme" is never sent from the server to the browser at any point - it's used by the server while assembling the page. As far as the browser is concerned, the page is completely normal HTML. Even the CSS files will appear to be at completely different locations, so there's no danger of styles cacheing between themes.

It might be that the *page* is cacheing at the browser level, but Drupal already sends all sorts of no-cache instructions with every page request.

#16

danielhonrade - August 28, 2009 - 09:45

If the browser loads the old one, how do we control it from drupal configuration, instead of clearing the browser cache every change of theme?

I also observe this when you logout and go to other pages, it will load the old page where you have previously logged in like it will show the admin menu.

#17

danielhonrade - August 28, 2009 - 09:49

hope this module works soon, it's very useful

#18

Reg - September 17, 2009 - 12:43

Hi, I came across this behavior too. Unfortunately my server is undergoing some changes so I can't just jump in the code right now but I have found some additional behavior that might help track it down.

If I go into Themes and Restore Defaults and then re-enable all the themes, I can switch themes once again, only once though.

If disable the theme that Drupal is stuck on, then clear all the cache, and then go to a non-admin page, it still uses the disables theme! (that's got to be a clue to someone).

I tracked down a similar problem in a different theme module which might help give you some ideas, this issue is here: http://drupal.org/node/421644

I also checked on node_load which does its own caching separate of the Disable Cache feature as far as I know (http://drupal.org/node/221081) by disabling its cache, that didn't help but I thought I would mention it in case it give someone else an idea.

I have applied the patch above but it made no change in behavior. Also, I am a developer so I can say straight up this is not a browser cache issue. All my browsers have cache disabled and I primarily use FireFox with plugins that give me finer cache control and guarantee it's not caching anything since I need it this way for my own development.

If this isn't resolved when I get my computers back in order I'll jump in the code and try to track it down but that might not be for a while so hopefully someone else will be able to figure it out in the meantime.

#19

Reg - September 17, 2009 - 13:03

I just noticed that this is rather sporadic. I logged out, logged back in, all of a sudden I could change themes at will. Just like I was for hours before it suddenly stopped. However, I logged out and still the theme was stuck. I moved to a different page and then back, now I could change themes while not logged in. I really haven't found a consistent pattern to it yet but will keep a careful lookout and post more if I see anything new.

#20

gianfrasoft - October 5, 2009 - 15:30

If you click on "Try out a demostration" on Switchtheme project page, you can see a site in which the theme changes only the first time you click on Switchtheme block!!!

#21

gianfrasoft - October 5, 2009 - 15:35
Priority:normal» critical

I think priority have to be set to "critical". Don't you?

#22

Reg - October 8, 2009 - 02:51

Agreed, it makes it essentially unusable.

#23

Reg - October 8, 2009 - 06:37

I put a write to log file (my own debug routines) at the start and exit point of every function in switchtheme.module. It's seems from the trace that the problem is in the very first function called is switchtheme_init.

I don't know the fix, just that this is what is happening (I will follow up soon after some analysis - right now I'm just making some diag. info. available for anyone who wants to help fix this). Below is my trace output and attached is switchtheme.module (had to change extension to txt so it would upload) with my trace code so you can see what is producing the trace.

I have also added the code to theme_init (will attach file as well if allowed to attach more than one file - I've never attached a file on this website before) since that is the critical system call that we must watch. This should be plenty for the owner to fix it since he knows the code intimately and can now see exactly how it is failing.

"acrylic" is the theme it is stuck on and "smoothBlue" is the theme I was attempting to switch to.

    switchtheme_init/S
      switchtheme_init/1
      switchtheme_init/2
      switchtheme_init
      switchtheme_switch_form_submit/SE
      switchtheme_init/3  custom_theme: {NULL}
      switchtheme_init  _SESSION[custom_theme]: acrylic
      switchtheme_init/4  custom_theme: acrylic
    switchtheme_init/E
    init_theme/S
      init_theme/1  theme: {NULL}
      init_theme/2  theme: smoothBlue
      init_theme  $custom_theme: acrylic
      init_theme/3  theme: acrylic
      init_theme/8  theme: acrylic
      init_theme/9  theme: acrylic
    init_theme/E2
    switchtheme_block/S
      switchtheme_block/3
      switchtheme_block/4
      switchtheme_switch_form/S
        switchtheme_select/S
          switchtheme_options/SE
        switchtheme_select/E
      switchtheme_switch_form/E
      switchtheme_switch_form_submit/SE

AttachmentSize
switchtheme.module.txt 8.26 KB
theme.inc_.txt 67.48 KB

#24

Reg - October 8, 2009 - 06:41

Found it! Everyone please check and see if this also works for you.

The attached patch was created by my IDE so it may not work for you. However, It's only two lines so it's a dead easy manual change.

In case it doesn't work, in switchtheme_init just change:

  if (isset($_SESSION['custom_theme']) && (!isset($custom_theme) || $custom_theme === '0')) {

to:
  if (user_access('select different theme')) {
    # Do nothing, this reflects the logic in switchtheme_switch_form_submit called just above
  } elseif (isset($_SESSION['custom_theme']) && (!isset($custom_theme) || $custom_theme === '0')) {

switchtheme_init should now reflect the logic in switchtheme_switch_form_submit. I should mention that this fix is without the previous patch in this issue applied. I had it applied at one point but it made no difference to whether the module worked so I removed it.

AttachmentSize
scratchpad.patch 755 bytes

#25

Reg - October 9, 2009 - 03:13

An alternative solution, perhaps a little cleaner. Either way hopefully the maintainer will look at these and make his own fix from them as I am not sure if I have taken all the logic into account. Please note that if you want to use this patch apply it after applying the patch in #24.

Something to remember, Drupal loads from index.php twice on each page change and I have been seeing it load 3 times while working on this bug, perhaps because of the theme change or perhaps some other module I have installed. In any case, with this module I have seen it make a difference in how I had to code it to work right.

AttachmentSize
scratchpad.patch 755 bytes

#26

Reg - October 8, 2009 - 08:04

Oops, wrong patch, here is the new one that was meant to be in the above.

AttachmentSize
switchtheme.module.patch 1.95 KB

#27

Reg - October 21, 2009 - 20:29
Status:needs work» needs review

After some testing I found the patch didn't work for non-logged in users. Digging deeper into this module's workings to figure out exactly what's going on with it I've created the following patch - it should work as I went through it quite thoroughly. I've also attached the final file (you will need to remove the .txt extension added so it could be uploaded) that can be copied over the old file in case the patch doesn't work for some people (remember to preserve your original file if you do this).

Testing and feedback appreciated.

AttachmentSize
switchtheme.module.2009.10.21.patch 3.53 KB
switchtheme.module.txt 7.59 KB

#28

Reg - October 24, 2009 - 05:34

Another thing that just came up. When I switched to a non-home page as an anonymous user it stopped working. On investigating it came down to another module, in this case nodewords getting there first.

The solution is to change the module weight of switchtheme. In my case -1 was sufficient. It would be useful if the developer would add this into the install script since 'being first' is an important attribute of this module. Or even better, make it an option in the admin section.

If you don't know how to change the module weight in the DB just install the module 'module weight' and then you can change through the interface under 'modules'.

 
 

Drupal is a registered trademark of Dries Buytaert.