|
|
@@ -2,7 +2,6 @@
|
|
|
|
|
|
namespace App\Commands\PostUpgrade\V0_2;
|
|
|
|
|
|
-use PDO;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
@@ -15,31 +14,35 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|
|
)]
|
|
|
class PostUpgradeCommand extends Command
|
|
|
{
|
|
|
- public const TARGETED_VERSION = "0.2";
|
|
|
+ public const TARGETED_VERSION = '0.2';
|
|
|
|
|
|
- public function __construct(private LoggerInterface $logger) {
|
|
|
+ public function __construct(private LoggerInterface $logger)
|
|
|
+ {
|
|
|
parent::__construct();
|
|
|
}
|
|
|
|
|
|
protected function configure(): void
|
|
|
- {}
|
|
|
+ {
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
{
|
|
|
- $this->logger->info('Run post-upgrade scripts for version ' . self::TARGETED_VERSION);
|
|
|
+ $this->logger->info('Run post-upgrade scripts for version '.self::TARGETED_VERSION);
|
|
|
|
|
|
$this->populateSubdomains();
|
|
|
$this->genEventsUuid();
|
|
|
$this->updateFilesStatuses();
|
|
|
|
|
|
- $output->writeln("Post-upgrade operations successfully executed");
|
|
|
+ $output->writeln('Post-upgrade operations successfully executed');
|
|
|
+
|
|
|
return Command::SUCCESS;
|
|
|
}
|
|
|
|
|
|
- private function getOpentalentConnexion(): PDO {
|
|
|
+ private function getOpentalentConnexion(): \PDO
|
|
|
+ {
|
|
|
$dbUrl = $_ENV['DATABASE_URL'];
|
|
|
$matches = [];
|
|
|
preg_match(
|
|
|
@@ -49,17 +52,19 @@ class PostUpgradeCommand extends Command
|
|
|
);
|
|
|
[$dbUser, $dbPwd, $dbHost, $dbPort, $dbName] = array_slice($matches, 1);
|
|
|
|
|
|
- $opentalentCnn = new PDO(
|
|
|
- "mysql:host=" . $dbHost . ";dbname=" . $dbName,
|
|
|
+ $opentalentCnn = new \PDO(
|
|
|
+ 'mysql:host='.$dbHost.';dbname='.$dbName,
|
|
|
$dbUser,
|
|
|
$dbPwd,
|
|
|
- array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
|
|
- $opentalentCnn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
+ [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
|
|
+ $opentalentCnn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
|
|
+
|
|
|
return $opentalentCnn;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Populate the new Subdomain table
|
|
|
+ * Populate the new Subdomain table.
|
|
|
+ *
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
private function populateSubdomains(): void
|
|
|
@@ -68,14 +73,14 @@ class PostUpgradeCommand extends Command
|
|
|
|
|
|
$opentalentCnn->beginTransaction();
|
|
|
|
|
|
- $openassosCnn = new PDO(
|
|
|
- "mysql:host=prod-front;dbname=openassos",
|
|
|
+ $openassosCnn = new \PDO(
|
|
|
+ 'mysql:host=prod-front;dbname=openassos',
|
|
|
'dbcloner',
|
|
|
'wWZ4hYcrmHLW2mUK',
|
|
|
- array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
|
|
+ [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
|
|
|
|
|
try {
|
|
|
- $stmt = $opentalentCnn->query("select count(*) from opentalent.Subdomain;");
|
|
|
+ $stmt = $opentalentCnn->query('select count(*) from opentalent.Subdomain;');
|
|
|
if ($stmt->fetchColumn(0)[0] > 0) {
|
|
|
throw new \RuntimeException('Subdomain table is not empty');
|
|
|
}
|
|
|
@@ -83,11 +88,11 @@ class PostUpgradeCommand extends Command
|
|
|
$this->logger->info('Populate with reserved subdomains');
|
|
|
$reservedSubdomains = [
|
|
|
'app', 'my', 'api', 'ap2i', 'assistance', 'local', 'ressources', 'logs', 'stats', 'support', 'preprod',
|
|
|
- 'test', 'admin', 'statistiques', 'drive', 'cloud', 'git', 'frames', 'v6', 'v59', 'www', 'myadmin'
|
|
|
+ 'test', 'admin', 'statistiques', 'drive', 'cloud', 'git', 'frames', 'v6', 'v59', 'www', 'myadmin',
|
|
|
];
|
|
|
foreach ($reservedSubdomains as $reserved) {
|
|
|
$sql = "insert into opentalent.Subdomain (organization_id, subdomain, active)
|
|
|
- values (13, '" . $reserved . "', 0);";
|
|
|
+ values (13, '".$reserved."', 0);";
|
|
|
$opentalentCnn->query($sql);
|
|
|
}
|
|
|
|
|
|
@@ -102,9 +107,9 @@ class PostUpgradeCommand extends Command
|
|
|
[$cmsId, $subdomain] = $row;
|
|
|
if (!empty($subdomain) and is_numeric($cmsId)) {
|
|
|
$sql = "INSERT INTO opentalent.Subdomain (organization_id, subdomain)
|
|
|
- SELECT o.id, '" . $subdomain . "'
|
|
|
+ SELECT o.id, '".$subdomain."'
|
|
|
from opentalent.Organization o
|
|
|
- where o.cmsId = " . $cmsId . ";";
|
|
|
+ where o.cmsId = ".$cmsId.';';
|
|
|
$opentalentCnn->query($sql);
|
|
|
}
|
|
|
}
|
|
|
@@ -121,22 +126,22 @@ class PostUpgradeCommand extends Command
|
|
|
$opentalentCnn->query($sql);
|
|
|
|
|
|
$this->logger->info('Complete with subdomains from Parameters table');
|
|
|
- $sql = "insert into opentalent.Subdomain (organization_id, subdomain)
|
|
|
+ $sql = 'insert into opentalent.Subdomain (organization_id, subdomain)
|
|
|
select distinct o.id, p.subDomain
|
|
|
from opentalent.Parameters p
|
|
|
inner join opentalent.Organization o on o.parameters_id = p.id
|
|
|
left join opentalent.Subdomain s on s.organization_id = o.id
|
|
|
- where p.subDomain is not null and not p.subDomain in (select subdomain from opentalent.Subdomain);";
|
|
|
+ where p.subDomain is not null and not p.subDomain in (select subdomain from opentalent.Subdomain);';
|
|
|
$opentalentCnn->query($sql);
|
|
|
|
|
|
$this->logger->info('Set the current subdomains');
|
|
|
- $sql = "update opentalent.Subdomain s set s.active = false;";
|
|
|
+ $sql = 'update opentalent.Subdomain s set s.active = false;';
|
|
|
$opentalentCnn->query($sql);
|
|
|
|
|
|
- $sql = "update opentalent.Subdomain s
|
|
|
+ $sql = 'update opentalent.Subdomain s
|
|
|
inner join opentalent.Organization o on o.id = s.organization_id
|
|
|
inner join opentalent.Parameters p on p.id = o.parameters_id and s.subdomain = p.subDomain
|
|
|
- set s.active = true;";
|
|
|
+ set s.active = true;';
|
|
|
$opentalentCnn->query($sql);
|
|
|
|
|
|
$this->logger->info('Set the custom domains');
|
|
|
@@ -154,7 +159,8 @@ class PostUpgradeCommand extends Command
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function genEventsUuid(): void {
|
|
|
+ private function genEventsUuid(): void
|
|
|
+ {
|
|
|
$opentalentCnn = $this->getOpentalentConnexion();
|
|
|
|
|
|
$opentalentCnn->beginTransaction();
|
|
|
@@ -163,10 +169,10 @@ class PostUpgradeCommand extends Command
|
|
|
$this->logger->info('Generate events uuids');
|
|
|
|
|
|
// Generating Uuid1 with native mysql function
|
|
|
- $sql = "update opentalent.Booking set uuid = UUID();";
|
|
|
+ $sql = 'update opentalent.Booking set uuid = UUID();';
|
|
|
$opentalentCnn->query($sql);
|
|
|
|
|
|
- $sql = "update opentalent.AwinProduct set uuid = UUID();";
|
|
|
+ $sql = 'update opentalent.AwinProduct set uuid = UUID();';
|
|
|
$opentalentCnn->query($sql);
|
|
|
|
|
|
$opentalentCnn->commit();
|
|
|
@@ -178,7 +184,8 @@ class PostUpgradeCommand extends Command
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function updateFilesStatuses():void {
|
|
|
+ private function updateFilesStatuses(): void
|
|
|
+ {
|
|
|
$opentalentCnn = $this->getOpentalentConnexion();
|
|
|
|
|
|
$opentalentCnn->beginTransaction();
|