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) 2018, ownCloud GmbH
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
24namespace OC\DB;
25
26use Doctrine\DBAL\Event\ConnectionEventArgs;
27use Doctrine\DBAL\Events;
28use Doctrine\Common\EventSubscriber;
29
30class SQLiteSessionInit implements EventSubscriber {
31	/**
32	 * @var bool
33	 */
34	private $caseSensitiveLike;
35
36	/**
37	 * @var string
38	 */
39	private $journalMode;
40
41	/**
42	 * Configure case sensitive like for each connection
43	 *
44	 * @param bool $caseSensitiveLike
45	 * @param string $journalMode
46	 */
47	public function __construct($caseSensitiveLike, $journalMode) {
48		$this->caseSensitiveLike = $caseSensitiveLike;
49		$this->journalMode = $journalMode;
50	}
51
52	/**
53	 * @param ConnectionEventArgs $args
54	 * @return void
55	 */
56	public function postConnect(ConnectionEventArgs $args) {
57		$sensitive = ($this->caseSensitiveLike) ? 'true' : 'false';
58		$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
59		$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
60	}
61
62	public function getSubscribedEvents() {
63		return [Events::postConnect];
64	}
65}
66