Skip to content

Commit 7d21eb8

Browse files
committed
Admin: Modify default expiration date behaviour to avoid adding default expiration period when selecting "Never expires". Affects CSV import and user creation/edition forms - refs #5538
1 parent 056f3fa commit 7d21eb8

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

main/admin/user_add.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,13 @@ function setExpirationDatePicker(status) {
397397
}
398398

399399
if ($user['radio_expiration_date'] == '1') {
400-
$expiration_date = $user['expiration_date'];
400+
if (!empty($user['expiration_date'])) {
401+
$expiration_date = $user['expiration_date'];
402+
} else {
403+
if (!empty($days)) {
404+
$expiration_date = api_get_local_time('+'.$days.' day');
405+
}
406+
}
401407
} else {
402408
$expiration_date = null;
403409
}

main/admin/user_edit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ function confirmation(name) {
421421

422422
if (empty($expiration_date)) {
423423
$user_data['radio_expiration_date'] = 0;
424-
$user_data['expiration_date'] = api_get_local_time();
424+
$days = api_get_setting('account_valid_duration');
425+
$user_data['expiration_date'] = api_get_local_time('+'.$days.' day');
425426
} else {
426427
$user_data['radio_expiration_date'] = 1;
427428
$user_data['expiration_date'] = api_get_local_time($expiration_date);

main/cron/import_csv.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,6 @@ private function importTeachers($file, $moveFile = true)
715715

716716
if (!empty($data)) {
717717
$this->logger->addInfo(count($data)." records found.");
718-
$expirationDateOnCreation = api_get_utc_datetime(strtotime("+".intval($this->expirationDateInUserCreation)."years"));
719-
$expirationDateOnUpdate = api_get_utc_datetime(strtotime("+".intval($this->expirationDateInUserUpdate)."years"));
720718

721719
$batchSize = $this->batchSize;
722720
$em = Database::getManager();
@@ -752,7 +750,7 @@ private function importTeachers($file, $moveFile = true)
752750
$row['phone'],
753751
null, //$row['picture'], //picture
754752
$row['auth_source'], // ?
755-
$expirationDateOnCreation, //'0000-00-00 00:00:00', //$row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
753+
null,
756754
1, //active
757755
0,
758756
null, // extra
@@ -800,7 +798,7 @@ private function importTeachers($file, $moveFile = true)
800798
$userInfo['official_code'],
801799
$userInfo['phone'],
802800
$userInfo['picture_uri'],
803-
$expirationDateOnUpdate,
801+
null,
804802
$userInfo['active'],
805803
null, //$creator_id = null,
806804
0, //$hr_dept_id = 0,
@@ -892,13 +890,6 @@ private function importStudents($file, $moveFile = true)
892890
$language = $this->defaultLanguage;
893891
$this->logger->addInfo(count($data)." records found.");
894892

895-
$expirationDateOnCreate = api_get_utc_datetime(
896-
strtotime("+".intval($this->expirationDateInUserCreation)."years")
897-
);
898-
$expirationDateOnUpdate = api_get_utc_datetime(
899-
strtotime("+".intval($this->expirationDateInUserUpdate)."years")
900-
);
901-
902893
$counter = 1;
903894
$secondsInYear = 365 * 24 * 60 * 60;
904895

@@ -965,7 +956,7 @@ private function importStudents($file, $moveFile = true)
965956
$row['phone'],
966957
null, //$row['picture'], //picture
967958
$row['auth_source'], // ?
968-
$expirationDateOnCreate,
959+
null,
969960
1, //active
970961
0,
971962
null, // extra
@@ -1000,11 +991,6 @@ private function importStudents($file, $moveFile = true)
1000991
continue;
1001992
}
1002993

1003-
if (isset($row['action']) && $row['action'] === 'delete') {
1004-
// Inactive one year later
1005-
$userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + $secondsInYear));
1006-
}
1007-
1008994
$password = $row['password']; // change password
1009995
$email = $row['email']; // change email
1010996
$resetPassword = 2; // allow password change
@@ -1075,7 +1061,7 @@ private function importStudents($file, $moveFile = true)
10751061
$userInfo['official_code'],
10761062
$userInfo['phone'],
10771063
$userInfo['picture_uri'],
1078-
$expirationDateOnUpdate,
1064+
null,
10791065
$userInfo['active'],
10801066
null, //$creator_id = null,
10811067
0, //$hr_dept_id = 0,

main/inc/lib/usermanager.lib.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,11 @@ public static function create_user(
457457
if (empty($expirationDate) || $expirationDate == '0000-00-00 00:00:00') {
458458
// Default expiration date
459459
// if there is a default duration of a valid account then
460-
// we have to change the expiration_date accordingly
460+
// the expiration_date has to be set taking it into account before calling create_user()
461461
// Accept 0000-00-00 00:00:00 as a null value to avoid issues with
462462
// third party code using this method with the previous (pre-1.10)
463463
// value of 0000...
464-
if (api_get_setting('account_valid_duration') != '') {
465-
$expirationDate = new DateTime($currentDate);
466-
$days = (int) api_get_setting('account_valid_duration');
467-
$expirationDate->modify('+'.$days.' day');
468-
}
464+
$expirationDate = null;
469465
} else {
470466
$expirationDate = api_get_utc_datetime($expirationDate);
471467
$expirationDate = new \DateTime($expirationDate, new DateTimeZone('UTC'));

0 commit comments

Comments
 (0)