]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Command/Calendar2Command.php
Add default values to class member variables
[airbundle] / Command / Calendar2Command.php
index 86be070bca659bb894b8add0788d915b6396a201..c0a739fccdd02d85e52259e8967ea6bd60087fff 100644 (file)
@@ -26,23 +26,14 @@ use Symfony\Contracts\Translation\TranslatorInterface;
 
 use Twig\Extra\Markdown\DefaultMarkdown;
 
-use Rapsys\AirBundle\Entity\Session;
+use Rapsys\AirBundle\Command;
 use Rapsys\AirBundle\Entity\GoogleCalendar;
 use Rapsys\AirBundle\Entity\GoogleToken;
+use Rapsys\AirBundle\Entity\Session;
 
 use Rapsys\PackBundle\Util\SluggerUtil;
 
 class Calendar2Command extends Command {
-       /**
-        * Set default name
-        */
-    protected static $defaultName = 'rapsysair:calendar2';
-
-       /**
-        * Set default description
-        */
-    protected static $defaultDescription = 'Synchronize sessions in users\' calendar';
-
        /**
         * Set google client scopes
         */
@@ -69,22 +60,18 @@ class Calendar2Command extends Command {
 
        /**
         * {@inheritdoc}
-        *
-        * @param string $project The google project
-        * @param string $client The google client
-        * @param string $secret The google secret
         */
-       public function __construct(ManagerRegistry $doctrine, RouterInterface $router, SluggerUtil $slugger, TranslatorInterface $translator, string $locale, string $project, string $client, string $secret) {
+       public function __construct(ManagerRegistry $doctrine, string $locale, RouterInterface $router, SluggerUtil $slugger, TranslatorInterface $translator) {
                //Call parent constructor
-               parent::__construct($doctrine, $router, $slugger, $translator, $locale);
+               parent::__construct($doctrine, $locale, $router, $slugger, $translator);
 
                //Set google client
                $this->client = new Client(
                        [
-                               'application_name' => $project,
-                               'client_id' => $client,
-                               'client_secret' => $secret,
-                               'redirect_uri' => $this->router->generate('rapsys_air_google_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
+                               'application_name' => $_ENV['RAPSYSAIR_GOOGLE_PROJECT'],
+                               'client_id' => $_ENV['RAPSYSAIR_GOOGLE_CLIENT'],
+                               'client_secret' => $_ENV['RAPSYSAIR_GOOGLE_SECRET'],
+                               'redirect_uri' => $this->router->generate('rapsysair_google_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
                                'scopes' => $this->scopes,
                                'access_type' => 'offline',
                                #'login_hint' => $user->getMail(),
@@ -98,10 +85,24 @@ class Calendar2Command extends Command {
                $this->markdown = new DefaultMarkdown;
        }
 
+       /**
+        * Configure attribute command
+        */
+       protected function configure() {
+               //Configure the class
+               $this
+                       //Set name
+                       ->setName('rapsysair:calendar2')
+                       //Set description shown with bin/console list
+                       ->setDescription('Synchronize sessions in users\' calendar')
+                       //Set description shown with bin/console --help airlibre:attribute
+                       ->setHelp('This command synchronize sessions in users\' google calendar');
+       }
+
        /**
         * Process the attribution
         */
-       protected function execute(InputInterface $input, OutputInterface $output) {
+       protected function execute(InputInterface $input, OutputInterface $output): int {
                //Iterate on google tokens
                foreach($tokens = $this->doctrine->getRepository(GoogleToken::class)->findAllIndexed() as $tid => $token) {
                        //Iterate on google calendars
@@ -124,7 +125,7 @@ class Calendar2Command extends Command {
                                //TODO: load all calendar events here ?
 
                                //Iterate on sessions to update
-                               foreach($sessions = $this->doctrine->getRepository(Session::class)->findAllByUserIdSynchronized($token['uid'], $calendar['synchronized'])) {
+                               foreach($sessions = $this->doctrine->getRepository(Session::class)->findAllByUserIdSynchronized($token['uid'], $calendar['synchronized']) as $session) {
                                        //TODO: insert/update/delete events here ?
                                }