2014-09-17 07:47:33 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2014-09-17 07:47:33 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-09-17 07:47:33 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\DB;
|
|
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use Doctrine\Common\EventSubscriber;
|
2014-09-17 07:47:33 -04:00
|
|
|
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
|
|
|
|
use Doctrine\DBAL\Events;
|
|
|
|
|
|
|
|
|
|
class SQLiteSessionInit implements EventSubscriber {
|
|
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $caseSensitiveLike;
|
|
|
|
|
|
2014-10-29 12:23:27 -04:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $journalMode;
|
|
|
|
|
|
2014-09-17 07:47:33 -04:00
|
|
|
/**
|
|
|
|
|
* Configure case sensitive like for each connection
|
|
|
|
|
*
|
|
|
|
|
* @param bool $caseSensitiveLike
|
2014-10-29 12:23:27 -04:00
|
|
|
* @param string $journalMode
|
2014-09-17 07:47:33 -04:00
|
|
|
*/
|
2014-10-29 12:23:27 -04:00
|
|
|
public function __construct($caseSensitiveLike, $journalMode) {
|
2014-09-17 07:47:33 -04:00
|
|
|
$this->caseSensitiveLike = $caseSensitiveLike;
|
2014-10-29 12:23:27 -04:00
|
|
|
$this->journalMode = $journalMode;
|
2014-09-17 07:47:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ConnectionEventArgs $args
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function postConnect(ConnectionEventArgs $args) {
|
2018-01-26 17:46:40 -05:00
|
|
|
$sensitive = $this->caseSensitiveLike ? 'true' : 'false';
|
2014-09-17 07:47:33 -04:00
|
|
|
$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
|
2014-10-29 12:23:27 -04:00
|
|
|
$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
|
2021-01-03 09:28:31 -05:00
|
|
|
/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
|
|
|
|
|
$connection = $args->getConnection()->getWrappedConnection();
|
|
|
|
|
$pdo = $connection->getWrappedConnection();
|
2017-01-16 10:16:32 -05:00
|
|
|
$pdo->sqliteCreateFunction('md5', 'md5', 1);
|
2014-09-17 07:47:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSubscribedEvents() {
|
2020-03-26 04:30:18 -04:00
|
|
|
return [Events::postConnect];
|
2014-09-17 07:47:33 -04:00
|
|
|
}
|
|
|
|
|
}
|