-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script: System: Script to delete content of a specific URL or all URL…
… except a specific one in a multiURL context -refs BT#20736
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
tests/scripts/multi_url_delete_courses_sessions_users_from_a_specific_url.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/* For licensing terms, see /license.txt */ | ||
/* | ||
* Delete all courses, sessions and users that are only on a specific URL identified by $urlId. | ||
* | ||
*/ | ||
|
||
exit; | ||
// Uncomment le following line and set the urlId of the URL to be treated by this script. | ||
//$urlId = ; | ||
|
||
if (empty($urlId)) { | ||
echo "You need to define a urlId at the begining of the script"; | ||
exit; | ||
} | ||
require_once '../../main/inc/global.inc.php'; | ||
|
||
$accessUrlRelCourseTable = Database::get_course_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); | ||
$accessUrlRelUserTable = Database::get_course_table(TABLE_MAIN_ACCESS_URL_REL_USER); | ||
$accessUrlRelSessionTable = Database::get_course_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); | ||
|
||
$sqlCoursesToDelete = "select c_id from $accessUrlRelCourseTable where access_url_id = $urlId and c_id not in (select c_id from $accessUrlRelCourseTable where access_url_id != $urlId)" | ||
$sqlUsersToDelete = "select user_id from $accessUrlRelUserTable where access_url_id = $urlId and user_id not in (select user_id from $accessUrlRelUserTable where access_url_id != $urlId)" | ||
$sqlSessionsToDelete = "select session_id from $accessUrlRelSessionTable where access_url_id = $urlId and session_id not in (select user_id from $accessUrlRelUserTable where access_url_id != $urlId)" | ||
|
||
|
||
echo "Initiating sessions deletion".PHP_EOL; | ||
$resSessionsToDelete = Database::query($sqlSessionsToDelete); | ||
while ($data = Database::fetch_array($resSessionsToDelete)) { | ||
echo "deleting session with id = " . $data['session_id'] . ".".PHP_EOL; | ||
if (!SessionManager::delete($data['session_id'])) { | ||
echo "Session " . $data['session_id'] . " not deleted".PHP_EOL; | ||
} | ||
} | ||
|
||
echo "Initiating courses deletion".PHP_EOL; | ||
$resCoursesToDelete = Database::query($sqlCoursesToDelete); | ||
while ($data = Database::fetch_array($resCoursesToDelete)) { | ||
$courseCode = CourseManager::get_course_code_from_course_id($data['c_id']); | ||
echo "deleting course " . $courseCode . " with c_id = " . $data['c_id'] . ".".PHP_EOL; | ||
if (!CourseManager::delete_course($courseCode)) { | ||
echo "Course " . $data['c_id'] . " not deleted".PHP_EOL; | ||
} | ||
} | ||
|
||
echo "Initiating users deletion".PHP_EOL; | ||
$resUsersToDelete = Database::query($sqlUsersToDelete); | ||
while ($data = Database::fetch_array($resUsersToDelete)) { | ||
$courseCode = CourseManager::get_course_code_from_course_id($data['c_id']); | ||
echo "deleting user with user_id = " . $data['user_id'] . ".".PHP_EOL; | ||
if (!UserManager::delete_user($data['user_id'])) { | ||
echo "User " . $data['user_id'] . " not deleted".PHP_EOL; | ||
} | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
tests/scripts/multi_url_delete_courses_sessions_users_from_all_urls_except_specific_url.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/* For licensing terms, see /license.txt */ | ||
/* | ||
* Delete all courses, sessions and users that are not on a specific URL identified by $urlId. | ||
* | ||
*/ | ||
|
||
exit; | ||
// Uncomment le following line and set the urlId of the URL to be kept by this script. | ||
//$urlId = ; | ||
|
||
if (empty($urlId)) { | ||
echo "You need to define a urlId at the begining of the script"; | ||
exit; | ||
} | ||
require_once '../../main/inc/global.inc.php'; | ||
|
||
$accessUrlRelCourseTable = Database::get_course_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); | ||
$accessUrlRelUserTable = Database::get_course_table(TABLE_MAIN_ACCESS_URL_REL_USER); | ||
$accessUrlRelSessionTable = Database::get_course_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); | ||
|
||
$sqlCoursesToDelete = "select c_id from $accessUrlRelCourseTable where access_url_id != $urlId and c_id not in (select c_id from $accessUrlRelCourseTable where access_url_id = $urlId)" | ||
$sqlUsersToDelete = "select user_id from $accessUrlRelUserTable where access_url_id != $urlId and user_id not in (select user_id from $accessUrlRelUserTable where access_url_id = $urlId)" | ||
$sqlSessionsToDelete = "select session_id from $accessUrlRelSessionTable where access_url_id != $urlId and session_id not in (select user_id from $accessUrlRelUserTable where access_url_id = $urlId)" | ||
|
||
|
||
echo "Initiating sessions deletion".PHP_EOL; | ||
$resSessionsToDelete = Database::query($sqlSessionsToDelete); | ||
while ($data = Database::fetch_array($resSessionsToDelete)) { | ||
echo "deleting session with id = " . $data['session_id'] . ".".PHP_EOL; | ||
if (!SessionManager::delete($data['session_id'])) { | ||
echo "Session " . $data['session_id'] . " not deleted".PHP_EOL; | ||
} | ||
} | ||
|
||
echo "Initiating courses deletion".PHP_EOL; | ||
$resCoursesToDelete = Database::query($sqlCoursesToDelete); | ||
while ($data = Database::fetch_array($resCoursesToDelete)) { | ||
$courseCode = CourseManager::get_course_code_from_course_id($data['c_id']); | ||
echo "deleting course " . $courseCode . " with c_id = " . $data['c_id'] . ".".PHP_EOL; | ||
if (!CourseManager::delete_course($courseCode)) { | ||
echo "Course " . $data['c_id'] . " not deleted".PHP_EOL; | ||
} | ||
} | ||
|
||
echo "Initiating users deletion".PHP_EOL; | ||
$resUsersToDelete = Database::query($sqlUsersToDelete); | ||
while ($data = Database::fetch_array($resUsersToDelete)) { | ||
$courseCode = CourseManager::get_course_code_from_course_id($data['c_id']); | ||
echo "deleting user with user_id = " . $data['user_id'] . ".".PHP_EOL; | ||
if (!UserManager::delete_user($data['user_id'])) { | ||
echo "User " . $data['user_id'] . " not deleted".PHP_EOL; | ||
} | ||
} | ||
|