diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index 65b5201c4b1..4a22d830eff 100755 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -868,7 +868,6 @@ private function importCalendarStatic($file, $moveFile = true) $this->logger->addInfo("external_sessionID: ".$externalSessionId." does not exists."); } $teacherId = null; - if (!empty($sessionId) && !empty($courseInfo)) { $courseIncluded = SessionManager::relation_session_course_exist( $sessionId, @@ -944,9 +943,7 @@ private function importCalendarStatic($file, $moveFile = true) } if (empty($eventsToCreate)) { - $this->logger->addInfo( - "No events to add" - ); + $this->logger->addInfo("No events to add"); return 0; } @@ -1045,6 +1042,34 @@ private function importCalendarStatic($file, $moveFile = true) $em->flush(); } } + $this->logger->addInfo('Move from course #'.$calendarEvent->getCId().' to #'.$courseInfo['real_id']); + + // Checking if session still exists + $calendarSessionId = (int) $calendarEvent->getSessionId(); + if (!empty($calendarSessionId)) { + $calendarSessionInfo = api_get_session_info($calendarSessionId); + if (empty($calendarSessionInfo)) { + $calendarId = (int) $calendarEvent->getIid(); + + // Delete calendar events because the session was deleted! + $this->logger->addInfo( + "Delete event # $calendarId because session # $calendarSessionId doesn't exist" + ); + + $sql = "DELETE FROM c_calendar_event + WHERE iid = $calendarId AND session_id = $calendarSessionId"; + Database::query($sql); + $this->logger->addInfo($sql); + + $sql = "DELETE FROM c_item_property + WHERE + tool = 'calendar_event' AND + ref = $calendarSessionId AND + session_id = $calendarSessionId"; + Database::query($sql); + $this->logger->addInfo($sql); + } + } } else { $this->logger->addInfo('Calendar event not found '.$item['item_id']); } diff --git a/src/Chamilo/CourseBundle/Entity/CCalendarEvent.php b/src/Chamilo/CourseBundle/Entity/CCalendarEvent.php index 8ce58531c8a..2d552f717f1 100644 --- a/src/Chamilo/CourseBundle/Entity/CCalendarEvent.php +++ b/src/Chamilo/CourseBundle/Entity/CCalendarEvent.php @@ -378,4 +378,22 @@ public function setColor($color) return $this; } + + /** + * @return int + */ + public function getIid() + { + return $this->iid; + } + + /** + * @param int $iid + * @return CCalendarEvent + */ + public function setIid($iid) + { + $this->iid = $iid; + return $this; + } }