1
0

DatabasePendingBigIntConversions.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
  5. *
  6. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\SetupChecks;
  25. use Doctrine\DBAL\Types\BigIntType;
  26. use OC\Core\Command\Db\ConvertFilecacheBigInt;
  27. use OC\DB\Connection;
  28. use OC\DB\SchemaWrapper;
  29. use OCP\EventDispatcher\IEventDispatcher;
  30. use OCP\IDBConnection;
  31. use OCP\IL10N;
  32. use OCP\IURLGenerator;
  33. use OCP\SetupCheck\ISetupCheck;
  34. use OCP\SetupCheck\SetupResult;
  35. class DatabasePendingBigIntConversions implements ISetupCheck {
  36. public function __construct(
  37. private IL10N $l10n,
  38. private IURLGenerator $urlGenerator,
  39. private Connection $db,
  40. private IEventDispatcher $dispatcher,
  41. private IDBConnection $connection,
  42. ) {
  43. }
  44. public function getCategory(): string {
  45. return 'database';
  46. }
  47. public function getName(): string {
  48. return $this->l10n->t('Database pending bigint migrations');
  49. }
  50. protected function getBigIntConversionPendingColumns(): array {
  51. $tables = ConvertFilecacheBigInt::getColumnsByTable();
  52. $schema = new SchemaWrapper($this->db);
  53. $isSqlite = $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE;
  54. $pendingColumns = [];
  55. foreach ($tables as $tableName => $columns) {
  56. if (!$schema->hasTable($tableName)) {
  57. continue;
  58. }
  59. $table = $schema->getTable($tableName);
  60. foreach ($columns as $columnName) {
  61. $column = $table->getColumn($columnName);
  62. $isAutoIncrement = $column->getAutoincrement();
  63. $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
  64. if (!($column->getType() instanceof BigIntType) && !$isAutoIncrementOnSqlite) {
  65. $pendingColumns[] = $tableName . '.' . $columnName;
  66. }
  67. }
  68. }
  69. return $pendingColumns;
  70. }
  71. public function run(): SetupResult {
  72. $pendingColumns = $this->getBigIntConversionPendingColumns();
  73. if (empty($pendingColumns)) {
  74. return SetupResult::success('None');
  75. } else {
  76. $list = '';
  77. foreach ($pendingColumns as $pendingColumn) {
  78. $list .= "\n$pendingColumn";
  79. }
  80. $list .= "\n";
  81. return SetupResult::info(
  82. $this->l10n->t('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.').$list,
  83. $this->urlGenerator->linkToDocs('admin-bigint-conversion')
  84. );
  85. }
  86. }
  87. }