|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @name OpenImporter |
|
4
|
|
|
* @copyright OpenImporter contributors |
|
5
|
|
|
* @license BSD https://opensource.org/licenses/BSD-3-Clause |
|
6
|
|
|
* |
|
7
|
|
|
* @version 1.0 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Importers; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This abstract class is the base for any php importer file. |
|
14
|
|
|
* |
|
15
|
|
|
* It provides some common necessary methods and some default properties |
|
16
|
|
|
* so that Importer can do its job without having to test for existence |
|
17
|
|
|
* of methods every two/three lines of code. |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractSourceImporter |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string Settings file name */ |
|
22
|
|
|
protected $setting_file = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string Path to source */ |
|
25
|
|
|
protected $path = ''; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \OpenImporter\Database */ |
|
28
|
|
|
protected $db; |
|
29
|
|
|
|
|
30
|
|
|
/** @var \OpenImporter\Configurator */ |
|
31
|
|
|
protected $config; |
|
32
|
|
|
|
|
33
|
|
|
public function setUtils($db, $config) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->db = $db; |
|
36
|
|
|
$this->config = $config; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public abstract function getName(); |
|
40
|
|
|
|
|
41
|
|
|
public abstract function getVersion(); |
|
42
|
|
|
|
|
43
|
|
|
public abstract function getPrefix(); |
|
44
|
|
|
|
|
45
|
|
|
public abstract function getDbName(); |
|
46
|
|
|
|
|
47
|
|
|
public abstract function getTableTest(); |
|
48
|
|
|
|
|
49
|
|
|
public function loadSettings($path, $test = false) |
|
50
|
|
|
{ |
|
51
|
|
|
if ($test) |
|
52
|
|
|
{ |
|
53
|
|
|
if (empty($this->setting_file)) |
|
54
|
|
|
{ |
|
55
|
|
|
return null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->testPath($path); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (empty($this->setting_file)) |
|
62
|
|
|
{ |
|
63
|
|
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ($this->testPath($path)) |
|
67
|
|
|
{ |
|
68
|
|
|
global $config; |
|
69
|
|
|
|
|
70
|
|
|
// Holds (generally) the source forum config values from the require file |
|
71
|
|
|
// @todo something better in the future |
|
72
|
|
|
if (empty($config)) |
|
73
|
|
|
{ |
|
74
|
|
|
$config = array(); |
|
75
|
|
|
|
|
76
|
|
|
// Load the $config values |
|
77
|
|
|
require_once($path . $this->setting_file); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function testPath($path) |
|
87
|
|
|
{ |
|
88
|
|
|
$found = @file_exists($path . $this->setting_file); |
|
89
|
|
|
|
|
90
|
|
|
if ($found) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->path = $path; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $found; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setDefines() |
|
99
|
|
|
{ |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function setGlobals() |
|
103
|
|
|
{ |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function fetchSetting($name) |
|
107
|
|
|
{ |
|
108
|
|
|
static $config = null; |
|
109
|
|
|
|
|
110
|
|
|
if ($config === null) |
|
111
|
|
|
{ |
|
112
|
|
|
$config = file_get_contents($this->path . $this->setting_file); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$match = array(); |
|
116
|
|
|
preg_match('~\$' . $name . '\s*=\s*\'?(.*?)\'?;~', $config, $match); |
|
117
|
|
|
|
|
118
|
|
|
return isset($match[1]) ? $match[1] : ''; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|