2018-01-03 18:36:34 +03:00
|
|
|
<?php
|
2020-05-12 16:04:42 +03:00
|
|
|
|
2019-02-13 13:17:02 +03:00
|
|
|
declare(strict_types=1);
|
2018-01-03 18:36:34 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-09-05 15:29:09 +03:00
|
|
|
namespace OCA\Talk\Migration;
|
2018-01-03 18:36:34 +03:00
|
|
|
|
2021-01-08 13:08:02 +03:00
|
|
|
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
2018-01-17 13:39:31 +03:00
|
|
|
use OCP\DB\ISchemaWrapper;
|
2018-01-12 17:17:45 +03:00
|
|
|
use OCP\IConfig;
|
2018-01-03 18:36:34 +03:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\Migration\SimpleMigrationStep;
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
|
|
|
|
class Version2001Date20180103144447 extends SimpleMigrationStep {
|
2022-04-06 18:43:03 +03:00
|
|
|
protected IDBConnection $connection;
|
2018-01-03 18:36:34 +03:00
|
|
|
|
2022-04-06 18:43:03 +03:00
|
|
|
protected IConfig $config;
|
2018-01-12 17:17:45 +03:00
|
|
|
|
2019-02-13 13:17:02 +03:00
|
|
|
public function __construct(IDBConnection $connection,
|
|
|
|
IConfig $config) {
|
2018-01-03 18:36:34 +03:00
|
|
|
$this->connection = $connection;
|
2018-01-12 17:17:45 +03:00
|
|
|
$this->config = $config;
|
2018-01-03 18:36:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IOutput $output
|
2018-01-17 13:39:31 +03:00
|
|
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
2018-01-03 18:36:34 +03:00
|
|
|
* @param array $options
|
2018-01-17 13:39:31 +03:00
|
|
|
* @return null|ISchemaWrapper
|
2018-01-03 18:36:34 +03:00
|
|
|
* @since 13.0.0
|
|
|
|
*/
|
2019-02-13 13:17:02 +03:00
|
|
|
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
2018-01-17 13:39:31 +03:00
|
|
|
/** @var ISchemaWrapper $schema */
|
2018-01-03 18:36:34 +03:00
|
|
|
$schema = $schemaClosure();
|
|
|
|
|
|
|
|
$table = $schema->getTable('talk_rooms');
|
|
|
|
|
|
|
|
if (!$table->hasColumn('active_since')) {
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('active_since', Types::DATETIME_MUTABLE, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => false,
|
|
|
|
]);
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('active_guests', Types::INTEGER, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
'default' => 0,
|
|
|
|
'unsigned' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = $schema->getTable('talk_participants');
|
|
|
|
|
|
|
|
if (!$table->hasColumn('user_id')) {
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('user_id', Types::STRING, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => false,
|
|
|
|
'length' => 255,
|
|
|
|
]);
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('room_id', Types::INTEGER, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 11,
|
2018-01-04 12:46:12 +03:00
|
|
|
'default' => 0,
|
|
|
|
'unsigned' => true,
|
2018-01-03 18:36:34 +03:00
|
|
|
]);
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('last_ping', Types::INTEGER, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 11,
|
2018-01-04 12:46:12 +03:00
|
|
|
'default' => 0,
|
|
|
|
'unsigned' => true,
|
2018-01-03 18:36:34 +03:00
|
|
|
]);
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('session_id', Types::STRING, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 255,
|
2020-09-08 11:34:50 +03:00
|
|
|
'default' => '0',
|
2018-01-03 18:36:34 +03:00
|
|
|
]);
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('participant_type', Types::SMALLINT, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 6,
|
|
|
|
'default' => 0,
|
2018-01-04 12:46:12 +03:00
|
|
|
'unsigned' => true,
|
2018-01-03 18:36:34 +03:00
|
|
|
]);
|
2021-01-08 13:08:02 +03:00
|
|
|
$table->addColumn('in_call', Types::BOOLEAN, [
|
2018-01-03 18:36:34 +03:00
|
|
|
'default' => 0,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IOutput $output
|
2018-01-17 13:39:31 +03:00
|
|
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
2018-01-03 18:36:34 +03:00
|
|
|
* @param array $options
|
|
|
|
* @since 13.0.0
|
|
|
|
*/
|
2019-02-13 13:17:02 +03:00
|
|
|
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
|
2018-01-12 18:15:01 +03:00
|
|
|
if (version_compare($this->config->getAppValue('spreed', 'installed_version', '0.0.0'), '2.0.0', '<')) {
|
2018-01-12 17:17:45 +03:00
|
|
|
// Migrations only work after 2.0.0
|
2018-01-03 18:36:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-08 13:08:02 +03:00
|
|
|
if (!$this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) {
|
2018-01-12 17:34:30 +03:00
|
|
|
$update = $this->connection->getQueryBuilder();
|
|
|
|
$update->update('talk_rooms')
|
|
|
|
->set('active_since', 'activeSince')
|
|
|
|
->set('active_guests', 'activeGuests');
|
2021-10-19 14:15:51 +03:00
|
|
|
$update->executeStatement();
|
2018-01-12 17:34:30 +03:00
|
|
|
|
|
|
|
$update = $this->connection->getQueryBuilder();
|
|
|
|
$update->update('talk_participants')
|
|
|
|
->set('user_id', 'userId')
|
|
|
|
->set('room_id', 'roomId')
|
|
|
|
->set('last_ping', 'lastPing')
|
|
|
|
->set('session_id', 'sessionId')
|
|
|
|
->set('participant_type', 'participantType')
|
|
|
|
->set('in_call', 'inCall');
|
2021-10-19 14:15:51 +03:00
|
|
|
$update->executeStatement();
|
2018-01-12 17:34:30 +03:00
|
|
|
} else {
|
|
|
|
$update = $this->connection->getQueryBuilder();
|
|
|
|
$update->update('talk_rooms')
|
|
|
|
->set('active_since', 'activesince')
|
|
|
|
->set('active_guests', 'activeguests');
|
2021-10-19 14:15:51 +03:00
|
|
|
$update->executeStatement();
|
2018-01-12 17:34:30 +03:00
|
|
|
|
|
|
|
$update = $this->connection->getQueryBuilder();
|
|
|
|
$update->update('talk_participants')
|
|
|
|
->set('user_id', 'userid')
|
|
|
|
->set('room_id', 'roomid')
|
|
|
|
->set('last_ping', 'lastping')
|
|
|
|
->set('session_id', 'sessionid')
|
|
|
|
->set('participant_type', 'participanttype')
|
|
|
|
->set('in_call', 'incall');
|
2021-10-19 14:15:51 +03:00
|
|
|
$update->executeStatement();
|
2018-01-12 17:34:30 +03:00
|
|
|
}
|
2018-01-03 18:36:34 +03:00
|
|
|
}
|
|
|
|
}
|