2014-09-17 15:47:33 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-02-26 13:37:37 +03:00
|
|
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
2014-09-17 15:47:33 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-09-17 15:47:33 +04:00
|
|
|
namespace OC\DB;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
|
|
|
use Doctrine\DBAL\Events;
|
|
|
|
use Doctrine\Common\EventSubscriber;
|
|
|
|
|
|
|
|
class SQLiteSessionInit implements EventSubscriber {
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $caseSensitiveLike;
|
|
|
|
|
2014-10-29 19:23:27 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $journalMode;
|
|
|
|
|
2014-09-17 15:47:33 +04:00
|
|
|
/**
|
|
|
|
* Configure case sensitive like for each connection
|
|
|
|
*
|
|
|
|
* @param bool $caseSensitiveLike
|
2014-10-29 19:23:27 +03:00
|
|
|
* @param string $journalMode
|
2014-09-17 15:47:33 +04:00
|
|
|
*/
|
2014-10-29 19:23:27 +03:00
|
|
|
public function __construct($caseSensitiveLike, $journalMode) {
|
2014-09-17 15:47:33 +04:00
|
|
|
$this->caseSensitiveLike = $caseSensitiveLike;
|
2014-10-29 19:23:27 +03:00
|
|
|
$this->journalMode = $journalMode;
|
2014-09-17 15:47:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ConnectionEventArgs $args
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function postConnect(ConnectionEventArgs $args) {
|
|
|
|
$sensitive = ($this->caseSensitiveLike) ? 'true' : 'false';
|
|
|
|
$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
|
2014-10-29 19:23:27 +03:00
|
|
|
$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
|
2014-09-17 15:47:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSubscribedEvents() {
|
|
|
|
return array(Events::postConnect);
|
|
|
|
}
|
|
|
|
}
|