Forráskód Böngészése

update Parameters and Subdomain entities, and v0.2 post-upgrade script

Olivier Massot 3 éve
szülő
commit
6a96167b85

+ 0 - 1
.env

@@ -12,7 +12,6 @@
 #
 # Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
 # https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
-VERSION=0.2
 
 ###> symfony/framework-bundle ###
 APP_ENV=prod

+ 19 - 17
src/Commands/PostUpgrade/V0_2/PostUpgradeCommand.php

@@ -24,16 +24,12 @@ class PostUpgradeCommand extends Command
     protected function configure(): void
     {}
 
+    /**
+     * @throws \Exception
+     */
     protected function execute(InputInterface $input, OutputInterface $output): int
     {
-        $version = $_ENV['VERSION'];
-        if ($version !== self::TARGETED_VERSION) {
-            throw new \RuntimeException(
-                'Targeted version (' . self::TARGETED_VERSION . ') is different from ' .
-                'current version (' . $version . ')'
-            );
-        }
-        $this->logger->info('Run post-upgrade scripts for version ' . $version);
+        $this->logger->info('Run post-upgrade scripts for version ' . self::TARGETED_VERSION);
 
         $this->populateSubdomains();
 
@@ -49,16 +45,12 @@ class PostUpgradeCommand extends Command
 
         $dbUrl = $_ENV['DATABASE_URL'];
         $matches = [];
-        $match = preg_match(
+        preg_match(
             "/^mysql:\/\/(\w+):([^\s@]+)@(\w+):(\d+)\/(\w+)/",
             $dbUrl,
             $matches
         );
-        $dbUser = $matches[1];
-        $dbPwd = $matches[2];
-        $dbHost = $matches[3];
-        $dbPort = $matches[4];
-        $dbName = $matches[5];
+        [$dbUser, $dbPwd, $dbHost, $dbPort, $dbName] = array_slice($matches, 1);
 
         $cnn = new PDO(
             "mysql:host=" . $dbHost . ";dbname=" . $dbName,
@@ -101,9 +93,19 @@ class PostUpgradeCommand extends Command
             $cnn->query($sql);
 
             $this->logger->info('Set the current subdomains');
-            $sql = "update opentalent.Parameters p
-                    inner join opentalent.Subdomain s on s.parameters_id = p.id and s.subdomain = p.subDomain 
-                    set p.activeSubdomain_id = s.id;";
+            $sql = "update opentalent.Subdomain s set s.active = false;";
+            $cnn->query($sql);
+
+            $sql = "update opentalent.Subdomain s
+                    inner join opentalent.Parameters p 
+                    on s.parameters_id = p.id and s.subdomain = p.subDomain 
+                    set s.active = true;";
+            $cnn->query($sql);
+
+            $this->logger->info('Set the custom domains');
+            $sql = "update opentalent.Parameters
+                    set customDomain = otherWebsite
+                    where otherWebsite not like '%.opentalent.fr'";
             $cnn->query($sql);
 
             $cnn->commit();

+ 19 - 3
src/Entity/Organization/Parameters.php

@@ -80,6 +80,9 @@ class Parameters
     #[ORM\Column(length: 150, nullable: true)]
     private ?string $otherWebsite = null;
 
+    #[ORM\Column(length: 150, nullable: true)]
+    private ?string $customDomain = null;
+
     #[ORM\Column(options: ['default' => false])]
     private bool $desactivateOpentalentSiteWeb = false;
 
@@ -160,9 +163,6 @@ class Parameters
     #[ORM\Column(options: ['default' => false])]
     private bool $sendAttendanceSms = false;
 
-    #[ORM\OneToOne(targetEntity: Subdomain::class, cascade: ['persist'], fetch: 'EAGER')]
-    private ?Subdomain $activeSubdomain = null;
-
     #[ORM\OneToMany( mappedBy: 'parameters', targetEntity: Subdomain::class)]
     #[ApiSubresource]
     private Collection $subdomains;
@@ -333,6 +333,22 @@ class Parameters
         return $this;
     }
 
+    /**
+     * @return string|null
+     */
+    public function getCustomDomain(): ?string
+    {
+        return $this->customDomain;
+    }
+
+    /**
+     * @param string|null $customDomain
+     */
+    public function setCustomDomain(?string $customDomain): void
+    {
+        $this->customDomain = $customDomain;
+    }
+
     public function getDesactivateOpentalentSiteWeb(): bool
     {
         return $this->desactivateOpentalentSiteWeb;

+ 19 - 0
src/Entity/Organization/Subdomain.php

@@ -33,6 +33,9 @@ class Subdomain
     #[ORM\Column(length: 60, nullable: false)]
     private string $subdomain;
 
+    #[ORM\Column(options: ['default' => false])]
+    private bool $active = false;
+
     /**
      * @return int|null
      */
@@ -80,4 +83,20 @@ class Subdomain
     {
         $this->subdomain = $subdomain;
     }
+
+    /**
+     * @return bool
+     */
+    public function isActive(): bool
+    {
+        return $this->active;
+    }
+
+    /**
+     * @param bool $active
+     */
+    public function setActive(bool $active): void
+    {
+        $this->active = $active;
+    }
 }