2015-07-30 04:57:16 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2024-05-24 13:43:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-07-30 04:57:16 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Core\Command\Db;
|
|
|
|
|
|
2021-01-03 09:28:31 -05:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2017-02-03 10:24:53 -05:00
|
|
|
use OC\DB\MySqlTools;
|
2015-07-30 04:57:16 -04:00
|
|
|
use OC\Migration\ConsoleOutput;
|
|
|
|
|
use OC\Repair\Collation;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\IURLGenerator;
|
2022-03-17 12:26:27 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-07-30 04:57:16 -04:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class ConvertMysqlToMB4 extends Command {
|
2022-03-17 12:26:27 -04:00
|
|
|
public function __construct(
|
2023-06-12 10:37:03 -04:00
|
|
|
private IConfig $config,
|
|
|
|
|
private IDBConnection $connection,
|
|
|
|
|
private IURLGenerator $urlGenerator,
|
|
|
|
|
private LoggerInterface $logger,
|
2022-03-17 12:26:27 -04:00
|
|
|
) {
|
2015-07-30 04:57:16 -04:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
|
$this
|
|
|
|
|
->setName('db:convert-mysql-charset')
|
|
|
|
|
->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4');
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 08:54:51 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2021-01-03 09:28:31 -05:00
|
|
|
if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
|
2015-07-30 04:57:16 -04:00
|
|
|
$output->writeln("This command is only valid for MySQL/MariaDB databases.");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-03 10:24:53 -05:00
|
|
|
$tools = new MySqlTools();
|
|
|
|
|
if (!$tools->supports4ByteCharset($this->connection)) {
|
2017-03-21 18:08:05 -04:00
|
|
|
$url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4');
|
2015-07-30 04:57:16 -04:00
|
|
|
$output->writeln("The database is not properly setup to use the charset utf8mb4.");
|
|
|
|
|
$output->writeln("For more information please read the documentation at $url");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-03 10:24:53 -05:00
|
|
|
// enable charset
|
|
|
|
|
$this->config->setSystemValue('mysql.utf8mb4', true);
|
|
|
|
|
|
2015-07-30 04:57:16 -04:00
|
|
|
// run conversion
|
|
|
|
|
$coll = new Collation($this->config, $this->logger, $this->connection, false);
|
|
|
|
|
$coll->run(new ConsoleOutput($output));
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|