I created a content type. When a registered user enters content, everything is fine. When an anonymous user enters information, the content posts but I get the following:

Notice: Undefined property: stdClass::$timezone in rate_expiration_node_insert() (line 184 of /home/MySite/public_html/MySite.com/sites/all/modules/rate/expiration/rate_expiration.module).

184 $timezone = is_null($user->timezone) ? variable_get('date_default_timezone', 0) : $user->timezone;
185 if (!is_numeric($timezone)) {
186 // Convert textual timezone to numeric offset.
187 $timezone = new DateTimeZone($timezone);
188 $timezone = $timezone->getOffset(new DateTime('now', $timezone));

Note: Content type/Display settings set to "Don't display post information"

Does the code above account for an anonymous user(s)?

Rate 7.x-1.3
Drupal 7.10 - all modules up to date

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

InternetDevels’s picture

Status: Active » Patch (to be ported)
FileSize
680 bytes

There is no timezone for anonymous user so to prevent notice isset() needed

xbrianx’s picture

I am getting the same issue.

xbrianx’s picture

I tried the patch but am still getting the notice on commerce checkouts

fabul’s picture

Bonjour,
Dans le fichier sites/all/modules/rate/expiration/rate_expiration.module
remplacer
$timezone = is_null($user->timezone) ? variable_get('date_default_timezone', 0) : $user->timezone;
Par
$timezone = (!isset($user->timezone)||is_null($user->timezone)) ? variable_get('date_default_timezone', 0) : $user->timezone;
Et le module fonctionnera mieux.
J'espère que cette solution permettra aux auteurs de corriger le module.

xbrianx’s picture

That replacement worked Kalamityjane

leymannx’s picture

Issue summary: View changes

#4 worked! Even in French ;) Thank you.

DamienMcKenna’s picture

Status: Patch (to be ported) » Needs review

@InternetDevels: Please set the issue status to "Needs review" when you upload a patch, that way people know that there's a patch that needs review. Only change the status to "Patch (to be ported)" when there's an existing patch for one branch that needs to be ported to another branch, e.g. if someone fixes a bug for 7.x-1.x and the patch needs to be backported to 6.x-1.x.

DamienMcKenna’s picture

Version: 7.x-1.3 » 7.x-1.x-dev

Lets see if this can be tested against the current 7.x-1.x codebase.

nicrodgers’s picture

I suggest changing is_null() to empty() as this handles the case where we have an empty string. (I had this whilst reacting on a commerce checkout rule).

Here's a patch that converts the three is_null($user->timezone) ifs to empty(), which seems to work for me.

brad.bulger’s picture

applied the patch in 9 to 1.7 and it's working fine for me.

erwangel’s picture

Patch #9 applied to 1.7 working for me also. By the occasion, I think the test
$timezone = empty($user->timezone) ? variable_get('date_default_timezone', 0) : $user->timezone;
near line 203, inside the foreach ($widgets as $widget) { is unnecessary because it is already done at the beginning of the function just some lines before.

RoloDMonkey’s picture

@erwangel,

I agree with you, but can you file a separate issue for refactoring that code?

RoloDMonkey’s picture

Status: Needs review » Reviewed & tested by the community

I ran into this notice-level error today while running Behat tests. The patch in comment #9 worked for me. Setting to RTBC.