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
|
|
|
/** |
11
|
|
|
* Class elkarte1_1 |
12
|
|
|
*/ |
13
|
|
|
class elkarte1_1 extends Importers\AbstractSourceImporter |
14
|
|
|
{ |
15
|
|
|
protected $setting_file = '/Settings.php'; |
16
|
|
|
|
17
|
|
|
protected $smf_attach_folders = null; |
18
|
|
|
|
19
|
|
|
public function getName() |
20
|
|
|
{ |
21
|
|
|
return 'elkarte1_1'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getVersion() |
25
|
|
|
{ |
26
|
|
|
return 'SMF 2.0'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function setDefines() |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getPrefix() |
35
|
|
|
{ |
36
|
|
|
$db_name = $this->getDbName(); |
37
|
|
|
$db_prefix = $this->fetchSetting('db_prefix'); |
38
|
|
|
|
39
|
|
|
return '`' . $db_name . '`.' . $db_prefix; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getDbName() |
43
|
|
|
{ |
44
|
|
|
return $this->fetchSetting('db_name'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function fetchSetting($name) |
48
|
|
|
{ |
49
|
|
|
static $content = null; |
50
|
|
|
|
51
|
|
|
if ($content === null) |
52
|
|
|
{ |
53
|
|
|
$content = file_get_contents($this->path . '/Settings.php'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$match = array(); |
57
|
|
|
preg_match('~\$' . $name . '\s*=\s*\'(.*?)\';~', $content, $match); |
58
|
|
|
|
59
|
|
|
return isset($match[1]) ? $match[1] : ''; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getTableTest() |
63
|
|
|
{ |
64
|
|
|
return 'members'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Read the attachment directory structure from the source db |
69
|
|
|
* |
70
|
|
|
* @return array|null |
71
|
|
|
*/ |
72
|
|
|
public function getAttachmentDirs() |
73
|
|
|
{ |
74
|
|
|
if ($this->smf_attach_folders === null) |
75
|
|
|
{ |
76
|
|
|
$from_prefix = $this->config->from_prefix; |
77
|
|
|
|
78
|
|
|
$request = $this->db->query(" |
79
|
|
|
SELECT value |
80
|
|
|
FROM {$from_prefix}settings |
81
|
|
|
WHERE variable='attachmentUploadDir';"); |
82
|
|
|
list ($smf_attachments_dir) = $this->db->fetch_row($request); |
83
|
|
|
|
84
|
|
|
$this->smf_attach_folders = @unserialize($smf_attachments_dir); |
85
|
|
|
|
86
|
|
|
if (!is_array($this->smf_attach_folders)) |
87
|
|
|
{ |
88
|
|
|
$this->smf_attach_folders = array(1 => $smf_attachments_dir); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->smf_attach_folders; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Copy attachments from the source to our destination |
98
|
|
|
* |
99
|
|
|
* @param array $row |
100
|
|
|
* @param \OpenImporter\Database $db |
101
|
|
|
* @param string $from_prefix |
102
|
|
|
* @param string $attachmentUploadDir |
103
|
|
|
*/ |
104
|
|
|
function moveAttachment(&$row, $db, $from_prefix, $attachmentUploadDir) |
105
|
|
|
{ |
106
|
|
|
static $smf_folders = null; |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
// We need to know where the attachments are located |
110
|
|
|
if ($smf_folders === null) |
111
|
|
|
{ |
112
|
|
|
$request = $db->query(" |
113
|
|
|
SELECT value |
114
|
|
|
FROM {$from_prefix}settings |
115
|
|
|
WHERE variable='attachmentUploadDir';"); |
116
|
|
|
list ($smf_attachments_dir) = $db->fetch_row($request); |
117
|
|
|
|
118
|
|
|
$smf_folders = @unserialize($smf_attachments_dir); |
119
|
|
|
|
120
|
|
|
// print_r($smf_folders); |
121
|
|
|
|
122
|
|
|
if (!is_array($smf_folders)) |
123
|
|
|
{ |
124
|
|
|
$smf_folders = array(1 => $smf_attachments_dir); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
// If something is broken, better try to account for it as well. |
130
|
|
|
if (isset($smf_folders[$row['id_folder']])) |
131
|
|
|
{ |
132
|
|
|
$smf_attachments_dir = $smf_folders[$row['id_folder']]; |
133
|
|
|
} |
134
|
|
|
else |
135
|
|
|
{ |
136
|
|
|
$smf_attachments_dir = $smf_folders[1]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// Missing the file hash ... create one |
140
|
|
|
if (empty($row['file_hash'])) |
141
|
|
|
{ |
142
|
|
|
$row['file_hash'] = createAttachmentFileHash($row['filename']); |
143
|
|
|
$source_file = $row['filename']; |
144
|
|
|
} |
145
|
|
|
else |
146
|
|
|
{ |
147
|
|
|
$source_file = $row['id_attach'] . '_' . $row['file_hash']; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
// Copy it over |
151
|
|
|
if (file_exists($smf_attachments_dir . '/' . $source_file . '.elk')) |
152
|
|
|
{ |
153
|
|
|
copy_file($smf_attachments_dir . '/' . $source_file . '.elk', $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash']); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
if (file_exists($smf_attachments_dir . '/' . $source_file . '.elk_thumb')) |
157
|
|
|
{ |
158
|
|
|
copy_file($smf_attachments_dir . '/' . $source_file . '.elk_thumb', $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash'] . '_thumb'); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|