SQLiteSessionInit.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\DB;
  8. use Doctrine\Common\EventSubscriber;
  9. use Doctrine\DBAL\Event\ConnectionEventArgs;
  10. use Doctrine\DBAL\Events;
  11. class SQLiteSessionInit implements EventSubscriber {
  12. /**
  13. * @var bool
  14. */
  15. private $caseSensitiveLike;
  16. /**
  17. * @var string
  18. */
  19. private $journalMode;
  20. /**
  21. * Configure case sensitive like for each connection
  22. *
  23. * @param bool $caseSensitiveLike
  24. * @param string $journalMode
  25. */
  26. public function __construct($caseSensitiveLike, $journalMode) {
  27. $this->caseSensitiveLike = $caseSensitiveLike;
  28. $this->journalMode = $journalMode;
  29. }
  30. /**
  31. * @param ConnectionEventArgs $args
  32. * @return void
  33. */
  34. public function postConnect(ConnectionEventArgs $args) {
  35. $sensitive = $this->caseSensitiveLike ? 'true' : 'false';
  36. $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
  37. $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
  38. /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
  39. $connection = $args->getConnection()->getWrappedConnection();
  40. $pdo = $connection->getWrappedConnection();
  41. $pdo->sqliteCreateFunction('md5', 'md5', 1);
  42. }
  43. public function getSubscribedEvents() {
  44. return [Events::postConnect];
  45. }
  46. }