Update #6003 is broken if the variable is an empty string

deviantintegral - August 6, 2009 - 23:50
Project:Masquerade
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

If "masquerade_quick_switches" is an empty string, then the update code doesn't change the variable from a string to an array. This throws a warning when the variable is used to display the block.

This patch changes the function to delete the variable entirely if it's empty.

AttachmentSize
empty_quick_switch.patch599 bytes

#1

deviantintegral - August 6, 2009 - 23:50
Status:active» needs review

#2

andypost - August 26, 2009 - 18:53
Status:needs review» needs work

This patch only a part of problem so need more work to adequately check variables for loops

#3

deviantintegral - August 26, 2009 - 19:06

I'm not sure what you mean by loops?

#4

andypost - August 27, 2009 - 20:26

I mean that using foreach (variable_get(.. is wrong - this should be fixed first

#5

deviantintegral - August 31, 2009 - 17:49
Status:needs work» fixed

The variable_get() call will either return an array of values, or an empty array. If it's not returning an array (due to broken code, or some other module saving a string or an int) then that code should be fixed. For an example in core, see color.module.

I've committed this, but feel free to follow up with another patch if you run into any issues.

#6

webavant - September 1, 2009 - 05:46

Hi, the latest update in 1.x-dev is not fixing this problem.

# warning: Invalid argument supplied for foreach() in /var/www/vhosts/stage.kartiniclinic.com/httpdocs/sites/all/modules/masquerade/masquerade.module on line 188.
# warning: Invalid argument supplied for foreach() in /var/www/vhosts/stage.kartiniclinic.com/httpdocs/sites/all/modules/masquerade/masquerade.module on line 382.

I do not see the warning until I save the settings page. I tried to fix it, but I couldn't get to the bottom of it. The loop is not getting the array that it expects. I put a print statement on the variable that it was looping on and saw the serialized data in the plain text string. The error warning occurs without entering any information at all on the settings page, but upon further investigation I can see that the serialized data that I entered into the Block input is stored in the DB but it does not appear in the input on the Masquerade settings page.

This problem also affected version 1.1 as well. Is the Block displaying properly for everyone else? This sounds like the same problem describe in this issue, but I don't know for sure.

#7

webavant - September 1, 2009 - 06:52
Status:fixed» active

Gosh, I guess I should set this back. I'm pretty sure there should be a drupal_explode_tags($masquerade_switches); somewhere around line 382 and I'm not sure what else.

#8

webavant - September 1, 2009 - 07:16

It appears there is no data in my 'masquerade' and 'masquerade_users' tables. What would cause this? The $masquerade_switches array is empty. I believe that's the cause of the the second warning I'm getting.

#9

deviantintegral - September 1, 2009 - 16:09

Can you post the output of all of the masquerade_% values from the variables table?

#10

deviantintegral - September 2, 2009 - 03:02
Status:active» fixed

I looked into this, and the issue is actually different then the one here. Lets continue the discussion over at #565860: Block quick switch users not properly saved.

#11

System Message - September 16, 2009 - 03:10
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.