Skip to content

Commit 0a10eb8

Browse files
committed
issue Wunderbyte-GmbH#1430: remove dependency on tool_mocktesttime
1 parent 591e264 commit 0a10eb8

121 files changed

Lines changed: 286 additions & 455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backup/moodle2/restore_booking_stepslib.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ protected function process_booking_option($data) {
279279
$oldcustomfields = $DB->get_records_sql($sql, $params);
280280
foreach ($oldcustomfields as $cf) {
281281
unset($cf->id);
282-
$cf->timecreated = time();
283-
$cf->timemodified = time();
282+
$cf->timecreated = \core\di::get(\core\clock::class)->time();
283+
$cf->timemodified = \core\di::get(\core\clock::class)->time();
284284
$cf->instanceid = $newitemid;
285285
$DB->insert_record('customfield_data', $cf);
286286
}
@@ -511,7 +511,7 @@ protected function process_booking_option_entity($data) {
511511
throw new moodle_exception('entityrelationhasinvalidarea');
512512
}
513513
$data->instanceid = $this->get_mappingid('booking_option', $data->instanceid);
514-
$data->timecreated = time();
514+
$data->timecreated = \core\di::get(\core\clock::class)->time();
515515
$DB->insert_record('local_entities_relations', $data);
516516
// No need to save this mapping as far as nothing depends on it.
517517
}
@@ -536,7 +536,7 @@ protected function process_booking_optiondate_entity($data) {
536536
throw new moodle_exception('entityrelationhasinvalidarea');
537537
}
538538
$data->instanceid = $this->get_mappingid('booking_optiondate', $data->instanceid);
539-
$data->timecreated = time();
539+
$data->timecreated = \core\di::get(\core\clock::class)->time();
540540
$DB->insert_record('local_entities_relations', $data);
541541
// No need to save this mapping as far as nothing depends on it.
542542
}
@@ -554,8 +554,8 @@ protected function process_booking_subbookingoption($data) {
554554
if (get_config('booking', 'duplicationrestoresubbookings')) {
555555
$data = (object) $data;
556556
$data->optionid = $this->get_mappingid('booking_option', $data->optionid);
557-
$data->timecreated = time();
558-
$data->timemodified = time();
557+
$data->timecreated = \core\di::get(\core\clock::class)->time();
558+
$data->timemodified = \core\di::get(\core\clock::class)->time();
559559
$data->usermodified = $USER->id;
560560
$DB->insert_record('booking_subbooking_options', $data);
561561
}
@@ -616,8 +616,8 @@ protected function process_booking_option_shoppingcartiteminfo($data) {
616616
return;
617617
}
618618
$data->itemid = $this->get_mappingid('booking_option', $data->itemid);
619-
$data->timecreated = time();
620-
$data->timemodified = time();
619+
$data->timecreated = \core\di::get(\core\clock::class)->time();
620+
$data->timemodified = \core\di::get(\core\clock::class)->time();
621621
$DB->insert_record('local_shopping_cart_iteminfo', $data);
622622
// No need to save this mapping as far as nothing depends on it.
623623
}

classes/all_userbookings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ private function get_certificates_for_row(stdClass $values): array {
750750
public function col_certificate(stdClass $values) {
751751
$checkmark = '✅ ';
752752
$cross = '❌ ';
753-
$now = time();
753+
$now = \core\di::get(\core\clock::class)->time();
754754

755755
$certificates = $this->get_certificates_for_row($values);
756756
if (empty($certificates)) {

classes/bo_actions/action_types/userprofilefield.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function apply_action(stdClass $actiondata, int $userid = 0) {
105105
if (!empty($startstring)) {
106106
$startdate = strtotime($startstring, time());
107107
} else if (empty($startdate)) {
108-
$startdate = time();
108+
$startdate = \core\di::get(\core\clock::class)->time();
109109
}
110110

111111
$user->{$key} = userdate($startdate) . " - " . userdate($enddate);

classes/bo_availability/conditions/booking_time.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function is_skippable(): bool {
114114
*/
115115
public function is_available(booking_option_settings $settings, int $userid, bool $not = false): bool {
116116

117-
$now = time();
117+
$now = \core\di::get(\core\clock::class)->time();
118118

119119
// Here, the logic is easier when we set available to true first.
120120
$isavailable = true;

classes/bo_availability/conditions/cancelmyself.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function is_skippable(): bool {
111111
public function is_available(booking_option_settings $settings, int $userid, bool $not = false): bool {
112112

113113
$optionid = $settings->id;
114-
$now = time();
114+
$now = \core\di::get(\core\clock::class)->time();
115115

116116
// This is the return value. Not available to begin with.
117117
$isavailable = false;
@@ -126,7 +126,7 @@ public function is_available(booking_option_settings $settings, int $userid, boo
126126
}
127127

128128
// Check if the option has its own canceluntil date and if it has already passed.
129-
$now = time();
129+
$now = \core\di::get(\core\clock::class)->time();
130130
$canceluntil = booking_option::get_value_of_json_by_key($optionid, 'canceluntil');
131131
if (!empty($canceluntil) && $now > $canceluntil) {
132132
return true;

classes/bo_availability/conditions/optionhasstarted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function is_available(booking_option_settings $settings, int $userid, boo
122122
} else if (!empty($settings->coursestarttime)) {
123123
// In this case, we have to check if the booking option has already started.
124124
$start = $settings->coursestarttime;
125-
$now = time();
125+
$now = \core\di::get(\core\clock::class)->time();
126126
$isavailable = $now > $start ? false : true;
127127
} else {
128128
$isavailable = true;

classes/booking_answers/booking_answers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public function get_count_of_answers_for_user(int $userid, int $bookingid) {
809809

810810
// If the config setting 'maxperuserdontcountpassed' is set, we don't count passed bookings.
811811
if (get_config('booking', 'maxperuserdontcountpassed')) {
812-
$now = time();
812+
$now = \core\di::get(\core\clock::class)->time();
813813
foreach ($answers as $key => $answer) {
814814
if (!empty($answer->courseendtime) && $answer->courseendtime < $now) {
815815
unset($answers[$key]);

classes/booking_bookit.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,21 @@ public static function bookit(string $area, int $itemid, int $userid = 0, string
303303
} else if ($id === MOD_BOOKING_BO_COND_BOOKITBUTTON) {
304304
$cache = cache::make('mod_booking', 'confirmbooking');
305305
$cachekey = $userid . "_" . $settings->id . "_bookit";
306-
$now = time();
306+
$now = \core\di::get(\core\clock::class)->time();
307307
$cache->set($userid, [$cachekey => $now]);
308308

309309
$isavailable = false;
310310
} else if ($id === MOD_BOOKING_BO_COND_BOOKWITHCREDITS) {
311311
$cache = cache::make('mod_booking', 'confirmbooking');
312312
$cachekey = $userid . "_" . $settings->id . "_bookwithcredits";
313-
$now = time();
313+
$now = \core\di::get(\core\clock::class)->time();
314314
$cache->set($userid, [$cachekey => $now]);
315315

316316
$isavailable = false;
317317
} else if ($id === MOD_BOOKING_BO_COND_BOOKWITHSUBSCRIPTION) {
318318
$cache = cache::make('mod_booking', 'confirmbooking');
319319
$cachekey = $userid . "_" . $settings->id . "_bookwithsubscription";
320-
$now = time();
320+
$now = \core\di::get(\core\clock::class)->time();
321321
$cache->set($userid, [$cachekey => $now]);
322322

323323
$isavailable = false;
@@ -364,7 +364,7 @@ public static function bookit(string $area, int $itemid, int $userid = 0, string
364364
} else if ($id === MOD_BOOKING_BO_COND_ASKFORCONFIRMATION) {
365365
$cache = cache::make('mod_booking', 'confirmbooking');
366366
$cachekey = $userid . "_" . $settings->id . "_confirmation";
367-
$now = time();
367+
$now = \core\di::get(\core\clock::class)->time();
368368
$cache->set($userid, [$cachekey => $now]);
369369

370370
$isavailable = false;
@@ -386,7 +386,7 @@ public static function bookit(string $area, int $itemid, int $userid = 0, string
386386
// If the cancel condition is blocking here, we can actually mark the option for cancelation.
387387
$cache = cache::make('mod_booking', 'confirmbooking');
388388
$cachekey = $userid . "_" . $settings->id . "_cancel";
389-
$now = time();
389+
$now = \core\di::get(\core\clock::class)->time();
390390
$cache->set($userid, [$cachekey => $now]);
391391
}
392392
} else if ($id === MOD_BOOKING_BO_COND_CONFIRMCANCEL) {

classes/booking_campaigns/campaigns_info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ public static function check_if_campaign_is_active(
535535
string $operator
536536
): bool {
537537
$isactive = false;
538-
$now = time();
538+
$now = \core\di::get(\core\clock::class)->time();
539539
if ($starttime <= $now && $now <= $endtime) {
540540
if (!empty($fieldname)) {
541541
if (is_string($fieldname) && $fieldname === $fieldvalue) {

classes/booking_option.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public function user_delete_response(
773773
!in_array($result->waitinglist, [MOD_BOOKING_STATUSPARAM_DELETED, MOD_BOOKING_STATUSPARAM_PREVIOUSLYBOOKED])
774774
) {
775775
$result->waitinglist = MOD_BOOKING_STATUSPARAM_DELETED;
776-
$result->timemodified = time();
776+
$result->timemodified = \core\di::get(\core\clock::class)->time();
777777
$result->openruleexecution = $openruleexecution ? time() : 0;
778778
// We mark all the booking answers as deleted.
779779
$DB->update_record('booking_answers', $result);
@@ -1524,7 +1524,7 @@ public static function write_user_answer_to_db(
15241524
) {
15251525

15261526
global $DB, $USER;
1527-
$now = time();
1527+
$now = \core\di::get(\core\clock::class)->time();
15281528

15291529
// For book with credits, we need to delete the cache.
15301530
$settings = singleton_service::get_instance_of_booking_option_settings($optionid);
@@ -1565,7 +1565,7 @@ public static function write_user_answer_to_db(
15651565
!empty($settings->selflearningcourse)
15661566
&& empty($currentanswerid) // We don't override on checkout.
15671567
) {
1568-
$now = time();
1568+
$now = \core\di::get(\core\clock::class)->time();
15691569
$duration = $settings->duration ?? 0;
15701570
$end = empty($duration) ? 0 : $now + $duration;
15711571
self::add_data_to_json($newanswer, 'selflearningendofsubscription', $end);
@@ -1601,18 +1601,18 @@ public static function write_user_answer_to_db(
16011601
$tm = self::get_data_from_json($answer, 'confirmwaitinglist_timemodified');
16021602
if (is_array($tm)) { // If it is an array, we just add new time to it.
16031603
$timemodified = $tm;
1604-
$timemodified[] = time();
1604+
$timemodified[] = \core\di::get(\core\clock::class)->time();
16051605
} else if (is_numeric($tm)) { // If it is a number we chnaged it to array of number and then we add new value.
16061606
$timemodified = [(int) $tm];
1607-
$timemodified[] = time();
1607+
$timemodified[] = \core\di::get(\core\clock::class)->time();
16081608
} else {
16091609
$timemodified = [];
1610-
$timemodified[] = time();
1610+
$timemodified[] = \core\di::get(\core\clock::class)->time();
16111611
}
16121612
} else {
16131613
$confirmationcount = 1;
16141614
$modifieduserid[] = $USER->id;
1615-
$timemodified[] = time();
1615+
$timemodified[] = \core\di::get(\core\clock::class)->time();
16161616
}
16171617

16181618
// The confirmation on the waitinglist is saved here.
@@ -1717,7 +1717,7 @@ public function user_confirm_response(stdClass $user): bool {
17171717
);
17181718
} else {
17191719
// When it's the first reserveration, we just confirm it.
1720-
$currentanswer->timemodified = time();
1720+
$currentanswer->timemodified = \core\di::get(\core\clock::class)->time();
17211721
$currentanswer->waitinglist = MOD_BOOKING_STATUSPARAM_BOOKED;
17221722

17231723
self::write_user_answer_to_db(
@@ -2039,7 +2039,7 @@ public function enrol_user(
20392039
// Timecreated is not a perfect solution, because users could have been on the waitinglist.
20402040
$now = $ba->timecreated;
20412041
} else {
2042-
$now = time();
2042+
$now = \core\di::get(\core\clock::class)->time();
20432043
}
20442044

20452045
$duration = $this->settings->duration ?? 0;
@@ -3026,7 +3026,7 @@ public function confirmactivity(?int $userid = null) {
30263026
['optionid' => $this->optionid, 'userid' => $userid, 'waitinglist' => MOD_BOOKING_STATUSPARAM_BOOKED]
30273027
);
30283028
$userdata->completed = '1';
3029-
$userdata->timemodified = time();
3029+
$userdata->timemodified = \core\di::get(\core\clock::class)->time();
30303030

30313031
$DB->update_record('booking_answers', $userdata);
30323032

@@ -3599,7 +3599,7 @@ public function show_conference_link(?int $sessionid = null): bool {
35993599
return false;
36003600
}
36013601

3602-
$now = time();
3602+
$now = \core\di::get(\core\clock::class)->time();
36033603
$openingtime = strtotime("+15 minutes", $now);
36043604

36053605
if (!$sessionid) {
@@ -3725,7 +3725,7 @@ public static function cancelbookingoption(
37253725

37263726
$settings = singleton_service::get_instance_of_booking_option_settings($optionid);
37273727

3728-
$now = time();
3728+
$now = \core\di::get(\core\clock::class)->time();
37293729

37303730
$record = $DB->get_record('booking_options', ['id' => $optionid]);
37313731

@@ -3782,7 +3782,7 @@ public static function cancelbookingoption(
37823782
public static function get_consumed_quota(int $optionid) {
37833783

37843784
$optionsettings = singleton_service::get_instance_of_booking_option_settings($optionid);
3785-
$now = time();
3785+
$now = \core\di::get(\core\clock::class)->time();
37863786
$consumedquota = 0.0;
37873787

37883788
if (empty($optionsettings->sessions)) {

0 commit comments

Comments
 (0)