|
|
@@ -46,23 +46,29 @@ class PostUpgradeCommand extends Command
|
|
|
$dbUrl = $_ENV['DATABASE_URL'];
|
|
|
$matches = [];
|
|
|
preg_match(
|
|
|
- "/^mysql:\/\/(\w+):([^\s@]+)@(\w+):(\d+)\/(\w+)/",
|
|
|
+ "/^mysql:\/\/(\w+):([^\s@]+)@([\w\-]+):(\d+)\/(\w+)/",
|
|
|
$dbUrl,
|
|
|
$matches
|
|
|
);
|
|
|
[$dbUser, $dbPwd, $dbHost, $dbPort, $dbName] = array_slice($matches, 1);
|
|
|
|
|
|
- $cnn = new PDO(
|
|
|
+ $opentalentCnn = new PDO(
|
|
|
"mysql:host=" . $dbHost . ";dbname=" . $dbName,
|
|
|
$dbUser,
|
|
|
$dbPwd,
|
|
|
array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
|
|
- $cnn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
+ $opentalentCnn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
|
- $cnn->beginTransaction();
|
|
|
+ $opentalentCnn->beginTransaction();
|
|
|
+
|
|
|
+ $opentassosCnn = new PDO(
|
|
|
+ "mysql:host=prod-front;dbname=openassos",
|
|
|
+ 'dbcloner',
|
|
|
+ 'wWZ4hYcrmHLW2mUK',
|
|
|
+ array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
|
|
|
|
|
try {
|
|
|
- $stmt = $cnn->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');
|
|
|
}
|
|
|
@@ -72,67 +78,59 @@ class PostUpgradeCommand extends Command
|
|
|
$sql = "SELECT d.pid, REGEXP_REPLACE(d.domainName, '^(.+)\\\\.opentalent\\\\.fr$', '\\\\1')
|
|
|
FROM openassos.sys_domain d
|
|
|
where d.domainName like '%.opentalent.fr';";
|
|
|
- $statement = $cnn->query($sql);
|
|
|
+ $statement = $opentassosCnn->query($sql);
|
|
|
|
|
|
foreach ($statement->fetchAll() as $row) {
|
|
|
[$cmsId, $subdomain] = $row;
|
|
|
- $sql = "INSERT INTO opentalent.Subdomain (organization_id, subdomain)
|
|
|
- SELECT o.id, " . $subdomain . "
|
|
|
- from opentalent.Organization o
|
|
|
- where o.cmsId = " . $cmsId . ";";
|
|
|
- $cnn->query($sql);
|
|
|
+ if (!empty($subdomain) and is_numeric($cmsId)) {
|
|
|
+ $sql = "INSERT INTO opentalent.Subdomain (organization_id, subdomain)
|
|
|
+ SELECT o.id, '" . $subdomain . "'
|
|
|
+ from opentalent.Organization o
|
|
|
+ where o.cmsId = " . $cmsId . ";";
|
|
|
+ $opentalentCnn->query($sql);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $sql = "delete
|
|
|
+ $sql = "delete
|
|
|
from opentalent.Subdomain
|
|
|
- where subdomain REGEXP '^(.*)\\\\.(.*)$'
|
|
|
+ where subdomain REGEXP '^(.*)\\\\.(.*)$'
|
|
|
and REGEXP_REPLACE(subdomain, '\\\\.', '-') in (select subdomain from opentalent.Subdomain);";
|
|
|
- $cnn->query($sql);
|
|
|
+ $opentalentCnn->query($sql);
|
|
|
|
|
|
$sql = "update opentalent.Subdomain
|
|
|
set subdomain = REGEXP_REPLACE(subdomain, '\\\\.', '-')
|
|
|
where subdomain REGEXP '^(.*)\\\\.(.*)$';";
|
|
|
- $cnn->query($sql);
|
|
|
+ $opentalentCnn->query($sql);
|
|
|
|
|
|
$this->logger->info('Complete with subdomains from Parameters table');
|
|
|
$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 s.id is null;";
|
|
|
- $cnn->query($sql);
|
|
|
-
|
|
|
- $sql = "insert into opentalent.Subdomain (organization_id, subdomain)
|
|
|
- select o.id, p.subDomain
|
|
|
- from opentalent.Parameters p
|
|
|
- inner join opentalent.Organization o on o.parameters_id = p.id
|
|
|
- inner join opentalent.Subdomain s
|
|
|
- on s.organization_id = o.id
|
|
|
- where p.subDomain not in (select subdomain from opentalent.Subdomain where organization_id=p.id);";
|
|
|
- $cnn->query($sql);
|
|
|
+ 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);";
|
|
|
+ $opentalentCnn->query($sql);
|
|
|
|
|
|
$this->logger->info('Set the current subdomains');
|
|
|
$sql = "update opentalent.Subdomain s set s.active = false;";
|
|
|
- $cnn->query($sql);
|
|
|
+ $opentalentCnn->query($sql);
|
|
|
|
|
|
$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
|
|
|
+ inner join opentalent.Parameters p on p.id = o.parameters_id and s.subdomain = p.subDomain
|
|
|
set s.active = true;";
|
|
|
- $cnn->query($sql);
|
|
|
+ $opentalentCnn->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);
|
|
|
+ $opentalentCnn->query($sql);
|
|
|
|
|
|
- $cnn->commit();
|
|
|
+ $opentalentCnn->commit();
|
|
|
$this->logger->info('Subdomain table was successfully populated');
|
|
|
} catch (\Exception $e) {
|
|
|
- $cnn->rollBack();
|
|
|
+ $opentalentCnn->rollBack();
|
|
|
$this->logger->critical('Error while running the post-upgrade script, abort and rollback');
|
|
|
throw $e;
|
|
|
}
|