Browse Source

update all cli command: add the --delete option

Olivier Massot 4 năm trước cách đây
mục cha
commit
04d9cc2639
1 tập tin đã thay đổi với 19 bổ sung2 xóa
  1. 19 2
      ot_admin/Classes/Command/UpdateSiteCommand.php

+ 19 - 2
ot_admin/Classes/Command/UpdateSiteCommand.php

@@ -4,6 +4,7 @@ namespace Opentalent\OtAdmin\Command;
 
 
 use Opentalent\OtAdmin\Controller\SiteController;
+use Opentalent\OtCore\Exception\NoSuchOrganizationException;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
@@ -46,6 +47,13 @@ class UpdateSiteCommand extends Command
                 'organization-id',
                 InputArgument::OPTIONAL,
                 "The organization's id in the opentalent DB"
+            )
+            ->addOption(
+                'delete',
+                null,
+                InputOption::VALUE_NONE,
+                "Performs a soft deletion of the websites when the organization does not exist anymore " .
+                "in the Opentalent DB. (This only applies if the --all option is used)"
             );
     }
 
@@ -60,7 +68,7 @@ class UpdateSiteCommand extends Command
     {
         $org_id = $input->getArgument('organization-id');
         $all = $input->getOption('all');
-        $hard = $input->getOption('hard');
+        $delete = $input->getOption('delete');
 
         if ($all && $org_id) {
             throw new \InvalidArgumentException("You can not pass both an organization id and the --all option");
@@ -68,6 +76,9 @@ class UpdateSiteCommand extends Command
         if (!$all && !$org_id) {
             throw new \InvalidArgumentException("You shall either pass an organization id or use the --all option");
         }
+        if (!$all && $delete) {
+            throw new \InvalidArgumentException("The delete option only applies when the --all option is passed");
+        }
 
         $io = new SymfonyStyle($input, $output);
 
@@ -90,6 +101,12 @@ class UpdateSiteCommand extends Command
                 $org_id = $site['organization_id'];
                 try {
                     $siteController->updateSiteAction($org_id);
+                } catch (NoSuchOrganizationException $e) {
+                    if ($delete) {
+                        $siteController->deleteSiteAction($org_id);
+                    } else {
+                        throw $e;
+                    }
                 } catch (\Throwable $e) {
                     $io->error('Organization Id: ' . $org_id . ' - ' . $e->getMessage());
                 }
@@ -99,7 +116,7 @@ class UpdateSiteCommand extends Command
 
             $io->success(sprintf("The websites have all been updated"));
         } else {
-            $rootUid = $siteController->updateSiteAction($org_id, $hard);
+            $rootUid = $siteController->updateSiteAction($org_id);
             $io->success(sprintf("The website with root uid " . $rootUid . " has been updated"));
         }
     }