1
0

SQLiteSessionInit.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }