### Eclipse Workspace Patch 1.0
#P leaguesite
Index: leaguesite_match/leaguesite_match.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/leaguesite/leaguesite_match/leaguesite_match.module,v
retrieving revision 1.4
diff -u -r1.4 leaguesite_match.module
--- leaguesite_match/leaguesite_match.module	27 Jan 2010 00:34:14 -0000	1.4
+++ leaguesite_match/leaguesite_match.module	27 Jan 2010 07:50:30 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: leaguesite_match.module,v 1.4 2010/01/27 00:34:14 alun Exp $
+// $Id$
 
 /**
 * Implementation of hook_perm()
@@ -232,11 +232,8 @@
     if($match['home_score'] != $node->home_score || $match['away_score'] != $node->away_score){
       //delete old score values
       _leaguesite_match_update_table($match['home_team'], $match['away_team'], $match['home_score'], $match['away_score'], $match['relation_id'], 'delete'); 
+      _leaguesite_match_update_table($node->home_team, $node->away_team, $node->home_score, $node->away_score, $node->season_league);
     }
-    //insert values anyway
-    
-    _leaguesite_match_update_table($node->home_team, $node->away_team, $node->home_score, $node->away_score, $node->season_league);
-
   } 
   $match_time = mktime($node->match_hour, $node->match_minute, 0, intval($node->match_time['month']), intval($node->match_time['day']), intval($node->match_time['year']));
   db_query("UPDATE {leaguesite_match} SET home_team = %d, away_team = %d, match_time = %d, home_score = %d, away_score = %d, relation_id = %d WHERE nid = %d;", intval($node->home_team), intval($node->away_team), check_plain($match_time), intval($node->home_score), intval($node->away_score), intval($node->season_league), intval($node->nid));
@@ -251,19 +248,17 @@
   $match = db_fetch_array(db_query("SELECT * FROM {leaguesite_match} WHERE nid = %d", intval($node->nid)));
   //check if a match result exists. If so, check if we should udpate the league tables to reflect the deletion of the match
   if($match['home_score'] != '' && $match['away_score'] != '' && variable_get('leaguesite_match_update_table_delete', '') == TRUE){
-    _leaguesite_match_update_table($node->home_team, $node->away_team, $node->home_score, $node->away_score, $match['relation_id'], "delete");
+    //node is not completely built here, only basic information is available, so we use the database info instead.
+    _leaguesite_match_update_table($match['home_team'], $match['away_team'], $match['home_score'], $match['away_score'], $match['relation_id'], 'delete');
   }
   
   db_query("DELETE FROM {leaguesite_match} WHERE nid = %d", intval($node->nid));
 }
 
 function _leaguesite_match_update_table($home_team, $away_team, $home_score, $away_score, $relation_id, $op = "insert"){
-  //TODO: The delete operation does not remove games effectively
   $home_standing = db_fetch_array(db_query("SELECT * FROM {leaguesite_standings} WHERE relation_id = %d AND team_id = %d;", intval($relation_id), intval($home_team)));
   $away_standing = db_fetch_array(db_query("SELECT * FROM {leaguesite_standings} WHERE relation_id = %d AND team_id = %d;", intval($relation_id), intval($away_team)));
-  //print_r($home_standing);
-  //print_r($away_standing);
-  //die();
+
   if(!$home_standing || !$away_standing){
     //we have a problem..
   }
