2023-08-02 18:27:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* Icinga Web 2 | (c) 2023 Icinga GmbH | GPLv2+ */
|
|
|
|
|
|
|
|
namespace Icinga\Application\ProvidedHook;
|
|
|
|
|
|
|
|
use Icinga\Application\Hook\MigrationHook;
|
|
|
|
use Icinga\Common\Database;
|
|
|
|
use Icinga\Model\Schema;
|
|
|
|
use ipl\Orm\Query;
|
|
|
|
|
|
|
|
class DbMigration extends MigrationHook
|
|
|
|
{
|
|
|
|
use Database;
|
|
|
|
|
|
|
|
public function getName(): string
|
|
|
|
{
|
2023-09-12 17:00:43 +02:00
|
|
|
return $this->translate('Icinga Web');
|
2023-08-02 18:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providedDescriptions(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersion(): string
|
|
|
|
{
|
|
|
|
if ($this->version === null) {
|
|
|
|
$conn = $this->getDb();
|
2023-09-12 16:57:53 +02:00
|
|
|
$schemaQuery = $this->getSchemaQuery()
|
2023-08-02 18:27:55 +02:00
|
|
|
->orderBy('id', SORT_DESC)
|
|
|
|
->limit(2);
|
|
|
|
|
|
|
|
if (static::getColumnType($conn, $schemaQuery->getModel()->getTableName(), 'success')) {
|
|
|
|
/** @var Schema $schema */
|
|
|
|
foreach ($schemaQuery as $schema) {
|
|
|
|
if ($schema->success) {
|
|
|
|
$this->version = $schema->version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->version) {
|
|
|
|
$this->version = '2.12.0';
|
|
|
|
}
|
|
|
|
} elseif (static::tableExists($conn, $schemaQuery->getModel()->getTableName())) {
|
|
|
|
$this->version = '2.11.0';
|
|
|
|
} elseif (static::tableExists($conn, 'icingaweb_rememberme')) {
|
|
|
|
$randomIvType = static::getColumnType($conn, 'icingaweb_rememberme', 'random_iv');
|
|
|
|
if ($randomIvType === 'varchar(32)') {
|
|
|
|
$this->version = '2.9.1';
|
|
|
|
} else {
|
|
|
|
$this->version = '2.9.0';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$usernameType = static::getColumnType($conn, 'icingaweb_group_membership', 'username');
|
|
|
|
if ($usernameType === 'varchar(254)') {
|
|
|
|
$this->version = '2.5.0';
|
|
|
|
} else {
|
|
|
|
$this->version = '2.0.0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->version;
|
|
|
|
}
|
|
|
|
|
2023-09-12 16:57:53 +02:00
|
|
|
protected function getSchemaQuery(): Query
|
2023-08-02 18:27:55 +02:00
|
|
|
{
|
2023-09-12 16:57:53 +02:00
|
|
|
return Schema::on($this->getDb());
|
2023-08-02 18:27:55 +02:00
|
|
|
}
|
|
|
|
}
|