I have noticed that in the event that you change the results of a game and change it's status to "Finished" (played), and then later you edit the game itself and change the teams, the stats table does not get updated with the new team IDs. As a result, the stats reflected are incorrect and if you later change the score again it will not be able to update the stats table because it still references the incorrect teams.

This is of course an unusual edge case and not something that would normally happen. However, it can always happen depending on what the site admins do, and in my particular use case I am hiding the game status field and forcing it to always be set to "finished" in the results form because my client does not wish to have their referees modify that field - they want to keep it simple. During the initial setup and testing of the site, people played around putting in fake games, tested editing the results, then later kept those games and just changed the teams to be the correct ones and ensured they had the right date, time etc. Thus I ran into the problem.

Even though this is an edge case and would not normally happen in most leagues, it seems that it should accommodate this edge case because it is possible regardless of whether it's what users would normally do. I will submit a patch to fix this once I have figured out a good solution.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

teknocat’s picture

FileSize
2.04 KB

Here is a patch that can be applied to the league_table module. It has a function that will remove all invalid team stats before doing the new stats calculations. Basically it removes all rows for the game where the team_id doesn't match the teams set for that game. If the game has no teams set, it ensures that all rows for that game in the stats table are removed. Stats are then calculated and it will make sure to save new stats if there are either no existing stats, or no stats for the current team being iterated over.

This is one possible solution, there may be other ways to do it.

teknocat’s picture

FileSize
2.04 KB

Update to the patch so it will ONLY delete stats if one or both game teams are set. The previous patch would always delete the stats for the game before inserting no matter what, which is not necessarily desired.

hatuhay’s picture

Thanks, we have been working around consistency of the result table and come into several issues basically for the same reason as you.
The idea of having 2 forms to edit a game is to separate the results from the administration of the game, allowing also a separate set of permissions.
With this idea in mind the tables are only updated when you save the game on the results form (or minute by minute) and also when you delete a game.
On our case the test games were deleted.
From a mantainance point of view your patch idea (have not seen the code yet) is great because there is a lot of room for the tables to loose synchronization with the games.
Now talking about the refferees, I believe it is a cleaner solution to hook_form_alter the result form disabling the fields for a certain user role, that should two lines of code.

hatuhay’s picture

Assigned: Unassigned » hatuhay
Status: Active » Needs review

The last submitted patch, 1: league_table-2293985.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: league_table-2293985.patch, failed testing.

teknocat’s picture

FileSize
1.77 KB

Here's an updated copy of the patch that can be applied to version 1.8 of the module - and this time should work as it's set to be relative to the main league module directory root. I think that's maybe why the patch failed the test last time.