Skip to content

Commit f3d288b

Browse files
committed
Prevent errors because of faulty DB records
Previous versions introduced records with groupid=0 into the ratingallocate_ch_gengroups table which caused problems with the groups/choices synchronization/allocation feature. This fix deals with the faulty records by deleting them and also handling them defensively during record retrieval. However, the root cause of these faulty records has not been fixed extensively. This has to be investigated further. Fixes: #330 References: #308, #316, #330
1 parent 25cc001 commit f3d288b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

classes/ratingallocate.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,19 @@ public function synchronize_allocation_and_grouping() {
15501550

15511551
// Fix for github bug issue #316. Delete bad dataset with groupingid=0 after backup and restore without groups/groupings.
15521552
$where = "ratingallocateid = $this->ratingallocateid AND groupingid = 0";
1553-
$DB->delete_records_select(this_db\ratingallocate_groupings::TABLE, $where);
1553+
$this->db->delete_records_select(this_db\ratingallocate_groupings::TABLE, $where);
1554+
1555+
/* Delete records with invalid group ids introduced via faulty
1556+
* backup/restore process.
1557+
*
1558+
* FIXME: Do not introduce records with groupid = 0 during
1559+
* backup/restore
1560+
*/
1561+
$this->db->delete_records(
1562+
this_db\ratingallocate_ch_gengroups::TABLE,
1563+
['groupid' => 0]
1564+
);
1565+
15541566
// Search if there is already a grouping from us.
15551567
$where = "ratingallocateid = $this->ratingallocateid AND groupingid <> 0";
15561568
if (!$groupingids = $this->db->get_record_select(this_db\ratingallocate_groupings::TABLE, $where, [], 'groupingid')) {
@@ -1619,8 +1631,10 @@ public function synchronize_allocation_and_grouping() {
16191631
$choiceid = $allocation->choiceid;
16201632
$userid = $allocation->userid;
16211633
// Get the group corresponding to the choiceid.
1622-
$groupids = $this->db->get_record(
1634+
$groupids = $this->db->get_record_select(
16231635
this_db\ratingallocate_ch_gengroups::TABLE,
1636+
// Filter out records with groupip=0 which might exists because of backup/restore.
1637+
'choiceid = :choiceid AND groupid <> 0',
16241638
['choiceid' => $choiceid],
16251639
'groupid'
16261640
);

0 commit comments

Comments
 (0)