Reference to a not initialized variable in flag_weights_set_flag()

hefox - June 25, 2009 - 02:13
Project:Flag Weights
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:minor
Assigned:Unassigned
Status:closed
Description

In flag_weights_set_flag it says $handlers instead of $handler when calling flag_weights_set_weight ( $handlers->content_type). Can't see anywhere else where $handlers is used; if this is related to how the module is used, then close this but I can't imagine how that ever worked.

In related (aka how I noticed the typo) popped out this function to flag/weight using an existing flag. (The flag using content type never worked for me btw, don't currently really see the purpose of it).

<?php
function flag_weights_set_flag_with_flag($flag_name, $content_id, $account = NULL, $weight = 0) {
 
$handler flag_get_flag($flag_name) ;
 
$ok = $handler->flag('flag', $content_id, $account);
  if (
$ok && $weight != 0) {
    if (!isset(
$account)) {
     
$account = $GLOBALS['user'];
    }
   
flag_weights_set_weight($handler->fid, $handler->content_type, $content_id, $account->uid, $weight);
  }
  return
$ok;
}
?>

#1

kiamlaluno - July 1, 2009 - 19:15
Title:Possible typo, flag_weights_set_flag» Reference to a not initialized variable in flag_weights_set_flag()

#2

markus_petrux - July 18, 2009 - 19:38
Status:active» reviewed & tested by the community

<?php
-    flag_weights_set_weight($handler->fid, $handlers->content_type, $content_id, $account->uid, $weight);
+   
flag_weights_set_weight($handler->fid, $handler->content_type, $content_id, $account->uid, $weight);
?>

Please, let me know if you wish a proper patch for this.

#3

lyricnz - August 25, 2009 - 22:29
Status:reviewed & tested by the community» needs review

Applied the handler/handlers patch to -dev.

Will consider the new function another day (setting back to "needs review"). Thanks!

#4

lyricnz - August 26, 2009 - 10:41
Status:needs review» fixed

Committed a new method as described above. Agree that flagging by flag-name makes more sense than by content-type, but changing the API now would break anyone who is using it, in unexpected ways.

http://drupal.org/cvs?commit=256248

#5

System Message - September 9, 2009 - 10:50
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.