delete_items_from_csv.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. exit;
  4. require_once __DIR__ . '/../../main/inc/global.inc.php';
  5. $file = 'delete.csv';
  6. if (!file_exists($file)) {
  7. echo "File $file doesn't exists";
  8. exit;
  9. }
  10. $data = Import::csv_reader($file);
  11. echo 'Number of lines '.count($data).PHP_EOL;
  12. $counter = 1;
  13. foreach ($data as $row) {
  14. if (isset($row['SessionID'])) {
  15. $sessionId = SessionManager::getSessionIdFromOriginalId($row['SessionID'], 'external_session_id');
  16. if (!empty($sessionId)) {
  17. $sessionInfo = api_get_session_info($sessionId);
  18. if (!empty($sessionInfo)) {
  19. $sessionId = $sessionInfo['id'];
  20. $sessionName = $sessionInfo['name'];
  21. echo "Line: $counter. Session will be deleted: $sessionName #$sessionId ".PHP_EOL;
  22. //SessionManager::delete($sessionId, true);
  23. } else {
  24. echo "Line: $counter. Session not found: $sessionName".PHP_EOL;
  25. }
  26. }
  27. }
  28. // Course
  29. $courseId = isset($row['CourseID']) ? $row['CourseID'] : '';
  30. if (!empty($courseId)) {
  31. $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseId, 'external_course_id');
  32. if (!empty($courseInfo) && isset($courseInfo['id'])) {
  33. $courseCode = $courseInfo['code'];
  34. $courseId = $courseInfo['id'];
  35. CourseManager::delete_course($courseCode);
  36. echo "Line: $counter. Course will be deleted: $courseCode #$courseId".PHP_EOL;
  37. } else {
  38. echo "Line: $counter. Course not found: $courseCode".PHP_EOL;
  39. }
  40. }
  41. // User
  42. $userName = isset($row['UserName']) ? $row['UserName'] : '';
  43. if (!empty($userName)) {
  44. $userInfo = api_get_user_info_from_username($userName);
  45. if (!empty($userInfo) && isset($userInfo['id'])) {
  46. $userId = $userInfo['id'];
  47. //UserManager::delete_user($userId);
  48. echo "Line: $counter. User will be deleted: $userId".PHP_EOL;
  49. } else {
  50. echo "Line: $counter. User not found: $userName".PHP_EOL;
  51. }
  52. }
  53. $counter++;
  54. }