Sqlite.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Setup;
  24. use OC\DB\ConnectionFactory;
  25. class Sqlite extends AbstractDatabase {
  26. public $dbprettyname = 'Sqlite';
  27. public function validate($config) {
  28. return array();
  29. }
  30. public function initialize($config) {
  31. /*
  32. * Web: When using web based installer its not possible to set dbname
  33. * or dbtableprefix. Defaults used from ConnectionFactory and dbtype = 'sqlite'
  34. * is written to config.php.
  35. *
  36. * Cli: When --database-name or --database-table-prefix empty or default
  37. * dbtype = 'sqlite' is written to config.php. If you choose a value different
  38. * from default these values are written to config.php. This is required because
  39. * in connection factory configuration is obtained from config.php.
  40. */
  41. $this->dbName = empty($config['dbname'])
  42. ? ConnectionFactory::DEFAULT_DBNAME
  43. : $config['dbname'];
  44. $this->tablePrefix = empty($config['dbtableprefix'])
  45. ? ConnectionFactory::DEFAULT_DBTABLEPREFIX
  46. : $config['dbtableprefix'];
  47. if ($this->dbName !== ConnectionFactory::DEFAULT_DBNAME) {
  48. $this->config->setValue('dbname', $this->dbName);
  49. }
  50. if ($this->tablePrefix !== ConnectionFactory::DEFAULT_DBTABLEPREFIX) {
  51. $this->config->setValue('dbtableprefix', $this->tablePrefix);
  52. }
  53. }
  54. public function setupDatabase($username) {
  55. $datadir = $this->config->getValue(
  56. 'datadirectory',
  57. \OC::$SERVERROOT . '/data'
  58. );
  59. $sqliteFile = $datadir . '/' . $this->dbName . 'db';
  60. if (file_exists($sqliteFile)) {
  61. unlink($sqliteFile);
  62. }
  63. }
  64. }