From 1231735b5135ca02bd381b70482c052d2a90bdc9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 30 Aug 2017 14:10:43 +0200 Subject: [PATCH] Revert "SQLiteJournal: checking for extension pdo_sqlite is lazy, service cache.journal is created always" This can leads to unexpected error 500 when GC is started. This reverts commit 7212326d59d0d40dc81e3ce8a5bd146bc1cf6be4. --- src/Bridges/CacheDI/CacheExtension.php | 12 ++++++++---- src/Caching/Storages/SQLiteJournal.php | 7 +++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Bridges/CacheDI/CacheExtension.php b/src/Bridges/CacheDI/CacheExtension.php index 0477117c..c56f849b 100644 --- a/src/Bridges/CacheDI/CacheExtension.php +++ b/src/Bridges/CacheDI/CacheExtension.php @@ -29,16 +29,20 @@ public function loadConfiguration() { $builder = $this->getContainerBuilder(); - $builder->addDefinition($this->prefix('journal')) - ->setClass(Nette\Caching\Storages\IJournal::class) - ->setFactory(Nette\Caching\Storages\SQLiteJournal::class, [$this->tempDir . '/cache/journal.s3db']); + if (extension_loaded('pdo_sqlite')) { + $builder->addDefinition($this->prefix('journal')) + ->setClass(Nette\Caching\Storages\IJournal::class) + ->setFactory(Nette\Caching\Storages\SQLiteJournal::class, [$this->tempDir . '/cache/journal.s3db']); + } $builder->addDefinition($this->prefix('storage')) ->setClass(Nette\Caching\IStorage::class) ->setFactory(Nette\Caching\Storages\FileStorage::class, [$this->tempDir . '/cache']); if ($this->name === 'cache') { - $builder->addAlias('nette.cacheJournal', $this->prefix('journal')); + if (extension_loaded('pdo_sqlite')) { + $builder->addAlias('nette.cacheJournal', $this->prefix('journal')); + } $builder->addAlias('cacheStorage', $this->prefix('storage')); } } diff --git a/src/Caching/Storages/SQLiteJournal.php b/src/Caching/Storages/SQLiteJournal.php index 323cc6f1..4b338e28 100644 --- a/src/Caching/Storages/SQLiteJournal.php +++ b/src/Caching/Storages/SQLiteJournal.php @@ -30,16 +30,15 @@ class SQLiteJournal implements IJournal */ public function __construct($path) { + if (!extension_loaded('pdo_sqlite')) { + throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.'); + } $this->path = $path; } private function open() { - if (!extension_loaded('pdo_sqlite')) { - throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.'); - } - if ($this->path !== ':memory:' && !is_file($this->path)) { touch($this->path); // ensures ordinary file permissions }