127 lines
4.9 KiB
PHP
127 lines
4.9 KiB
PHP
<?php
|
|
namespace Cadoles\CoreBundle\Command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Finder\Finder;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
use Doctrine\DBAL\Connection as DBALConnection;
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
use Cadoles\CoreBundle\Entity\Niveau01;
|
|
use Cadoles\CoreBundle\Entity\Niveau02;
|
|
use Cadoles\CoreBundle\Entity\User;
|
|
use Cadoles\CoreBundle\Entity\Group;
|
|
use Cadoles\CoreBundle\Entity\UserGroup;
|
|
use Cadoles\PortalBundle\Entity\Calendar;
|
|
use Cadoles\PortalBundle\Entity\Blog;
|
|
|
|
use Unirest\Request;
|
|
|
|
global $bdd01;
|
|
global $config;
|
|
|
|
class OnlyCommand extends Command
|
|
{
|
|
private $container;
|
|
private $em;
|
|
private $em2;
|
|
private $output;
|
|
private $filesystem;
|
|
private $rootlog;
|
|
private $only_sync;
|
|
private $only_url;
|
|
private $only_user;
|
|
private $only_password;
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setName('Core:Only')
|
|
->setDescription('Synchronisation Only Office')
|
|
->setHelp('This command Synchro Only Office for Core')
|
|
->addArgument('simulate', InputArgument::OPTIONAL, 'true to simulate / false to run')
|
|
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
|
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
|
;
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$this->container = $this->getApplication()->getKernel()->getContainer();
|
|
$this->em = $this->container->get('doctrine')->getEntityManager();
|
|
$this->output = $output;
|
|
$this->filesystem = new Filesystem();
|
|
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
|
|
|
|
$this->writelnred('');
|
|
$this->writelnred('== Core:Only');
|
|
$this->writelnred('==========================================================================================================');
|
|
|
|
setlocale( LC_CTYPE, 'fr_FR' );
|
|
|
|
$simulate = $input->getArgument('simulate');
|
|
if($simulate=="") $simulate="true";
|
|
|
|
if($simulate!="true"&&$simulate!="false") {
|
|
$this->writeln('Paramétre incorrect');
|
|
return;
|
|
}
|
|
$simulate=($simulate=="true");
|
|
|
|
$this->writeln('');
|
|
if($simulate) $this->writeln('** SIMULATION');
|
|
else $this->writeln('** REEL');
|
|
|
|
$this->writeln('');
|
|
$this->writeln('=====================================================');
|
|
$this->writeln('== SYNCHONISATION ONLY OFFICE =======================');
|
|
$this->writeln('=====================================================');
|
|
|
|
$this->only_sync = true;
|
|
$this->only_url = "https://transnum.oo.pp.ac-dijon.fr"."/api/2.0/";
|
|
$this->only_user = "admin";
|
|
$this->only_password = "brigitte89!";
|
|
|
|
if($this->only_sync) {
|
|
// Only Office est-il dans le domaine
|
|
if(stripos($this->only_url,"/")===0)
|
|
$this->only_url="https://".$this->container->getParameter("weburl").$this->only_url;
|
|
$indomaine = (stripos($this->only_url,$this->container->getParameter("weburl"))!==false);
|
|
|
|
// Si hors domaine on utilise le proxy si proxy il y a
|
|
if(!$indomaine) {
|
|
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue();
|
|
if($PROXYactivate) {
|
|
$PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue();
|
|
$PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue();
|
|
\Unirest\Request::proxy($PROXYserver, $PROXYport, CURLPROXY_HTTP, true);
|
|
}
|
|
}
|
|
|
|
// Récupération des informations utilisateurs issus du masteridentity
|
|
$headers = ['Accept' => 'application/json'];
|
|
$query = array('userName' => $this->only_user, 'password' => $this->only_password);
|
|
$body = json_encode($query);
|
|
$response = \Unirest\Request::post($this->only_url.'/authentication',$headers,$body);
|
|
}
|
|
|
|
$this->writeln('');
|
|
return 1;
|
|
}
|
|
|
|
private function writelnred($string) {
|
|
$this->output->writeln('<fg=red>'.$string.'</>');
|
|
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
|
}
|
|
private function writeln($string) {
|
|
$this->output->writeln($string);
|
|
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
|
}
|
|
|
|
|
|
}
|