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.

SQLiteSessionInit.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\DB;
  27. use Doctrine\Common\EventSubscriber;
  28. use Doctrine\DBAL\Event\ConnectionEventArgs;
  29. use Doctrine\DBAL\Events;
  30. class SQLiteSessionInit implements EventSubscriber {
  31. /**
  32. * @var bool
  33. */
  34. private $caseSensitiveLike;
  35. /**
  36. * @var string
  37. */
  38. private $journalMode;
  39. /**
  40. * Configure case sensitive like for each connection
  41. *
  42. * @param bool $caseSensitiveLike
  43. * @param string $journalMode
  44. */
  45. public function __construct($caseSensitiveLike, $journalMode) {
  46. $this->caseSensitiveLike = $caseSensitiveLike;
  47. $this->journalMode = $journalMode;
  48. }
  49. /**
  50. * @param ConnectionEventArgs $args
  51. * @return void
  52. */
  53. public function postConnect(ConnectionEventArgs $args) {
  54. $sensitive = $this->caseSensitiveLike ? 'true' : 'false';
  55. $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
  56. $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
  57. /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
  58. $connection = $args->getConnection()->getWrappedConnection();
  59. $pdo = $connection->getWrappedConnection();
  60. $pdo->sqliteCreateFunction('md5', 'md5', 1);
  61. }
  62. public function getSubscribedEvents() {
  63. return [Events::postConnect];
  64. }
  65. }