Skip to content

Commit 772b6fc

Browse files
committed
Add setup check for pending bigint conversion
Signed-off-by: Morris Jobke <[email protected]>
1 parent f57e334 commit 772b6fc

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

core/Command/Db/ConvertFilecacheBigInt.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected function configure() {
5252
}
5353

5454
protected function getColumnsByTable() {
55+
// also update in CheckSetupController::hasBigIntConversionPendingColumns()
5556
return [
5657
'activity' => ['activity_id', 'object_id'],
5758
'activity_mq' => ['mail_id'],

core/js/setupchecks.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,22 @@
337337
type: OC.SetupChecks.MESSAGE_TYPE_INFO
338338
})
339339
}
340+
if (data.pendingBigIntConversionColumns.length > 0) {
341+
var listOfPendingBigIntConversionColumns = "";
342+
data.pendingBigIntConversionColumns.forEach(function(element){
343+
listOfPendingBigIntConversionColumns += "<li>" + element + "</li>";
344+
});
345+
messages.push({
346+
msg: t(
347+
'core',
348+
'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>.',
349+
{
350+
docLink: oc_defaults.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion'),
351+
}
352+
) + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>",
353+
type: OC.SetupChecks.MESSAGE_TYPE_INFO
354+
})
355+
}
340356
if (data.isSqliteUsed) {
341357
messages.push({
342358
msg: t(

settings/Controller/CheckSetupController.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
use DirectoryIterator;
3535
use Doctrine\DBAL\DBALException;
3636
use Doctrine\DBAL\Platforms\SqlitePlatform;
37+
use Doctrine\DBAL\Types\Type;
3738
use GuzzleHttp\Exception\ClientException;
3839
use OC;
3940
use OC\AppFramework\Http;
4041
use OC\DB\Connection;
4142
use OC\DB\MissingIndexInformation;
43+
use OC\DB\SchemaWrapper;
4244
use OC\IntegrityCheck\Checker;
4345
use OC\Lock\NoopLockingProvider;
4446
use OC\MemoryInfo;
@@ -603,6 +605,39 @@ protected function hasRecommendedPHPModules(): array {
603605
return $recommendedPHPModules;
604606
}
605607

608+
protected function hasBigIntConversionPendingColumns(): array {
609+
// copy of ConvertFilecacheBigInt::getColumnsByTable()
610+
$tables = [
611+
'activity' => ['activity_id', 'object_id'],
612+
'activity_mq' => ['mail_id'],
613+
'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
614+
'mimetypes' => ['id'],
615+
'storages' => ['numeric_id'],
616+
];
617+
618+
$schema = new SchemaWrapper($this->db);
619+
$isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
620+
$pendingColumns = [];
621+
622+
foreach ($tables as $tableName => $columns) {
623+
if (!$schema->hasTable($tableName)) {
624+
continue;
625+
}
626+
627+
$table = $schema->getTable($tableName);
628+
foreach ($columns as $columnName) {
629+
$column = $table->getColumn($columnName);
630+
$isAutoIncrement = $column->getAutoincrement();
631+
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
632+
if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) {
633+
$pendingColumns[] = $tableName . '.' . $columnName;
634+
}
635+
}
636+
}
637+
638+
return $pendingColumns;
639+
}
640+
606641
/**
607642
* @return DataResponse
608643
*/
@@ -643,6 +678,7 @@ public function check() {
643678
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
644679
'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
645680
'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
681+
'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
646682
]
647683
);
648684
}

tests/Settings/Controller/CheckSetupControllerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function setUp() {
159159
'hasOpcacheLoaded',
160160
'getAppDirsWithDifferentOwner',
161161
'hasRecommendedPHPModules',
162+
'hasBigIntConversionPendingColumns',
162163
])->getMock();
163164
}
164165

@@ -493,6 +494,11 @@ public function testCheck() {
493494
->method('hasRecommendedPHPModules')
494495
->willReturn([]);
495496

497+
$this->checkSetupController
498+
->expects($this->once())
499+
->method('hasBigIntConversionPendingColumns')
500+
->willReturn([]);
501+
496502
$expected = new DataResponse(
497503
[
498504
'isGetenvServerWorking' => true,
@@ -536,6 +542,7 @@ public function testCheck() {
536542
'isMemoryLimitSufficient' => true,
537543
'appDirsWithDifferentOwner' => [],
538544
'recommendedPHPModules' => [],
545+
'pendingBigIntConversionColumns' => [],
539546
]
540547
);
541548
$this->assertEquals($expected, $this->checkSetupController->check());

0 commit comments

Comments
 (0)