]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Command/RekeyCommand.php
Add rekey feature
[airbundle] / Command / RekeyCommand.php
diff --git a/Command/RekeyCommand.php b/Command/RekeyCommand.php
new file mode 100644 (file)
index 0000000..91d7967
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace Rapsys\AirBundle\Command;
+
+use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use Rapsys\AirBundle\Entity\Session;
+
+class RekeyCommand extends DoctrineCommand {
+       //Set failure constant
+       const FAILURE = 1;
+
+       ///Set success constant
+       const SUCCESS = 0;
+
+       ///Configure attribute command
+       protected function configure() {
+               //Configure the class
+               $this
+                       //Set name
+                       ->setName('rapsysair:rekey')
+                       //Set description shown with bin/console list
+                       ->setDescription('Rekey sessions')
+                       //Set description shown with bin/console --help airlibre:attribute
+                       ->setHelp('This command rekey sessions in chronological order');
+       }
+
+       ///Process the attribution
+       protected function execute(InputInterface $input, OutputInterface $output) {
+               //Fetch doctrine
+               $doctrine = $this->getDoctrine();
+
+               //Rekey sessions
+               if (!$doctrine->getRepository(Session::class)->rekey()) {
+                       //Return failure
+                       return self::FAILURE;
+               }
+
+               //Return success
+               return self::SUCCESS;
+       }
+
+       /**
+        * Return the bundle alias
+        *
+        * {@inheritdoc}
+        */
+       public function getAlias(): string {
+               return 'rapsys_air';
+       }
+}