@ -131,7 +131,7 @@ class ImportCsv
if (!empty($files)) {
if (!empty($files)) {
foreach ($files as $file) {
foreach ($files as $file) {
$fileInfo = pathinfo($file);
$fileInfo = pathinfo($file);
if (isset($fileInfo['extension']) & & $fileInfo['extension'] === 'csv' ) {
if (isset($fileInfo['extension']) & & 'csv' === $fileInfo['extension']) {
// Checking teachers_yyyymmdd.csv,
// Checking teachers_yyyymmdd.csv,
// courses_yyyymmdd.csv, students_yyyymmdd.csv and sessions_yyyymmdd.csv
// courses_yyyymmdd.csv, students_yyyymmdd.csv and sessions_yyyymmdd.csv
$parts = explode('_', $fileInfo['filename']);
$parts = explode('_', $fileInfo['filename']);
@ -141,37 +141,37 @@ class ImportCsv
$isStatic = strpos($method, 'Static');
$isStatic = strpos($method, 'Static');
if ($method == 'importSessionsextidStatic') {
if ('importSessionsextidStatic' == $method ) {
$method = 'importSessionsExtIdStatic';
$method = 'importSessionsExtIdStatic';
}
}
if ($method == 'importCourseinsertStatic') {
if ('importCourseinsertStatic' == $method ) {
$method = 'importSubscribeUserToCourse';
$method = 'importSubscribeUserToCourse';
}
}
if ($method == 'importUnsubsessionsextidStatic') {
if ('importUnsubsessionsextidStatic' == $method ) {
$method = 'importUnsubsessionsExtidStatic';
$method = 'importUnsubsessionsExtidStatic';
}
}
if ($method == 'importCareersdiagram') {
if ('importCareersdiagram' == $method ) {
$method = 'importCareersDiagram';
$method = 'importCareersDiagram';
}
}
if ($method == 'importCareersresults') {
if ('importCareersresults' == $method ) {
$method = 'importCareersResults';
$method = 'importCareersResults';
}
}
if ($method == 'importOpensessions') {
if ('importOpensessions' == $method ) {
$method = 'importOpenSessions';
$method = 'importOpenSessions';
}
}
if ($method == 'importSubsessionsextidStatic') {
if ('importSubsessionsextidStatic' == $method ) {
$method = 'importSubscribeUserToCourseSessionExtStatic';
$method = 'importSubscribeUserToCourseSessionExtStatic';
}
}
if (method_exists($this, $method)) {
if (method_exists($this, $method)) {
if ((
if ((
$method == 'importSubscribeStatic' ||
'importSubscribeStatic' == $method ||
$method == 'importSubscribeUserToCourse'
'importSubscribeUserToCourse' == $method
) ||
) ||
empty($isStatic)
empty($isStatic)
) {
) {
@ -231,7 +231,7 @@ class ImportCsv
$this->logger->addInfo('====================================================');
$this->logger->addInfo('====================================================');
$this->logger->addInfo("Reading file: $file");
$this->logger->addInfo("Reading file: $file");
$this->logger->addInfo("Loading method $method ");
$this->logger->addInfo("Loading method $method ");
if ($method == 'importSessions' || $method == 'importOpenSessions' ) {
if ('importSessions' == $method || 'importOpenSessions' == $method ) {
$this->$method(
$this->$method(
$file,
$file,
true,
true,
@ -405,7 +405,7 @@ class ImportCsv
$this->logger->addInfo("Post id saved #".$post->getId());
$this->logger->addInfo("Post id saved #".$post->getId());
if (($counter % $batchSize) === 0 ) {
if (0 === ($counter % $batchSize)) {
$em->flush();
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
$em->clear(); // Detaches all objects from Doctrine!
}
}
@ -437,7 +437,7 @@ class ImportCsv
*/
*/
public function updateUsersEmails()
public function updateUsersEmails()
{
{
if ($this->getUpdateEmailToDummy() === true ) {
if (true === $this->getUpdateEmailToDummy()) {
$sql = "UPDATE user SET email = CONCAT(username,'@example.com') WHERE id NOT IN (SELECT user_id FROM admin)";
$sql = "UPDATE user SET email = CONCAT(username,'@example.com') WHERE id NOT IN (SELECT user_id FROM admin)";
Database::query($sql);
Database::query($sql);
}
}
@ -693,7 +693,7 @@ class ImportCsv
if ($userId) {
if ($userId) {
foreach ($row as $key => $value) {
foreach ($row as $key => $value) {
if (substr($key, 0, 6) == 'extra_' ) {
if ('extra_' == substr($key, 0, 6)) {
//an extra field
//an extra field
UserManager::update_extra_field_value(
UserManager::update_extra_field_value(
$userId,
$userId,
@ -740,7 +740,7 @@ class ImportCsv
if ($result) {
if ($result) {
foreach ($row as $key => $value) {
foreach ($row as $key => $value) {
if (substr($key, 0, 6) == 'extra_' ) {
if ('extra_' == substr($key, 0, 6)) {
//an extra field
//an extra field
UserManager::update_extra_field_value(
UserManager::update_extra_field_value(
$userInfo['user_id'],
$userInfo['user_id'],
@ -755,7 +755,7 @@ class ImportCsv
}
}
}
}
if (($counter % $batchSize) === 0 ) {
if (0 === ($counter % $batchSize)) {
$em->flush();
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
$em->clear(); // Detaches all objects from Doctrine!
}
}
@ -895,7 +895,7 @@ class ImportCsv
if ($result) {
if ($result) {
foreach ($row as $key => $value) {
foreach ($row as $key => $value) {
if (substr($key, 0, 6) === 'extra_' ) {
if ('extra_' === substr($key, 0, 6)) {
//an extra field
//an extra field
UserManager::update_extra_field_value(
UserManager::update_extra_field_value(
$result,
$result,
@ -916,7 +916,7 @@ class ImportCsv
continue;
continue;
}
}
if (isset($row['action']) & & $row['action'] === 'delete' ) {
if (isset($row['action']) & & 'delete' === $row['action']) {
// Inactive one year later
// Inactive one year later
$userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + $secondsInYear));
$userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + $secondsInYear));
}
}
@ -1005,7 +1005,7 @@ class ImportCsv
$this->logger->addInfo("Students - Username was changes from '".$userInfo['username']."' to '".$row['username']."' ");
$this->logger->addInfo("Students - Username was changes from '".$userInfo['username']."' to '".$row['username']."' ");
}
}
foreach ($row as $key => $value) {
foreach ($row as $key => $value) {
if (substr($key, 0, 6) === 'extra_' ) {
if ('extra_' === substr($key, 0, 6)) {
//an extra field
//an extra field
UserManager::update_extra_field_value(
UserManager::update_extra_field_value(
$userInfo['user_id'],
$userInfo['user_id'],
@ -1020,7 +1020,7 @@ class ImportCsv
}
}
}
}
if (($counter % $batchSize) === 0 ) {
if (0 === ($counter % $batchSize)) {
$em->flush();
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
$em->clear(); // Detaches all objects from Doctrine!
$this->logger->addInfo("Detaches all objects");
$this->logger->addInfo("Detaches all objects");
@ -1091,7 +1091,7 @@ class ImportCsv
'disable_import_calendar'
'disable_import_calendar'
);
);
if (!empty($item) & & isset($item['value']) & & $item['value'] == 1 ) {
if (!empty($item) & & isset($item['value']) & & 1 == $item['value']) {
$this->logger->addInfo(
$this->logger->addInfo(
"Course '".$courseInfo['code']."' has 'disable_import_calendar' turn on. Skip"
"Course '".$courseInfo['code']."' has 'disable_import_calendar' turn on. Skip"
);
);
@ -1101,7 +1101,7 @@ class ImportCsv
if (empty($courseInfo)) {
if (empty($courseInfo)) {
$this->logger->addInfo("Course '$courseCode' does not exists");
$this->logger->addInfo("Course '$courseCode' does not exists");
} else {
} else {
if ($courseInfo['visibility'] == COURSE_VISIBILITY_HIDDEN ) {
if (COURSE_VISIBILITY_HIDDEN == $courseInfo['visibility']) {
$this->logger->addInfo("Course '".$courseInfo['code']."' has hidden visiblity. Skip");
$this->logger->addInfo("Course '".$courseInfo['code']."' has hidden visiblity. Skip");
$errorFound = true;
$errorFound = true;
}
}
@ -1119,7 +1119,7 @@ class ImportCsv
$courseInfo['real_id']
$courseInfo['real_id']
);
);
if ($courseIncluded == false ) {
if (false == $courseIncluded) {
$this->logger->addInfo(
$this->logger->addInfo(
"Course '$courseCode' is not included in session: $sessionId"
"Course '$courseCode' is not included in session: $sessionId"
);
);
@ -1183,7 +1183,7 @@ class ImportCsv
}
}
}
}
if ($errorFound == false ) {
if (false == $errorFound) {
$eventsToCreate[] = [
$eventsToCreate[] = [
'start' => $startDate,
'start' => $startDate,
'end' => $endDate,
'end' => $endDate,
@ -1416,7 +1416,7 @@ class ImportCsv
}
}
// Send announcement to users
// Send announcement to users
if ($sendMail & & $alreadyAdded == false ) {
if ($sendMail & & false == $alreadyAdded) {
$start = $firstDate;
$start = $firstDate;
$end = $firstEndDate;
$end = $firstEndDate;
@ -1448,7 +1448,7 @@ class ImportCsv
'careerid'
'careerid'
);
);
$externalCareerIdList = $externalCareerIdList['value'];
$externalCareerIdList = $externalCareerIdList['value'];
if (substr($externalCareerIdList, 0, 1) === '[' ) {
if ('[' === substr($externalCareerIdList, 0, 1)) {
$externalCareerIdList = substr($externalCareerIdList, 1, -1);
$externalCareerIdList = substr($externalCareerIdList, 1, -1);
$externalCareerIds = preg_split('/,/', $externalCareerIdList);
$externalCareerIds = preg_split('/,/', $externalCareerIdList);
} else {
} else {
@ -1513,7 +1513,7 @@ class ImportCsv
1
1
);
);
if (count($announcementsWithTitleList) === 0 ) {
if (0 === count($announcementsWithTitleList)) {
$this->logger->addInfo(
$this->logger->addInfo(
'Mail to be sent because start date: '.$event['start'].' and no announcement found.'
'Mail to be sent because start date: '.$event['start'].' and no announcement found.'
);
);
@ -1568,7 +1568,7 @@ class ImportCsv
$this->logger->addInfo(
$this->logger->addInfo(
"Send Mail: ".intval($sendMail).' - Already added: '.intval($alreadyAdded)
"Send Mail: ".intval($sendMail).' - Already added: '.intval($alreadyAdded)
);
);
if ($sendMail == false ) {
if (false == $sendMail) {
$report['mail_not_sent_because_date']++;
$report['mail_not_sent_because_date']++;
}
}
}
}
@ -1636,7 +1636,7 @@ class ImportCsv
$this->defaultAdminId
$this->defaultAdminId
);
);
if ($eventResult !== false ) {
if (false !== $eventResult) {
$this->logger->addInfo(
$this->logger->addInfo(
"Event updated #".$item['item_id']." External cal Id: (".$externalEventId.") $info"
"Event updated #".$item['item_id']." External cal Id: (".$externalEventId.") $info"
);
);
@ -1681,7 +1681,7 @@ class ImportCsv
}
}
}
}
if (($counter % $batchSize) === 0 ) {
if (0 === ($counter % $batchSize)) {
$em->flush();
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
$em->clear(); // Detaches all objects from Doctrine!
}
}
@ -2273,7 +2273,7 @@ class ImportCsv
$courseCoachId = UserManager::get_user_id_from_username(
$courseCoachId = UserManager::get_user_id_from_username(
$courseCoach
$courseCoach
);
);
if ($courseCoachId !== false ) {
if (false !== $courseCoachId) {
// Just insert new coaches
// Just insert new coaches
$coachList[] = $courseCoachId;
$coachList[] = $courseCoachId;
}
}
@ -3228,7 +3228,7 @@ $logger->pushHandler(new BufferHandler($stream, 0, $minLevel));
$logger->pushHandler(new RotatingFileHandler('import_csv', 5, $minLevel));
$logger->pushHandler(new RotatingFileHandler('import_csv', 5, $minLevel));
$verbose = false;
$verbose = false;
if (isset($argv[1]) & & $argv[1] === '--verbose') {
if (isset($argv[1]) & & '--verbose' === $argv[1] ) {
$verbose = true;
$verbose = true;
}
}
if ($verbose) {
if ($verbose) {
@ -3246,12 +3246,12 @@ if (isset($_configuration['default_admin_user_id_for_cron'])) {
}
}
// @todo in production disable the dump option
// @todo in production disable the dump option
$dump = false;
$dump = false;
if (isset($argv[1]) & & $argv[1] === '--dump') {
if (isset($argv[1]) & & '--dump' === $argv[1] ) {
$dump = true;
$dump = true;
}
}
if (isset($_configuration['import_csv_disable_dump']) & &
if (isset($_configuration['import_csv_disable_dump']) & &
$_configuration['import_csv_disable_dump'] == true
true == $_configuration['import_csv_disable_dump']
) {
) {
$import->setDumpValues(false);
$import->setDumpValues(false);
} else {
} else {
@ -3287,7 +3287,7 @@ $executionTime = round(($timeEnd - $timeStart) / 60, 2);
$logger->addInfo("Total execution Time $executionTime Min");
$logger->addInfo("Total execution Time $executionTime Min");
if (isset($_configuration['import_csv_fix_permissions']) & &
if (isset($_configuration['import_csv_fix_permissions']) & &
$_configuration['import_csv_fix_permissions'] == true
true == $_configuration['import_csv_fix_permissions']
) {
) {
$command = "sudo find ".api_get_path(SYS_COURSE_PATH)." -type d -exec chmod 777 {} \; ";
$command = "sudo find ".api_get_path(SYS_COURSE_PATH)." -type d -exec chmod 777 {} \; ";
echo "Executing: ".$command.PHP_EOL;
echo "Executing: ".$command.PHP_EOL;