refactor(dbal): Migrate away from Type::getName

Instead use Type::lookupName

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
pull/55674/head
Carl Schwan 2025-10-10 15:52:33 +07:00
parent b0c6ef5821
commit 7a43bf26ca
7 changed files with 10 additions and 29 deletions

@ -30,7 +30,7 @@ class Version1011Date20201120125158 extends SimpleMigrationStep {
if ($schema->hasTable('federated_reshares')) { if ($schema->hasTable('federated_reshares')) {
$table = $schema->getTable('federated_reshares'); $table = $schema->getTable('federated_reshares');
$remoteIdColumn = $table->getColumn('remote_id'); $remoteIdColumn = $table->getColumn('remote_id');
if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { if ($remoteIdColumn && Type::lookupName($remoteIdColumn->getType()) !== Types::STRING) {
$remoteIdColumn->setNotnull(false); $remoteIdColumn->setNotnull(false);
$remoteIdColumn->setType(Type::getType(Types::STRING)); $remoteIdColumn->setType(Type::getType(Types::STRING));
$remoteIdColumn->setOptions(['length' => 255]); $remoteIdColumn->setOptions(['length' => 255]);

@ -88,7 +88,7 @@ class Version11300Date20201120141438 extends SimpleMigrationStep {
} else { } else {
$table = $schema->getTable('share_external'); $table = $schema->getTable('share_external');
$remoteIdColumn = $table->getColumn('remote_id'); $remoteIdColumn = $table->getColumn('remote_id');
if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { if ($remoteIdColumn && Type::lookupName($remoteIdColumn->getType()) !== Types::STRING) {
$remoteIdColumn->setNotnull(false); $remoteIdColumn->setNotnull(false);
$remoteIdColumn->setType(Type::getType(Types::STRING)); $remoteIdColumn->setType(Type::getType(Types::STRING));
$remoteIdColumn->setOptions(['length' => 255]); $remoteIdColumn->setOptions(['length' => 255]);

@ -1268,11 +1268,6 @@
<code><![CDATA[(int)$data['id']]]></code> <code><![CDATA[(int)$data['id']]]></code>
</InvalidArgument> </InvalidArgument>
</file> </file>
<file src="apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php">
<DeprecatedMethod>
<code><![CDATA[getName]]></code>
</DeprecatedMethod>
</file>
<file src="apps/federatedfilesharing/lib/Notifications.php"> <file src="apps/federatedfilesharing/lib/Notifications.php">
<DeprecatedMethod> <DeprecatedMethod>
<code><![CDATA[sendNotification]]></code> <code><![CDATA[sendNotification]]></code>
@ -1709,11 +1704,6 @@
<code><![CDATA[getAppValue]]></code> <code><![CDATA[getAppValue]]></code>
</DeprecatedMethod> </DeprecatedMethod>
</file> </file>
<file src="apps/files_sharing/lib/Migration/Version11300Date20201120141438.php">
<DeprecatedMethod>
<code><![CDATA[getName]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/MountProvider.php"> <file src="apps/files_sharing/lib/MountProvider.php">
<InternalClass> <InternalClass>
<code><![CDATA[new View('/' . $parentShare->getShareOwner() . '/files')]]></code> <code><![CDATA[new View('/' . $parentShare->getShareOwner() . '/files')]]></code>
@ -3054,19 +3044,8 @@
<code><![CDATA[$this->appConfig->getValues($app, false)]]></code> <code><![CDATA[$this->appConfig->getValues($app, false)]]></code>
</FalsableReturnStatement> </FalsableReturnStatement>
</file> </file>
<file src="core/Command/Db/AddMissingPrimaryKeys.php">
<DeprecatedMethod>
<code><![CDATA[hasPrimaryKey]]></code>
</DeprecatedMethod>
</file>
<file src="core/Command/Db/ConvertFilecacheBigInt.php">
<DeprecatedMethod>
<code><![CDATA[getName]]></code>
</DeprecatedMethod>
</file>
<file src="core/Command/Db/ConvertType.php"> <file src="core/Command/Db/ConvertType.php">
<DeprecatedMethod> <DeprecatedMethod>
<code><![CDATA[getName]]></code>
<code><![CDATA[getPrimaryKeyColumns]]></code> <code><![CDATA[getPrimaryKeyColumns]]></code>
</DeprecatedMethod> </DeprecatedMethod>
<InvalidScalarArgument> <InvalidScalarArgument>

@ -70,7 +70,7 @@ class ConvertFilecacheBigInt extends Command {
$column = $table->getColumn($columnName); $column = $table->getColumn($columnName);
$isAutoIncrement = $column->getAutoincrement(); $isAutoIncrement = $column->getAutoincrement();
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement; $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) { if (Type::lookupName($column->getType()) !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
$column->setType(Type::getType(Types::BIGINT)); $column->setType(Type::getType(Types::BIGINT));
$column->setOptions(['length' => 20]); $column->setOptions(['length' => 20]);

@ -10,6 +10,7 @@ namespace OC\Core\Command\Db;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use OC\DB\Connection; use OC\DB\Connection;
use OC\DB\ConnectionFactory; use OC\DB\ConnectionFactory;
use OC\DB\MigrationService; use OC\DB\MigrationService;
@ -379,7 +380,7 @@ class ConvertType extends Command implements CompletionAwareInterface {
return $this->columnTypes[$tableName][$columnName]; return $this->columnTypes[$tableName][$columnName];
} }
$type = $table->getColumn($columnName)->getType()->getName(); $type = Type::lookupName($table->getColumn($columnName)->getType());
switch ($type) { switch ($type) {
case Types::BLOB: case Types::BLOB:

@ -13,6 +13,7 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use OC\App\InfoParser; use OC\App\InfoParser;
use OC\Migration\SimpleOutput; use OC\Migration\SimpleOutput;
use OCP\App\IAppManager; use OCP\App\IAppManager;
@ -579,7 +580,7 @@ class MigrationService {
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
// Oracle doesn't support boolean column with non-null value // Oracle doesn't support boolean column with non-null value
if ($thing->getNotnull() && $thing->getType()->getName() === Types::BOOLEAN) { if ($thing->getNotnull() && Type::lookupName($thing->getType()) === Types::BOOLEAN) {
$thing->setNotnull(false); $thing->setNotnull(false);
} }
} }
@ -591,8 +592,8 @@ class MigrationService {
// If the column was just created OR the length changed OR the type changed // If the column was just created OR the length changed OR the type changed
// we will NOT detect invalid length if the column is not modified // we will NOT detect invalid length if the column is not modified
if (($sourceColumn === null || $sourceColumn->getLength() !== $thing->getLength() || $sourceColumn->getType()->getName() !== Types::STRING) if (($sourceColumn === null || $sourceColumn->getLength() !== $thing->getLength() || Type::lookupName($sourceColumn->getType()) !== Types::STRING)
&& $thing->getLength() > 4000 && $thing->getType()->getName() === Types::STRING) { && $thing->getLength() > 4000 && Type::lookupName($thing->getType()) === Types::STRING) {
throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type String, but exceeding the 4.000 length limit.'); throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type String, but exceeding the 4.000 length limit.');
} }
} }

@ -39,7 +39,7 @@ abstract class BigIntMigration extends SimpleMigrationStep {
foreach ($columns as $columnName) { foreach ($columns as $columnName) {
$column = $table->getColumn($columnName); $column = $table->getColumn($columnName);
if ($column->getType()->getName() !== Types::BIGINT) { if (Type::lookupName($column->getType()) !== Types::BIGINT) {
$column->setType(Type::getType(Types::BIGINT)); $column->setType(Type::getType(Types::BIGINT));
$column->setOptions(['length' => 20]); $column->setOptions(['length' => 20]);
} }