Skip to content

Commit

Permalink
Import calendar events by csv: delete event if session doesn't exists.
Browse files Browse the repository at this point in the history
BT#14096
  • Loading branch information
jmontoyaa committed Mar 7, 2018
1 parent fb76863 commit 042c265
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
33 changes: 29 additions & 4 deletions main/cron/import_csv.php
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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']);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Chamilo/CourseBundle/Entity/CCalendarEvent.php
Expand Up @@ -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;
}
}

0 comments on commit 042c265

Please sign in to comment.