diff --git a/analytics/classes/analysable.php b/analytics/classes/analysable.php index 968de63f683..bbcebd5c465 100644 --- a/analytics/classes/analysable.php +++ b/analytics/classes/analysable.php @@ -39,7 +39,7 @@ interface analysable { * Max timestamp. * We are limited by both PHP's max int value and DB (cross-db) max int allowed. Use the smallest one. */ - const MAX_TIME = PHP_INT_MAX < 9999999999 ? PHP_MAX_INT : 9999999999; + const MAX_TIME = PHP_INT_MAX < SQL_INT_MAX ? PHP_INT_MAX : SQL_INT_MAX; /** * The analysable unique identifier in the site. diff --git a/analytics/classes/site.php b/analytics/classes/site.php index c503e8aeeff..5beeaa9a5ee 100644 --- a/analytics/classes/site.php +++ b/analytics/classes/site.php @@ -84,7 +84,7 @@ class site implements \core_analytics\analysable { // Much faster than reading the first log in the site. $admins = get_admins(); - $this->start = 9999999999; + $this->start = self::MAX_TIME; foreach ($admins as $admin) { if ($admin->firstaccess < $this->start) { $this->start = $admin->firstaccess; diff --git a/badges/classes/reportbuilder/local/entities/badge.php b/badges/classes/reportbuilder/local/entities/badge.php index f1b9aa7c7f4..46d31a1da43 100644 --- a/badges/classes/reportbuilder/local/entities/badge.php +++ b/badges/classes/reportbuilder/local/entities/badge.php @@ -326,17 +326,17 @@ class badge extends base { ]); // Expiry date/period. - [$parammaxint, $paramtime] = database::generate_param_names(2); + $paramtime = database::generate_param_name(); $filters[] = (new filter( date::class, 'expiry', new lang_string('expirydate', 'core_badges'), $this->get_entity_name(), "CASE WHEN {$badgealias}.expiredate IS NULL AND {$badgealias}.expireperiod IS NULL - THEN " . $DB->sql_cast_char2int(":{$parammaxint}") . " + THEN " . SQL_INT_MAX . " ELSE COALESCE({$badgealias}.expiredate, {$badgealias}.expireperiod + :{$paramtime}) END", - [$parammaxint => 2147483647, $paramtime => time()] + [$paramtime => time()] )) ->add_joins($this->get_joins()) ->set_limited_operators([ diff --git a/enrol/meta/locallib.php b/enrol/meta/locallib.php index 74a604f18e3..5ee305f2200 100644 --- a/enrol/meta/locallib.php +++ b/enrol/meta/locallib.php @@ -301,9 +301,9 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) { list($enabled, $params) = $DB->get_in_or_equal(explode(',', $CFG->enrol_plugins_enabled), SQL_PARAMS_NAMED, 'e'); $params['courseid'] = $courseid; $sql = "SELECT pue.userid, e.id AS enrolid, MIN(pue.status + pe.status) AS status, - MIN(CASE WHEN (pue.status + pe.status = 0) THEN pue.timestart ELSE 9999999999 END) AS timestart, + MIN(CASE WHEN (pue.status + pe.status = 0) THEN pue.timestart ELSE " . SQL_INT_MAX . " END) AS timestart, MAX(CASE WHEN (pue.status + pe.status = 0) THEN - (CASE WHEN pue.timeend = 0 THEN 9999999999 ELSE pue.timeend END) + (CASE WHEN pue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE pue.timeend END) ELSE 0 END) AS timeend FROM {user_enrolments} pue JOIN {enrol} pe ON (pe.id = pue.enrolid AND pe.enrol <> 'meta' AND pe.enrol $enabled) @@ -341,9 +341,9 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) { // Again, we use the fact that active=0 and disabled/suspended=1. Only when MIN(pue.status + pe.status)=0 the enrolment is active: $ue->status = ($ue->status == ENROL_USER_ACTIVE + ENROL_INSTANCE_ENABLED) ? ENROL_USER_ACTIVE : ENROL_USER_SUSPENDED; // Timeend 9999999999 was used instead of 0 in the "MAX()" function: - $ue->timeend = ($ue->timeend == 9999999999) ? 0 : (int)$ue->timeend; + $ue->timeend = ($ue->timeend == SQL_INT_MAX) ? 0 : (int)$ue->timeend; // Timestart 9999999999 is only possible when there are no active enrolments: - $ue->timestart = ($ue->timestart == 9999999999) ? 0 : (int)$ue->timestart; + $ue->timestart = ($ue->timestart == SQL_INT_MAX) ? 0 : (int)$ue->timestart; $meta->enrol_user($instance, $ue->userid, null, $ue->timestart, $ue->timeend, $ue->status); if ($instance->customint2 && $group = $DB->get_record('groups', ['id' => $instance->customint2])) { @@ -418,9 +418,9 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) { // the start and end time. $sql = "SELECT ue.userid, ue.enrolid, MIN(xpue.status + xpe.status) AS pstatus, - MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE 9999999999 END) AS ptimestart, + MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE " . SQL_INT_MAX . " END) AS ptimestart, MAX(CASE WHEN (xpue.status + xpe.status = 0) THEN - (CASE WHEN xpue.timeend = 0 THEN 9999999999 ELSE xpue.timeend END) + (CASE WHEN xpue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE xpue.timeend END) ELSE 0 END) AS ptimeend FROM {user_enrolments} ue JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'meta' $onecourse) @@ -431,17 +431,18 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) { HAVING (MIN(xpue.status + xpe.status) = 0 AND MIN(ue.status) > 0) OR (MIN(xpue.status + xpe.status) > 0 AND MIN(ue.status) = 0) OR ((CASE WHEN - MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE 9999999999 END) = 9999999999 - THEN 0 - ELSE - MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE 9999999999 END) - END) <> MIN(ue.timestart)) + MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE " . SQL_INT_MAX . " END) = " . + SQL_INT_MAX . " + THEN 0 + ELSE + MIN(CASE WHEN (xpue.status + xpe.status = 0) THEN xpue.timestart ELSE " . SQL_INT_MAX . " END) + END) <> MIN(ue.timestart)) OR ((CASE WHEN MAX(CASE WHEN (xpue.status + xpe.status = 0) - THEN (CASE WHEN xpue.timeend = 0 THEN 9999999999 ELSE xpue.timeend END) - ELSE 0 END) = 9999999999 + THEN (CASE WHEN xpue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE xpue.timeend END) + ELSE 0 END) = " . SQL_INT_MAX . " THEN 0 ELSE MAX(CASE WHEN (xpue.status + xpe.status = 0) - THEN (CASE WHEN xpue.timeend = 0 THEN 9999999999 ELSE xpue.timeend END) + THEN (CASE WHEN xpue.timeend = 0 THEN " . SQL_INT_MAX . " ELSE xpue.timeend END) ELSE 0 END) END) <> MAX(ue.timeend))"; $rs = $DB->get_recordset_sql($sql, $params); @@ -451,8 +452,8 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) { } $instance = $instances[$ue->enrolid]; $ue->pstatus = ($ue->pstatus == ENROL_USER_ACTIVE + ENROL_INSTANCE_ENABLED) ? ENROL_USER_ACTIVE : ENROL_USER_SUSPENDED; - $ue->ptimeend = ($ue->ptimeend == 9999999999) ? 0 : (int)$ue->ptimeend; - $ue->ptimestart = ($ue->ptimestart == 9999999999) ? 0 : (int)$ue->ptimestart; + $ue->ptimeend = ($ue->ptimeend == SQL_INT_MAX) ? 0 : (int)$ue->ptimeend; + $ue->ptimestart = ($ue->ptimestart == SQL_INT_MAX) ? 0 : (int)$ue->ptimestart; if ($ue->pstatus == ENROL_USER_ACTIVE and (!$ue->ptimeend || $ue->ptimeend > time()) and !$syncall and $unenrolaction != ENROL_EXT_REMOVED_UNENROL) { diff --git a/lib/tests/analytics/indicators_test.php b/lib/tests/analytics/indicators_test.php index f2a11eb1e02..c0f479d496a 100644 --- a/lib/tests/analytics/indicators_test.php +++ b/lib/tests/analytics/indicators_test.php @@ -86,8 +86,8 @@ class indicators_test extends \advanced_testcase { // Test any access before start. $params = array( - 'startdate' => 9999999998, - 'enddate' => 9999999999 + 'startdate' => SQL_INT_MAX - 1, + 'enddate' => SQL_INT_MAX, ); // Resetting $course var. $course = $this->getDataGenerator()->create_course($params); diff --git a/lib/tests/context_helper_test.php b/lib/tests/context_helper_test.php index 7033d52a2af..52140a19a25 100644 --- a/lib/tests/context_helper_test.php +++ b/lib/tests/context_helper_test.php @@ -281,7 +281,7 @@ class context_helper_test extends \advanced_testcase { } $record = new \stdClass(); $record->contextlevel = $classname::LEVEL; - $record->instanceid = 9999999999; + $record->instanceid = SQL_INT_MAX; $record->path = null; $record->depth = '2'; $record->id = $DB->insert_record('context', $record); diff --git a/mod/quiz/tests/local/override_manager_test.php b/mod/quiz/tests/local/override_manager_test.php index caa7e4e949b..2690513a2b0 100644 --- a/mod/quiz/tests/local/override_manager_test.php +++ b/mod/quiz/tests/local/override_manager_test.php @@ -666,7 +666,7 @@ final class override_manager_test extends \advanced_testcase { 'existing id given to update is invalid' => [ 'existingdata' => [], 'formdata' => [ - 'id' => 999999999999, + 'id' => SQL_INT_MAX, 'userid' => ':userid', 'groupid' => null, 'timeopen' => 50,