From 9759014d2a2430ed3e8cd12ebe46e71885d63c14 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Rapha=C3=ABl=20Gertz?= <git@rapsys.eu>
Date: Wed, 28 Feb 2024 12:15:50 +0100
Subject: [PATCH] Add configure member function Remove useless static variables
 Update execute function prototype

---
 Command/Calendar2Command.php | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/Command/Calendar2Command.php b/Command/Calendar2Command.php
index 86be070..76d5c4c 100644
--- a/Command/Calendar2Command.php
+++ b/Command/Calendar2Command.php
@@ -33,16 +33,6 @@ use Rapsys\AirBundle\Entity\GoogleToken;
 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
 	 */
@@ -98,10 +88,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 +128,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 ?
 				}
 
-- 
2.41.3