Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts: Add script to move a session from URL X to URL Y BT#18023
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
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,94 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
/** | ||
* Move sessions from URL 1 to URL 2 | ||
*/ | ||
exit; | ||
|
||
require_once __DIR__.'/../../main/inc/global.inc.php'; | ||
|
||
$test = true; | ||
$sessionsToMove = [1]; | ||
$urlSourceId = 2; | ||
$urlDestinationId = 3; | ||
|
||
$urlSourceInfo = UrlManager::get_url_data_from_id($urlSourceId); | ||
if (empty($urlSourceInfo)) { | ||
echo 'Portal not found'; | ||
exit; | ||
} | ||
|
||
$urlDestination = UrlManager::get_url_data_from_id($urlDestinationId); | ||
if (empty($urlDestination)) { | ||
echo 'Portal not found'; | ||
exit; | ||
} | ||
|
||
if ($test) { | ||
echo '----'.PHP_EOL; | ||
echo '----No DB changes'.PHP_EOL; | ||
echo '----'.PHP_EOL; | ||
} | ||
|
||
foreach ($sessionsToMove as $sessionId) { | ||
$sessionInfo = api_get_session_info($sessionId); | ||
if (empty($sessionInfo)) { | ||
echo "Session does not exists $sessionId ".PHP_EOL; | ||
continue; | ||
} | ||
|
||
$coachId = $sessionInfo['coach_id']; | ||
if (!empty($coachId)) { | ||
if ($test) { | ||
echo "Add coach: $coachId to URL: $urlDestinationId".PHP_EOL; | ||
} else { | ||
//UrlManager::delete_url_rel_user($coachId, $sourceId); | ||
UrlManager::add_user_to_url($coachId, $urlDestinationId); | ||
} | ||
} | ||
|
||
$sessionAdminId = $sessionInfo['session_admin_id']; | ||
if (!empty($sessionAdminId)) { | ||
if ($test) { | ||
echo "Add sessionAdminId: $sessionAdminId to URL: $urlDestinationId".PHP_EOL; | ||
} else { | ||
//UrlManager::delete_url_rel_user($coachId, $sourceId); | ||
UrlManager::add_user_to_url($sessionAdminId, $urlDestinationId); | ||
} | ||
} | ||
|
||
$courses = SessionManager::getCoursesInSession($sessionId); | ||
foreach ($courses as $course) { | ||
$courseId = $course['id']; | ||
/*$sql = "DELETE FROM access_url_rel_course | ||
WHERE c_id = $courseId AND access_url_id = $urlSourceId"; | ||
Database::query($sql);*/ | ||
if ($test) { | ||
echo "Add course: $courseId to URL: $urlDestinationId".PHP_EOL; | ||
} else { | ||
UrlManager::add_course_to_url($courseId, $urlDestinationId); | ||
} | ||
} | ||
|
||
$users = SessionManager::get_users_by_session($sessionId, null, false,$urlSourceId); | ||
foreach ($users as $user) { | ||
$userId = $users['user_id']; | ||
//UrlManager::delete_url_rel_user($userId, $sourceId); | ||
if ($test) { | ||
echo "Add user: $userId to URL: $urlDestinationId".PHP_EOL; | ||
} else { | ||
UrlManager::add_user_to_url($userId, $urlDestinationId); | ||
} | ||
} | ||
|
||
if ($test) { | ||
echo "Add session: $sessionId to URL: $urlDestinationId".PHP_EOL; | ||
} else { | ||
$sql = "DELETE FROM access_url_rel_session | ||
WHERE session_id = $sessionId AND access_url_id = $urlSourceId"; | ||
Database::query($sql); | ||
UrlManager::add_session_to_url($sessionId, $urlDestinationId); | ||
} | ||
} |