1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: jensk |
4
|
|
|
* Date: 21-2-2017 |
5
|
|
|
* Time: 17:05 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace library\search; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use library\storage\JsonStorage; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Abstract Class SearchDbConnected |
15
|
|
|
* Handles connection with the search index database |
16
|
|
|
* @package library\search |
17
|
|
|
*/ |
18
|
|
|
abstract class SearchDbConnected |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var resource |
22
|
|
|
*/ |
23
|
|
|
protected $searchDbHandle; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \library\storage\JsonStorage |
27
|
|
|
*/ |
28
|
|
|
protected $storage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Indexer constructor. |
32
|
|
|
* |
33
|
|
|
* @param \library\storage\JsonStorage $storage |
34
|
|
|
*/ |
35
|
|
|
public function __construct(JsonStorage $storage) |
36
|
|
|
{ |
37
|
|
|
$this->storageDir = $storage->getStorageDir(); |
|
|
|
|
38
|
|
|
$this->storage = $storage; |
39
|
|
|
$this->initializeDb(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function initializeDb() |
43
|
|
|
{ |
44
|
|
|
if (!$this->isDatabaseConfigured()) { |
45
|
|
|
$this->configureDatabase(); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function configureDatabase() |
50
|
|
|
{ |
51
|
|
|
$db = $this->getSearchDbHandle(); |
52
|
|
|
$sqlPath = __DIR__ . DIRECTORY_SEPARATOR . '../cc/install/search.sql'; |
53
|
|
|
$searchSql = file_get_contents($sqlPath); |
54
|
|
|
$db->exec($searchSql); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function isDatabaseConfigured() |
58
|
|
|
{ |
59
|
|
|
$db = $this->getSearchDbHandle(); |
60
|
|
|
$stmt = $db->query('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'term_count\';'); |
61
|
|
|
$result = $stmt->fetchAll(); |
62
|
|
|
return !empty($result); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
protected function getSearchDbHandle() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
if ($this->searchDbHandle === null) { |
68
|
|
|
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->storageDir . DIRECTORY_SEPARATOR; |
|
|
|
|
69
|
|
|
$this->searchDbHandle = new \PDO('sqlite:' . $path . 'search.db'); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
return $this->searchDbHandle; |
72
|
|
|
} |
73
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.