X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/4f1511980043fca288c364b794e540af1c54f95e..ff9e7c39f22c3a65b416c8f00a7a0f1f83e16758:/Command/CalendarCommand.php?ds=inline diff --git a/Command/CalendarCommand.php b/Command/CalendarCommand.php index 25c45ca..2968f48 100644 --- a/Command/CalendarCommand.php +++ b/Command/CalendarCommand.php @@ -108,7 +108,7 @@ class CalendarCommand extends Command { //Retrieve cache object //XXX: by default stored in /tmp/symfony-cache/@/W/3/6SEhFfeIW4UMDlAII+Dg //XXX: stored in %kernel.project_dir%/var/cache/airlibre/0/P/IA20X0K4dkMd9-+Ohp9Q - $cache = new FilesystemAdapter($this->config['cache']['namespace'], $this->config['cache']['lifetime'], $this->config['cache']['directory']); + $cache = new FilesystemAdapter($this->config['cache']['namespace'], $this->config['cache']['lifetime'], $this->config['path']['cache']); //Retrieve calendars $cacheCalendars = $cache->getItem('calendars'); @@ -147,10 +147,7 @@ class CalendarCommand extends Command { //With expired token if ($exp = $googleClient->isAccessTokenExpired()) { //Refresh token - if ($googleClient->getRefreshToken()) { - //Retrieve refreshed token - $googleToken = $googleClient->fetchAccessTokenWithRefreshToken($googleClient->getRefreshToken()); - + if (($refreshToken = $googleClient->getRefreshToken()) && ($googleToken = $googleClient->fetchAccessTokenWithRefreshToken($refreshToken)) && empty($googleToken['error'])) { //Add refreshed token $calendars[$clientId]['tokens'][$googleToken['access_token']] = [ 'calendar' => $token['calendar'], @@ -174,7 +171,15 @@ class CalendarCommand extends Command { unset($calendars[$clientId]); } + //Save calendars + $cacheCalendars->set($calendars); + + //Save calendar + $cache->save($cacheCalendars); + //Drop token and report + //XXX: submit app to avoid expiration + //XXX: see https://console.cloud.google.com/apis/credentials/consent?project=calendar-317315 echo 'Token '.$tokenId.' for calendar '.$token['calendar'].' has expired and is not refreshable'."\n"; //Return failure @@ -278,6 +283,7 @@ class CalendarCommand extends Command { foreach($sessions as $sessionId => $session) { //Init shared properties //TODO: validate for constraints here ??? https://developers.google.com/calendar/api/guides/extended-properties + //TODO: drop shared as unused ??? $shared = [ 'gps' => $session['l_latitude'].','.$session['l_longitude'] ]; @@ -289,38 +295,37 @@ class CalendarCommand extends Command { ]; //Init description - #$description = '
Description
'.$markdown->convert(strip_tags(str_replace(["\r", "\n\n"], ['', "\n"], $session['p_description']))).'
'; - $description = '
Description
'.$markdown->convert(strip_tags($session['p_description'])).'
'; + $description = 'Description :'."\n".strip_tags(preg_replace('!([^<]+)!', '\1', $markdown->convert(strip_tags($session['p_description'])))); + $shared['description'] = $markdown->convert(strip_tags($session['p_description'])); //Add class when available if (!empty($session['p_class'])) { $shared['class'] = $session['p_class']; - #$description .= '
Classe
'.$markdown->convert(strip_tags(str_replace(["\r", "\n\n"], ['', "\n"], $session['p_class']))).'
'; - $description .= '
Classe

'.$session['p_class'].'

'; + $description .= "\n\n".'Classe :'."\n".$session['p_class']; } //Add contact when available if (!empty($session['p_contact'])) { $shared['contact'] = $session['p_contact']; - $description .= '
Contacter

'.$session['p_contact'].'

'; + $description .= "\n\n".'Contact :'."\n".$session['p_contact']; } //Add donate when available if (!empty($session['p_donate'])) { $shared['donate'] = $session['p_donate']; - $description .= '
Contribuer

'.$session['p_donate'].'

'; + $description .= "\n\n".'Contribuer :'."\n".$session['p_donate']; } //Add link when available if (!empty($session['p_link'])) { $shared['link'] = $session['p_link']; - $description .= '
Site

'.$session['p_link'].'

'; + $description .= "\n\n".'Site :'."\n".$session['p_link']; } //Add profile when available if (!empty($session['p_profile'])) { $shared['profile'] = $session['p_profile']; - $description .= '
Réseau social

'.$session['p_profile'].'

'; + $description .= "\n\n".'Réseau social :'."\n".$session['p_profile']; } //Locked session @@ -349,7 +354,7 @@ class CalendarCommand extends Command { //TODO: replace 'airlibre' with $this->config['calendar']['prefix'] when possible with prefix validating [a-v0-9]{5,} //XXX: see https://developers.google.com/calendar/api/v3/reference/events/insert#id 'id' => $token['prefix'].$sessionId, - 'summary' => $session['au_pseudonym'].' '.$this->translator->trans('at '.$session['l_short']), + 'summary' => $session['au_pseudonym'].' '.$this->translator->trans('at '.$session['l_title']), #'description' => $markdown->convert(strip_tags($session['p_description'])), 'description' => $description, 'status' => empty($session['a_canceled'])?'confirmed':'cancelled', @@ -388,10 +393,9 @@ class CalendarCommand extends Command { $event = $events[$sessionId]; //With updated event - #if ($session['updated'] >= (new \DateTime($event->getUpdated()))) { - { + if ($session['updated'] >= (new \DateTime($event->getUpdated()))) { //Set summary - $event->setSummary($session['au_pseudonym'].' '.$this->translator->trans('at '.$session['l_short'])); + $event->setSummary($session['au_pseudonym'].' '.$this->translator->trans('at '.$session['l_title'])); //Set description $event->setDescription($description); @@ -436,7 +440,7 @@ class CalendarCommand extends Command { $end->setDateTime($session['stop']->format(\DateTime::ISO8601)); try { - //Insert the event + //Update the event $updatedEvent = $googleCalendar->events->update($token['calendar'], $event->getId(), $event); //Catch exception } catch(\Google\Service\Exception $e) {