浏览代码

Transforming funcion into a class + using monolog see BT#6369

Julio Montoya 11 年之前
父节点
当前提交
405f95020a
共有 2 个文件被更改,包括 317 次插入287 次删除
  1. 300 275
      main/cron/import_csv.php
  2. 17 12
      main/inc/lib/sessionmanager.lib.php

+ 300 - 275
main/cron/import_csv.php

@@ -4,315 +4,340 @@ if (PHP_SAPI!='cli') {
     die('Run this script through the command line or comment this line in the code');
 }
 
-require_once '../inc/global.inc.php';
+require_once __DIR__.'/../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'log.class.php';
 
-$path = api_get_path(SYS_CODE_PATH).'cron/incoming/';
-$files = scandir($path);
-if (!empty($files)) {
-    foreach ($files as $file) {
-        $fileInfo = pathinfo($file);
-        if ($fileInfo['extension'] == 'csv') {
-            // teachers_yyyymmdd.csv, courses_yyyymmdd.csv, students_yyyymmdd.csv and sessions_yyyymmdd.csv
-            $parts = explode('_', $fileInfo['filename']);
-            $method = 'import'.ucwords($parts[0]);
-            if (function_exists($method)) {
-                $method($path.$fileInfo['basename']);
-            } else {
-                echo "Error - This file can't be processed.";
-                exit;
-            }
-        }
-    }
-}
-
-/**
- * @param $file
- */
-function moveFile($file)
+class ImportCsv
 {
-    $moved = str_replace('incoming', 'treated', $file);
-    // $result = rename($file, $moved);
-    $result = 1;
-    if ($result) {
-        Log::info("Moving file to the treated folder: $file");
-    } else {
-        Log::error("Error - Cant move file to the treated folder: $file");
-    }
-}
+    private $logger;
 
-/**
- * File to import
- * @param string $file
- */
-function importTeachers($file)
-{
-    $data = Import::csv_to_array($file);
-    Log::info("-- Import Teachers --");
-    Log::info("Reading file: $file");
-
-    /* Unique identifier: official-code username.
-    Email address and password should never get updated. *ok
-    The only fields that I can think of that should update if the data changes in the csv file are FirstName and LastName. *ok
-    A slight edit of these fields should be taken into account. ???
-    Adding teachers is no problem, but deleting them shouldn’t be automated, but we should get a log of “to delete teachers”.
-    We’ll handle that manually if applicable.
-    No delete!
-    */
-
-    if (!empty($data)) {
-        foreach ($data as $row) {
-            $userInfo = api_get_user_info_from_username($row['username']);
-            $userInfoByOfficialCode = api_get_user_info_from_official_code($row['official_code']);
-
-            if (empty($userInfo) && empty($userInfoByOfficialCode)) {
-                // Create user
-                $result = UserManager::create_user(
-                    $row['firstname'],
-                    $row['lastname'],
-                    COURSEMANAGER,
-                    $row['email'],
-                    $row['username'],
-                    $row['password'],
-                    $row['official_code'],
-                    $row['language'],
-                    $row['phone'],
-                    $row['picture'], //picture
-                    PLATFORM_AUTH_SOURCE, // ?
-                    $row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
-                    1, //active
-                    0,
-                    null, // extra
-                    null, //$encrypt_method = '',
-                    false //$send_mail = false
-                );
-
-                if ($result) {
-                    Log::info("Info - Teachers - User created: ".$row['username']);
-                } else {
-                    Log::error("Error - Teachers - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
-                }
-            } else {
-                if (empty($userInfo)) {
-                    Log::error("Error - Teachers - Can't update user :".$row['username']);
-                    continue;
-                }
+    public function __construct($logger)
+    {
+        $this->logger = $logger;
+    }
 
-                // Update user
-                $result = UserManager::update_user(
-                    $userInfo['user_id'],
-                    $row['firstname'], // <<-- changed
-                    $row['lastname'],  // <<-- changed
-                    $userInfo['username'],
-                    null, //$password = null,
-                    $auth_source = null,
-                    $userInfo['email'],
-                    COURSEMANAGER,
-                    $userInfo['official_code'],
-                    $userInfo['phone'],
-                    $userInfo['picture_uri'],
-                    $userInfo['expiration_date'],
-                    $userInfo['active'],
-                    null, //$creator_id = null,
-                    0, //$hr_dept_id = 0,
-                    null, // $extra = null,
-                    null, //$language = 'english',
-                    null, //$encrypt_method = '',
-                    false, //$send_email = false,
-                    0 //$reset_password = 0
-                );
-
-                if ($result) {
-                    Log::info("Teachers - User updated: ".$row['username']);
-                } else {
-                    Log::error("Teachers - User not updated: ".$row['username']);
+    public function run()
+    {
+        $path = api_get_path(SYS_CODE_PATH).'cron/incoming/';
+        $files = scandir($path);
+        if (!empty($files)) {
+            foreach ($files as $file) {
+                $fileInfo = pathinfo($file);
+                if ($fileInfo['extension'] == 'csv') {
+                    // teachers_yyyymmdd.csv, courses_yyyymmdd.csv, students_yyyymmdd.csv and sessions_yyyymmdd.csv
+                    $parts = explode('_', $fileInfo['filename']);
+                    $method = 'import'.ucwords($parts[0]);
+
+                    if (method_exists($this, $method)) {
+                        $this->$method($path.$fileInfo['basename']);
+                    } else {
+                        echo "Error - This file can't be processed.";
+                        exit;
+                    }
                 }
             }
-
-            // UserManager::delete_user();
-            moveFile($file);
         }
     }
-}
 
-function importStudents($file)
-{
-    $data = Import::csv_to_array($file);
-    Log::info("-- Import Students --");
-    Log::info("Reading file: $file");
-
-    /*
-     * Another users import.
-    Unique identifier: official code and username . ok
-    Username and password should never get updated. ok
-    If an update should need to occur (because it changed in the .csv), we’ll want that logged. We will handle this manually in that case.
-    All other fields should be updateable, though passwords should of course not get updated. ok
-    If a user gets deleted (not there anymore),
-    He should be set inactive one year after the current date. So I presume you’ll just update the expiration date. We want to grant access to courses up to a year after deletion.
+    /**
+     * @param string $file
      */
+    function moveFile($file)
+    {
+        $moved = str_replace('incoming', 'treated', $file);
+        // $result = rename($file, $moved);
+        $result = 1;
+        if ($result) {
+            $this->logger->addInfo("Moving file to the treated folder: $file");
+        } else {
+            $this->logger->addError("Error - Cant move file to the treated folder: $file");
+        }
+    }
 
-
-    if (!empty($data)) {
-        foreach ($data as $row) {
-            $userInfo = api_get_user_info_from_username($row['username']);
-            $userInfoByOfficialCode = api_get_user_info_from_official_code($row['official_code']);
-
-            if (empty($userInfo) && empty($userInfoByOfficialCode)) {
-                // Create user
-                $result = UserManager::create_user(
-                    $row['firstname'],
-                    $row['lastname'],
-                    STUDENT,
-                    $row['email'],
-                    $row['username'],
-                    $row['password'],
-                    $row['official_code'],
-                    $row['language'],
-                    $row['phone'],
-                    $row['picture'], //picture
-                    PLATFORM_AUTH_SOURCE, // ?
-                    $row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
-                    1, //active
-                    0,
-                    null, // extra
-                    null, //$encrypt_method = '',
-                    false //$send_mail = false
-                );
-
-                if ($result) {
-                    Log::info("Students - User created: ".$row['username']);
+    /**
+     * File to import
+     * @param string $file
+     */
+    function importTeachers($file)
+    {
+        $data = Import::csv_to_array($file);
+        $this->logger->addInfo("-- Import Teachers --");
+        $this->logger->addInfo("Reading file: $file");
+
+        /* Unique identifier: official-code username.
+        Email address and password should never get updated. *ok
+        The only fields that I can think of that should update if the data changes in the csv file are FirstName and LastName. *ok
+        A slight edit of these fields should be taken into account. ???
+        Adding teachers is no problem, but deleting them shouldn’t be automated, but we should get a log of “to delete teachers”.
+        We’ll handle that manually if applicable.
+        No delete!
+        */
+
+        if (!empty($data)) {
+            foreach ($data as $row) {
+                $userInfo = api_get_user_info_from_username($row['username']);
+                $userInfoByOfficialCode = api_get_user_info_from_official_code($row['official_code']);
+
+                if (empty($userInfo) && empty($userInfoByOfficialCode)) {
+                    // Create user
+                    $result = UserManager::create_user(
+                        $row['firstname'],
+                        $row['lastname'],
+                        COURSEMANAGER,
+                        $row['email'],
+                        $row['username'],
+                        $row['password'],
+                        $row['official_code'],
+                        $row['language'],
+                        $row['phone'],
+                        $row['picture'], //picture
+                        PLATFORM_AUTH_SOURCE, // ?
+                        $row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
+                        1, //active
+                        0,
+                        null, // extra
+                        null, //$encrypt_method = '',
+                        false //$send_mail = false
+                    );
+
+                    if ($result) {
+                        $this->logger->addInfo("Info - Teachers - User created: ".$row['username']);
+                    } else {
+                        $this->logger->addError("Error - Teachers - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
+                    }
                 } else {
-                    Log::error("Students - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
-                }
-            } else {
-                if (empty($userInfo)) {
-                    Log::error("Students - Can't update user :".$row['username']);
-                    continue;
+                    if (empty($userInfo)) {
+                        $this->logger->addError("Error - Teachers - Can't update user :".$row['username']);
+                        continue;
+                    }
+
+                    // Update user
+                    $result = UserManager::update_user(
+                        $userInfo['user_id'],
+                        $row['firstname'], // <<-- changed
+                        $row['lastname'],  // <<-- changed
+                        $userInfo['username'],
+                        null, //$password = null,
+                        $auth_source = null,
+                        $userInfo['email'],
+                        COURSEMANAGER,
+                        $userInfo['official_code'],
+                        $userInfo['phone'],
+                        $userInfo['picture_uri'],
+                        $userInfo['expiration_date'],
+                        $userInfo['active'],
+                        null, //$creator_id = null,
+                        0, //$hr_dept_id = 0,
+                        null, // $extra = null,
+                        null, //$language = 'english',
+                        null, //$encrypt_method = '',
+                        false, //$send_email = false,
+                        0 //$reset_password = 0
+                    );
+
+                    if ($result) {
+                        $this->logger->addInfo("Teachers - User updated: ".$row['username']);
+                    } else {
+                        $this->logger->addError("Teachers - User not updated: ".$row['username']);
+                    }
                 }
 
-                if ($row['action'] == 'delete') {
-                    // INactive one year later
-                    $userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + 365*24*60*60));
-                }
-
-                // Update user
-                $result = UserManager::update_user(
-                    $userInfo['user_id'],
-                    $row['firstname'], // <<-- changed
-                    $row['lastname'],  // <<-- changed
-                    $userInfo['username'],
-                    null, //$password = null,
-                    $auth_source = null,
-                    $userInfo['email'],
-                    STUDENT,
-                    $userInfo['official_code'],
-                    $userInfo['phone'],
-                    $userInfo['picture_uri'],
-                    $userInfo['expiration_date'],
-                    $userInfo['active'],
-                    null, //$creator_id = null,
-                    0, //$hr_dept_id = 0,
-                    null, // $extra = null,
-                    null, //$language = 'english',
-                    null, //$encrypt_method = '',
-                    false, //$send_email = false,
-                    0 //$reset_password = 0
-                );
-
-                if ($result) {
-                    Log::info("Students - User updated: ".$row['username']);
-                } else {
-                    Log::error("Students - User NOT updated: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
-                }
+                // UserManager::delete_user();
+                $this->moveFile($file);
             }
-
-            // UserManager::delete_user();
-            moveFile($file);
         }
     }
 
-    moveFile($file);
-}
-
-function importCourses($file)
-{
-    $data = Import::csv_to_array($file);
-    Log::info("Reading file: $file");
-
-    if (!empty($data)) {
-        foreach ($data as $row) {
-            $courseInfo = api_get_course_info($row['course_code']);
-            if (empty($courseInfo)) {
-                // Create
-                $params = array();
-                $params['title']                = $row['title'];
-                $params['exemplary_content']    = false;
-                $params['wanted_code']          = $row['course_code'];
-                $params['category_code']        = $row['category_code'];
-                $params['course_language']      = $row['language'];
-                //$params['gradebook_model_id']   = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
-                $courseInfo = CourseManager::create_course($params);
-
-                if (!empty($courseInfo)) {
-                    Log::info("Courses - Course created ".$courseInfo['code']);
+    /**
+     * @param string $file
+     */
+    function importStudents($file)
+    {
+        $data = Import::csv_to_array($file);
+        $this->logger->addInfo("-- Import Students --");
+        $this->logger->addInfo("Reading file: $file");
+
+        /*
+         * Another users import.
+        Unique identifier: official code and username . ok
+        Username and password should never get updated. ok
+        If an update should need to occur (because it changed in the .csv), we’ll want that logged. We will handle this manually in that case.
+        All other fields should be updateable, though passwords should of course not get updated. ok
+        If a user gets deleted (not there anymore),
+        He should be set inactive one year after the current date. So I presume you’ll just update the expiration date. We want to grant access to courses up to a year after deletion.
+         */
+        if (!empty($data)) {
+            foreach ($data as $row) {
+                $userInfo = api_get_user_info_from_username($row['username']);
+                $userInfoByOfficialCode = api_get_user_info_from_official_code($row['official_code']);
+
+                if (empty($userInfo) && empty($userInfoByOfficialCode)) {
+                    // Create user
+                    $result = UserManager::create_user(
+                        $row['firstname'],
+                        $row['lastname'],
+                        STUDENT,
+                        $row['email'],
+                        $row['username'],
+                        $row['password'],
+                        $row['official_code'],
+                        $row['language'],
+                        $row['phone'],
+                        $row['picture'], //picture
+                        PLATFORM_AUTH_SOURCE, // ?
+                        $row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
+                        1, //active
+                        0,
+                        null, // extra
+                        null, //$encrypt_method = '',
+                        false //$send_mail = false
+                    );
+
+                    if ($result) {
+                        $this->logger->addInfo("Students - User created: ".$row['username']);
+                    } else {
+                        $this->logger->addError("Students - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
+                    }
                 } else {
-                    Log::error("Courses - Can't create course:".$row['title']);
+                    if (empty($userInfo)) {
+                        $this->logger->addError("Students - Can't update user :".$row['username']);
+                        continue;
+                    }
+
+                    if ($row['action'] == 'delete') {
+                        // INactive one year later
+                        $userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + 365*24*60*60));
+                    }
+
+                    // Update user
+                    $result = UserManager::update_user(
+                        $userInfo['user_id'],
+                        $row['firstname'], // <<-- changed
+                        $row['lastname'],  // <<-- changed
+                        $userInfo['username'],
+                        null, //$password = null,
+                        $auth_source = null,
+                        $userInfo['email'],
+                        STUDENT,
+                        $userInfo['official_code'],
+                        $userInfo['phone'],
+                        $userInfo['picture_uri'],
+                        $userInfo['expiration_date'],
+                        $userInfo['active'],
+                        null, //$creator_id = null,
+                        0, //$hr_dept_id = 0,
+                        null, // $extra = null,
+                        null, //$language = 'english',
+                        null, //$encrypt_method = '',
+                        false, //$send_email = false,
+                        0 //$reset_password = 0
+                    );
+
+                    if ($result) {
+                        $this->logger->addInfo("Students - User updated: ".$row['username']);
+                    } else {
+                        $this->logger->addError("Students - User NOT updated: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
+                    }
                 }
 
-            } else {
-                // Update
-                $params = array(
-                    'title' => $row['title'],
-                );
+                // UserManager::delete_user();
+                $this->moveFile($file);
+            }
+        }
+
+        $this->moveFile($file);
+    }
 
-                $result = CourseManager::update_attributes($courseInfo['id'], $params);
+    /**
+     * @param string $file
+     */
+    function importCourses($file)
+    {
+        $data = Import::csv_to_array($file);
+        $this->logger->addInfo("Reading file: $file");
+
+        if (!empty($data)) {
+            foreach ($data as $row) {
+                $courseInfo = api_get_course_info($row['course_code']);
+                if (empty($courseInfo)) {
+                    // Create
+                    $params = array();
+                    $params['title']                = $row['title'];
+                    $params['exemplary_content']    = false;
+                    $params['wanted_code']          = $row['course_code'];
+                    $params['category_code']        = $row['category_code'];
+                    $params['course_language']      = $row['language'];
+                    //$params['gradebook_model_id']   = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
+                    $courseInfo = CourseManager::create_course($params);
+
+                    if (!empty($courseInfo)) {
+                        $this->logger->addInfo("Courses - Course created ".$courseInfo['code']);
+                    } else {
+                        $this->logger->addError("Courses - Can't create course:".$row['title']);
+                    }
 
-                if ($result) {
-                    Log::info("Courses - Course updated ".$courseInfo['code']);
                 } else {
-                    Log::error("Courses - Course NOT updated ".$courseInfo['code']);
+                    // Update
+                    $params = array(
+                        'title' => $row['title'],
+                    );
+
+                    $result = CourseManager::update_attributes($courseInfo['id'], $params);
+
+                    if ($result) {
+                        $this->logger->addInfo("Courses - Course updated ".$courseInfo['code']);
+                    } else {
+                        $this->logger->addError("Courses - Course NOT updated ".$courseInfo['code']);
+                    }
+
+                    /*course_language='".Database::escape_string($course_language)."',
+                    title='".Database::escape_string($title)."',
+                    category_code='".Database::escape_string($category_code)."',
+                    tutor_name='".Database::escape_string($tutor_name)."',
+                    visual_code='".Database::escape_string($visual_code)."',
+                    department_name='".Database::escape_string($department_name)."',
+                    department_url='".Database::escape_string($department_url)."',
+                    disk_quota='".Database::escape_string($disk_quota)."',
+                    visibility = '".Database::escape_string($visibility)."',
+                    subscribe = '".Database::escape_string($subscribe)."',
+                    unsubscribe='*/
                 }
-
-                /*course_language='".Database::escape_string($course_language)."',
-                title='".Database::escape_string($title)."',
-                category_code='".Database::escape_string($category_code)."',
-                tutor_name='".Database::escape_string($tutor_name)."',
-                visual_code='".Database::escape_string($visual_code)."',
-                department_name='".Database::escape_string($department_name)."',
-                department_url='".Database::escape_string($department_url)."',
-                disk_quota='".Database::escape_string($disk_quota)."',
-                visibility = '".Database::escape_string($visibility)."',
-                subscribe = '".Database::escape_string($subscribe)."',
-                unsubscribe='*/
             }
         }
+        $this->moveFile($file);
     }
-    moveFile($file);
-}
 
-function importSessions($file)
-{
-    $result = SessionManager::importCSV($file, true, 1, true);
+    /**
+     * @param string $file
+     */
+    function importSessions($file)
+    {
+        $result = SessionManager::importCSV($file, true, 1, $this->logger);
 
-    if (!empty($result['error_message'])) {
-        Log::error($result['error_message']);
+        if (!empty($result['error_message'])) {
+            $this->logger->addError($result['error_message']);
+        }
+        $this->logger->addInfo("Sessions - Sessions parsed: ".$result['session_counter']);
+        $this->moveFile($file);
     }
+}
+use Monolog\Logger;
+use Monolog\Handler\StreamHandler;
+use Monolog\Handler\NativeMailerHandler;
+use Monolog\Handler\RotatingFileHandler;
 
-    Log::info("Sessions - Sessions parsed: ".$result['session_counter']);
-
-    moveFile($file);
-
-    /*$data = Import::csv_to_array($file);
-    Log::info("Reading file: $file");
-    if (!empty($data)) {
-        foreach ($data as $row) {
+//use Monolog\Handler\SwiftMailerHandler;
+//require_once api_get_path(LIBRARY_PATH).'swiftmailer/lib/swift_required.php';
 
-            if (empty($courseInfo)) {
+$logger = new Logger('cron');
 
-            }
-        }
-    }
-    moveFile($file);*/
-}
+$to = "";
+$subject = "Cron main/cron/import_csv.php ".date('Y-m-d h:i:s');
+$from = api_get_setting('emailAdministrator');
+$logger->pushHandler(new NativeMailerHandler($to, $subject, $from, Logger::ERROR));
 
+$logger->pushHandler(new StreamHandler(api_get_path(SYS_ARCHIVE_PATH).'import_csv.log'), Logger::ERROR);
+$logger->pushHandler(new RotatingFileHandler('import_csv', 5, Logger::ERROR));
 
+$import = new ImportCsv($logger);
+$import->run();

+ 17 - 12
main/inc/lib/sessionmanager.lib.php

@@ -1851,7 +1851,7 @@ class SessionManager {
      * @param int $user_id
      * @return array
      */
-    static function importCSV($file, $updatesession, $user_id = null, $debug = false)
+    static function importCSV($file, $updatesession, $user_id = null, $logger = null)
     {
         $content = file($file);
         $error_message = null;
@@ -1861,6 +1861,11 @@ class SessionManager {
             $user_id = api_get_user_id();
         }
 
+        $debug = false;
+        if (isset($logger)) {
+            $debug = true;
+        }
+
         $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
         $tbl_session_user           = Database::get_main_table(TABLE_MAIN_SESSION_USER);
         $tbl_session_course         = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
@@ -1944,9 +1949,9 @@ class SessionManager {
 
                     if ($debug) {
                         if ($session_id) {
-                            Log::info("Sessions - Session created: #$session_id - $session_name");
+                            $logger->addInfo("Sessions - Session created: #$session_id - $session_name");
                         } else {
-                            Log::error("Sessions - Session NOT created $session_name");
+                            $logger->addError("Sessions - Session NOT created $session_name");
                         }
                     }
                     $session_counter++;
@@ -1970,9 +1975,9 @@ class SessionManager {
 
                         if ($debug) {
                             if ($session_id) {
-                                Log::info("Sessions - #$session_id created: $session_name");
+                                $logger->addInfo("Sessions - #$session_id created: $session_name");
                             } else {
-                                Log::error("Sessions - Session NOT created $session_name");
+                                $logger->addError("Sessions - Session NOT created $session_name");
                             }
                         }
                     } else {
@@ -2007,7 +2012,7 @@ class SessionManager {
                                     id_session = '$session_id'";
                             Database::query($sql);
                             if ($debug) {
-                                Log::info("Sessions - Adding User #$user_id to session #$session_id");
+                                $logger->addInfo("Sessions - Adding User #$user_id to session #$session_id");
                             }
                             $user_counter++;
                         }
@@ -2043,7 +2048,7 @@ class SessionManager {
                         Database::query($sql_course);
 
                         if ($debug) {
-                            Log::info("Sessions - Adding course '$course_code' to session #$session_id");
+                            $logger->addInfo("Sessions - Adding course '$course_code' to session #$session_id");
                         }
                         $course_counter++;
 
@@ -2070,7 +2075,7 @@ class SessionManager {
                                             status = 2 ";
                                     Database::query($sql);
                                     if ($debug) {
-                                        Log::info("Sessions - Adding course coach: user #$coach_id to course: '$course_code' and session #$session_id");
+                                        $logger->addInfo("Sessions - Adding course coach: user #$coach_id to course: '$course_code' and session #$session_id");
                                     }
                                 } else {
                                     $error_message .= get_lang('UserDoesNotExist').' : '.$user.'<br />';
@@ -2090,7 +2095,7 @@ class SessionManager {
                                         id_session = '$session_id'";
                                 Database::query($sql);
                                 if ($debug) {
-                                    Log::info("Sessions - Adding student: user #$user_id to course: '$course_code' and session #$session_id");
+                                    $logger->addInfo("Sessions - Adding student: user #$user_id to course: '$course_code' and session #$session_id");
                                 }
                                 $users_in_course_counter++;
                             } else {
@@ -2126,7 +2131,7 @@ class SessionManager {
                                 Database::query($sql_course);
 
                                 if ($debug) {
-                                    Log::info("Sessions - Adding course to session: course: '".$vcourse['code']."' and session #$session_id");
+                                    $logger->addInfo("Sessions - Adding course to session: course: '".$vcourse['code']."' and session #$session_id");
                                 }
 
                                 // adding coachs to session course user
@@ -2141,7 +2146,7 @@ class SessionManager {
                                         Database::query($sql);
 
                                         if ($debug) {
-                                            Log::info("Sessions - Adding coach to session: user #$coach_id course: '".$vcourse['code']."' and session #$session_id");
+                                            $logger->addInfo("Sessions - Adding coach to session: user #$coach_id course: '".$vcourse['code']."' and session #$session_id");
                                         }
 
                                     } else {
@@ -2161,7 +2166,7 @@ class SessionManager {
                                         Database::query($sql);
 
                                         if ($debug) {
-                                            Log::info("Sessions - Adding user to session: user #$user_id course: '".$vcourse['code']."' and session #$session_id");
+                                            $logger->addInfo("Sessions - Adding user to session: user #$user_id course: '".$vcourse['code']."' and session #$session_id");
                                         }
 
                                         $users_in_course_counter++;