Skip to content

Commit 7a6ed04

Browse files
committed
Script: user: add filter for url white list and url black list - refs BT#23122
1 parent 94e5bc2 commit 7a6ed04

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/scripts/delete_or_disable_students_before_last_connection.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
$date = $argv[2];
3030
$force = '--force' === ($argv[3] ?? '');
3131

32+
// URL white list. It will only take users that have access to those URLs
33+
//$urlWhiteList = "1,2";
34+
// URL black list. It will not take users that have access to those URLs
35+
//$urlBlackList = "1,2";
36+
3237
if (!in_array($action, ['disable', 'delete'])) {
3338
die('Action not allowed'.PHP_EOL);
3439
}
@@ -38,11 +43,20 @@
3843
$date = api_get_utc_datetime($date);
3944

4045
$tblUser = Database::get_main_table(TABLE_MAIN_USER);
46+
$tblUrlRelUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
47+
$whereURLWhiteList = "";
48+
$whereURLBlackList = "";
49+
if (isset($urlWhiteList)){
50+
$whereURLWhiteList = " AND user_id IN (SELECT user_id from $tblUrlRelUser where access_url_id in ($urlWhiteList)) ";
51+
}
52+
if (isset($urlBlackList)){
53+
$whereURLBlackList = " AND user_id NOT IN (SELECT user_id from $tblUrlRelUser where access_url_id in ($urlBlackList)) ";
54+
}
4155

4256
$result = Database::query(
4357
sprintf(
4458
"SELECT id, username FROM $tblUser
45-
WHERE last_login <= '%s' AND active = %d AND status = %d
59+
WHERE last_login <= '%s' AND active = %d AND status = %d $whereURLWhiteList $whereURLBlackList
4660
ORDER BY last_login",
4761
$date,
4862
1,

0 commit comments

Comments
 (0)