1
0

SQLiteSessionInit.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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\DB;
  25. use Doctrine\DBAL\Event\ConnectionEventArgs;
  26. use Doctrine\DBAL\Events;
  27. use Doctrine\Common\EventSubscriber;
  28. class SQLiteSessionInit implements EventSubscriber {
  29. /**
  30. * @var bool
  31. */
  32. private $caseSensitiveLike;
  33. /**
  34. * @var string
  35. */
  36. private $journalMode;
  37. /**
  38. * Configure case sensitive like for each connection
  39. *
  40. * @param bool $caseSensitiveLike
  41. * @param string $journalMode
  42. */
  43. public function __construct($caseSensitiveLike, $journalMode) {
  44. $this->caseSensitiveLike = $caseSensitiveLike;
  45. $this->journalMode = $journalMode;
  46. }
  47. /**
  48. * @param ConnectionEventArgs $args
  49. * @return void
  50. */
  51. public function postConnect(ConnectionEventArgs $args) {
  52. $sensitive = ($this->caseSensitiveLike) ? 'true' : 'false';
  53. $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
  54. $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
  55. /** @var \PDO $pdo */
  56. $pdo = $args->getConnection()->getWrappedConnection();
  57. $pdo->sqliteCreateFunction('md5', 'md5', 1);
  58. }
  59. public function getSubscribedEvents() {
  60. return array(Events::postConnect);
  61. }
  62. }