gestion exception caldav et acces dans le reseau interne

This commit is contained in:
afornerot 2021-02-22 12:00:11 +01:00
parent cd9cff085c
commit d4c2274d34
1 changed files with 32 additions and 12 deletions

View File

@ -13,6 +13,7 @@ use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Validator\Constraints\DateTime;
use it\thecsea\simple_caldav_client\SimpleCalDAVClient;
use it\thecsea\simple_caldav_client\CalDAVException;
use Cadoles\PortalBundle\Entity\Calendarevent;
@ -437,7 +438,6 @@ class SynchroICSCommand extends Command
$idcalendar = $input->getArgument('idcalendar');
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue();
$PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYserver"])->getValue();
$PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYport"])->getValue();
@ -461,6 +461,7 @@ class SynchroICSCommand extends Command
case 1:
$this->writeln($calendar->getId()." = ICS = ".$calendar->getUrl());
$client = new CalFileParser();
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue();
try {
if($PROXYactivate)
@ -555,25 +556,44 @@ class SynchroICSCommand extends Command
// CalDav
case 2:
$this->writeln($calendar->getId()." = CalDAV = ".$calendar->getUrl());
// Création du client calDAV
$this->writeln("");
$this->writeln($calendar->getId()." = CalDAV = ".$calendar->getUrl());
// Récupération du mode proxy
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue();
$client = new SimpleCalDAVClient();
try {
if($PROXYactivate)
// En mode proxy on tente la connection via le proxy
if($PROXYactivate) {
$client = new SimpleCalDAVClient();
try {
@$client->connect($calendar->getUrl(), $calendar->getLogin(), $calendar->getPasswordDecrypt(),['proxy_host'=>$PROXYserver.":".$PROXYport,'timeout'=>5]);
else
}
catch (CalDAVException $e) {
// Si KO on tente la meme connection mais sans le proxy
$PROXYactivate = false;
$this->writeln("Tentative de connection sans proxy");
}
}
if(!$PROXYactivate) {
$client = new SimpleCalDAVClient();
try {
@$client->connect($calendar->getUrl(), $calendar->getLogin(), $calendar->getPasswordDecrypt(),['timeout'=>5]);
}
catch (Exception $e) {
dump($e->__toString());
break;
}
catch (CalDAVException $e) {
$this->writelnred("");
$this->writelnred("KO = ".$e->getMessage());
break;
}
}
$this->writeln("Connected");
$this->writeln("");
$tbuid=array();
$arrayOfCalendars = $client->findCalendars("afornerot");
$arrayOfCalendars = $client->findCalendars();
foreach($arrayOfCalendars as $calcalendar) {
$this->writeln($calcalendar->getDisplayName());
if($calcalendar->getDisplayName()!=$calendar->getCaldavname()) continue;
$client->setCalendar($calcalendar);