The function failing is at nws_weather.module lines 976-989:

/**
 *
 */
function nws_weather_override_image($image) {
  if ($override = variable_get('nws_weather_override_bool', 0)) {
    $result = db_query("SELECT img FROM {nws_weather_config} WHERE url = '%s'", $image);
    $row = db_fetch_array($result);
    $directory = variable_get('nws_weather_override_directory', NWS_WEATHER_OVERRIDE_DIRECTORY_DEFAULT);
    // Need $override switch set before will override image.
    if ($override && $fname = $row['img']) {
      $image = $directory . '/' . $fname;
    }
  }
  return $image;

The db_query and db_fetch_array calls are both still formatted for D6 and fail with D7. db_query expects arguments to be passed in an array and db_fetch_array no longer is supported in D7. The changes below pass the query argument in an array, replace the db_fetch_array with a $result->fetchfield(), and inserts a test to see if the field was successfully retrieved.

I changed the function to:

/**
 *
 */
 function nws_weather_override_image($image) {
     if ($override = variable_get('nws_weather_override_bool', 0)) {
         $result = db_query('SELECT n.img FROM {nws_weather_config} n WHERE n.url = :url', array(':url'=>$image));
         $newimage = $result->fetchfield();
         if ($newimage) {
             $directory = variable_get('nws_weather_override_directory', NWS_WEATHER_OVERRIDE_DIRECTORY_DEFAULT);
             // Need $override switch set before will override image.
             if ($override && $fname = $newimage) {
                 $image = $directory . '/' . $fname;
             }
         }
     }
     return $image;

One of these days I'm going to figure out how to develop a patch! For now, this will have to do.

Comments

jimsmith’s picture

Status: Active » Needs review
StatusFileSize
new1.46 KB

Here's a patch of @David4514's fix. Looks to me like it works.

dwaine’s picture

Assigned: Unassigned » dwaine
Status: Needs review » Active

Thank you for debugging my relatively obvious bug. If nothing else the length of time this bug stayed hidden demonstrates how few users are choosing to override the default images. I have updated the code in the version control system and the next release will include this bug fix.

juahoo’s picture

I had this issue in a fresh install of 7.x-1.3. I applied the patch and it corrected the error.

  • dwaine committed 6672bd5 on 8.x-1.x
    Issue #1333034 by Dwaine: Updated D6 query code to D7 query code.
    
    
jerry’s picture

Status: Active » Reviewed & tested by the community

Patch is working here as well, so marking as RTBC. Note: this patch must be applied from Drupal root.

spacemuon’s picture

Comment #1 patch worked for me. Thanks JimSmith.

Note: Applied patch from the sites/all/modules/nws_weather directory.

aaronrus’s picture

Status: Reviewed & tested by the community » Closed (outdated)

Closing as outdated — the branch this issue was reported against is no longer supported. The module is now maintained on the 2.x-dev branch.

Thank you for your report!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.