Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable15] Add setup check for pending bigint conversion #12853

Merged
merged 3 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions core/Command/Db/ConvertFilecacheBigInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OC\Core\Command\Db;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
use OC\DB\SchemaWrapper;
use OCP\IDBConnection;
Expand Down Expand Up @@ -51,6 +52,7 @@ protected function configure() {
}

protected function getColumnsByTable() {
// also update in CheckSetupController::hasBigIntConversionPendingColumns()
return [
'activity' => ['activity_id', 'object_id'],
'activity_mq' => ['mail_id'],
Expand All @@ -63,6 +65,7 @@ protected function getColumnsByTable() {
protected function execute(InputInterface $input, OutputInterface $output) {

$schema = new SchemaWrapper($this->connection);
$isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
$updates = [];

$tables = $this->getColumnsByTable();
Expand All @@ -75,11 +78,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {

foreach ($columns as $columnName) {
$column = $table->getColumn($columnName);
if ($column->getType()->getName() !== Type::BIGINT) {
$isAutoIncrement = $column->getAutoincrement();
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) {
$column->setType(Type::getType(Type::BIGINT));
$column->setOptions(['length' => 20]);

$updates[] = $tableName . '.' . $columnName;
$updates[] = '* ' . $tableName . '.' . $columnName;
}
}
}
Expand All @@ -89,6 +94,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
return 0;
}

$output->writeln('<comment>Following columns will be updated:</comment>');
$output->writeln('');
$output->writeln($updates);
$output->writeln('');
$output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>');

if ($input->isInteractive()) {
Expand Down
16 changes: 16 additions & 0 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,22 @@
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.pendingBigIntConversionColumns.length > 0) {
var listOfPendingBigIntConversionColumns = "";
data.pendingBigIntConversionColumns.forEach(function(element){
listOfPendingBigIntConversionColumns += "<li>" + element + "</li>";
});
messages.push({
msg: t(
'core',
'Some columns in the database are missing a conversion to big int. Due to the fact that changing column types on big tables could take some time they were not changed automatically. By running \'occ db:convert-filecache-bigint\' those pending changes could be applied manually. This operation needs to be made while the instance is offline. For further details read <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
{
docLink: oc_defaults.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion'),
}
) + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>",
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.isSqliteUsed) {
messages.push({
msg: t(
Expand Down
39 changes: 26 additions & 13 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -261,7 +262,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -312,7 +314,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -361,7 +364,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -408,7 +412,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -457,7 +462,8 @@ describe('OC.SetupChecks tests', function() {
appDirsWithDifferentOwner: [
'/some/path'
],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -504,7 +510,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -551,7 +558,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -596,9 +604,10 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isMemoryLimitSufficient: false,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
isMemoryLimitSufficient: false
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -666,7 +675,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -714,7 +724,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -762,7 +773,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down Expand Up @@ -810,7 +822,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

Expand Down
36 changes: 36 additions & 0 deletions settings/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
use DirectoryIterator;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
use GuzzleHttp\Exception\ClientException;
use OC;
use OC\AppFramework\Http;
use OC\DB\Connection;
use OC\DB\MissingIndexInformation;
use OC\DB\SchemaWrapper;
use OC\IntegrityCheck\Checker;
use OC\Lock\NoopLockingProvider;
use OC\MemoryInfo;
Expand Down Expand Up @@ -603,6 +605,39 @@ protected function hasRecommendedPHPModules(): array {
return $recommendedPHPModules;
}

protected function hasBigIntConversionPendingColumns(): array {
// copy of ConvertFilecacheBigInt::getColumnsByTable()
$tables = [
'activity' => ['activity_id', 'object_id'],
'activity_mq' => ['mail_id'],
'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
'mimetypes' => ['id'],
'storages' => ['numeric_id'],
];

$schema = new SchemaWrapper($this->db);
$isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
$pendingColumns = [];

foreach ($tables as $tableName => $columns) {
if (!$schema->hasTable($tableName)) {
continue;
}

$table = $schema->getTable($tableName);
foreach ($columns as $columnName) {
$column = $table->getColumn($columnName);
$isAutoIncrement = $column->getAutoincrement();
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) {
$pendingColumns[] = $tableName . '.' . $columnName;
}
}
}

return $pendingColumns;
}

/**
* @return DataResponse
*/
Expand Down Expand Up @@ -643,6 +678,7 @@ public function check() {
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
]
);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Settings/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function setUp() {
'hasOpcacheLoaded',
'getAppDirsWithDifferentOwner',
'hasRecommendedPHPModules',
'hasBigIntConversionPendingColumns',
])->getMock();
}

Expand Down Expand Up @@ -493,6 +494,11 @@ public function testCheck() {
->method('hasRecommendedPHPModules')
->willReturn([]);

$this->checkSetupController
->expects($this->once())
->method('hasBigIntConversionPendingColumns')
->willReturn([]);

$expected = new DataResponse(
[
'isGetenvServerWorking' => true,
Expand Down Expand Up @@ -536,6 +542,7 @@ public function testCheck() {
'isMemoryLimitSufficient' => true,
'appDirsWithDifferentOwner' => [],
'recommendedPHPModules' => [],
'pendingBigIntConversionColumns' => [],
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
Expand Down