1
0

sqlitesessioninit.php 1.8 KB

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