You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.3 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Setup;
  25. use OC\DB\ConnectionFactory;
  26. class Sqlite extends AbstractDatabase {
  27. public $dbprettyname = 'Sqlite';
  28. public function validate($config) {
  29. return [];
  30. }
  31. public function initialize($config) {
  32. /*
  33. * Web: When using web based installer its not possible to set dbname
  34. * or dbtableprefix. Defaults used from ConnectionFactory and dbtype = 'sqlite'
  35. * is written to config.php.
  36. *
  37. * Cli: When --database-name or --database-table-prefix empty or default
  38. * dbtype = 'sqlite' is written to config.php. If you choose a value different
  39. * from default these values are written to config.php. This is required because
  40. * in connection factory configuration is obtained from config.php.
  41. */
  42. $this->dbName = empty($config['dbname'])
  43. ? ConnectionFactory::DEFAULT_DBNAME
  44. : $config['dbname'];
  45. $this->tablePrefix = empty($config['dbtableprefix'])
  46. ? ConnectionFactory::DEFAULT_DBTABLEPREFIX
  47. : $config['dbtableprefix'];
  48. if ($this->dbName !== ConnectionFactory::DEFAULT_DBNAME) {
  49. $this->config->setValue('dbname', $this->dbName);
  50. }
  51. if ($this->tablePrefix !== ConnectionFactory::DEFAULT_DBTABLEPREFIX) {
  52. $this->config->setValue('dbtableprefix', $this->tablePrefix);
  53. }
  54. }
  55. public function setupDatabase($username) {
  56. $datadir = $this->config->getValue(
  57. 'datadirectory',
  58. \OC::$SERVERROOT . '/data'
  59. );
  60. $sqliteFile = $datadir . '/' . $this->dbName . 'db';
  61. if (file_exists($sqliteFile)) {
  62. unlink($sqliteFile);
  63. }
  64. }
  65. }