Skip to content

Commit

Permalink
Merge branch 'release-3.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 20, 2024
2 parents 929fcc7 + 6ea08bd commit da9fe0a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
99 changes: 99 additions & 0 deletions migrations/Version202412181339442234_taoEventLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoEventLog\migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use oat\generis\persistence\PersistenceManager;
use oat\oatbox\reporting\Report;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\taoEventLog\model\userLastActivityLog\rds\UserLastActivityLogStorage;

final class Version202412181339442234_taoEventLog extends AbstractMigration
{
public function getDescription(): string
{
return sprintf(
'Expand role field for "%s" table',
UserLastActivityLogStorage::TABLE_NAME
);
}

public function up(Schema $schema): void
{
$originalSchema = clone $schema;
$this->updateTable($schema, Type::getType(Types::TEXT));
$this->migrate($originalSchema, $schema);

$this->addReport(
Report::createSuccess(
sprintf(
'Table "%s" successfully updated',
UserLastActivityLogStorage::TABLE_NAME
)
)
);
}

public function down(Schema $schema): void
{
$originalSchema = clone $schema;
$this->updateTable($schema, Type::getType(Types::STRING));
$this->migrate($originalSchema, $schema);

$this->addReport(
Report::createSuccess(
sprintf(
'Table "%s" successfully reverted',
UserLastActivityLogStorage::TABLE_NAME
)
)
);
}

private function updateTable(Schema $schema, Type $filedType): void
{
$userLastActivityLogTable = $schema->getTable(
UserLastActivityLogStorage::TABLE_NAME
);

$userLastActivityLogTable->changeColumn(
UserLastActivityLogStorage::COLUMN_USER_ROLES,
[
'type' => $filedType,
]
);
}

private function migrate(Schema $originalSchema, Schema $schema): void
{
$persistenceManager = $this->getServiceLocator()->get(PersistenceManager::SERVICE_ID);
$persistence = $persistenceManager->getPersistenceById('default');

$queries = $persistence->getPlatForm()->getMigrateSchemaSql($originalSchema, $schema);
foreach ($queries as $query) {
$persistence->exec($query);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static function install($persistence)
$table = $schema->createTable(self::TABLE_NAME);
$table->addOption('engine', 'InnoDB');
$table->addColumn(static::COLUMN_USER_ID, "string", ["length" => 255]);
$table->addColumn(static::COLUMN_USER_ROLES, "string", ["notnull" => true, "length" => 4096]);
$table->addColumn(static::COLUMN_USER_ROLES, "text", ["notnull" => true]);
$table->addColumn(static::COLUMN_ACTION, "string", ["notnull" => false, "length" => 4096]);
$table->addColumn(
static::COLUMN_EVENT_TIME,
Expand Down

0 comments on commit da9fe0a

Please sign in to comment.