Merge branch 'MDL-78327_401' of https://github.com/timhunt/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols 2023-06-01 10:52:47 +08:00
commit 036cb9a997
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
2 changed files with 6 additions and 5 deletions

View File

@ -272,11 +272,11 @@ class all_calculated_for_qubaid_condition {
$timemodified = time();
foreach ($this->get_all_slots() as $slot) {
$this->for_slot($slot)->cache($qubaids);
$this->for_slot($slot)->cache($qubaids, $timemodified);
}
foreach ($this->get_all_subq_ids() as $subqid) {
$this->for_subq($subqid)->cache($qubaids);
$this->for_subq($subqid)->cache($qubaids, $timemodified);
}
$transaction->allow_commit();

View File

@ -219,12 +219,13 @@ class calculated {
* Cache calculated stats stored in this object in 'question_statistics' table.
*
* @param \qubaid_condition $qubaids
* @param int|null $timemodified the modified time to store. Defaults to the current time.
*/
public function cache($qubaids) {
public function cache($qubaids, $timemodified = null) {
global $DB;
$toinsert = new \stdClass();
$toinsert->hashcode = $qubaids->get_hash_code();
$toinsert->timemodified = time();
$toinsert->timemodified = $timemodified ?? time();
foreach ($this->fieldsindb as $field) {
$toinsert->{$field} = $this->{$field};
}
@ -232,7 +233,7 @@ class calculated {
if ($this->get_variants()) {
foreach ($this->variantstats as $variantstat) {
$variantstat->cache($qubaids);
$variantstat->cache($qubaids, $timemodified);
}
}
}