1
0

Sqlite.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Setup;
  8. use OC\DB\ConnectionFactory;
  9. class Sqlite extends AbstractDatabase {
  10. public $dbprettyname = 'Sqlite';
  11. public function validate($config) {
  12. return [];
  13. }
  14. public function initialize($config) {
  15. /*
  16. * Web: When using web based installer its not possible to set dbname
  17. * or dbtableprefix. Defaults used from ConnectionFactory and dbtype = 'sqlite'
  18. * is written to config.php.
  19. *
  20. * Cli: When --database-name or --database-table-prefix empty or default
  21. * dbtype = 'sqlite' is written to config.php. If you choose a value different
  22. * from default these values are written to config.php. This is required because
  23. * in connection factory configuration is obtained from config.php.
  24. */
  25. $this->dbName = empty($config['dbname'])
  26. ? ConnectionFactory::DEFAULT_DBNAME
  27. : $config['dbname'];
  28. $this->tablePrefix = empty($config['dbtableprefix'])
  29. ? ConnectionFactory::DEFAULT_DBTABLEPREFIX
  30. : $config['dbtableprefix'];
  31. if ($this->dbName !== ConnectionFactory::DEFAULT_DBNAME) {
  32. $this->config->setValue('dbname', $this->dbName);
  33. }
  34. if ($this->tablePrefix !== ConnectionFactory::DEFAULT_DBTABLEPREFIX) {
  35. $this->config->setValue('dbtableprefix', $this->tablePrefix);
  36. }
  37. }
  38. public function setupDatabase($username) {
  39. $datadir = $this->config->getValue(
  40. 'datadirectory',
  41. \OC::$SERVERROOT . '/data'
  42. );
  43. $sqliteFile = $datadir . '/' . $this->dbName . 'db';
  44. if (file_exists($sqliteFile)) {
  45. unlink($sqliteFile);
  46. }
  47. }
  48. }