1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* phpBB Directory extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com> |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ernadoo\phpbbdirectory\migrations\v10x; |
12
|
|
|
|
13
|
|
|
class v1_0_0 extends \phpbb\db\migration\migration |
14
|
|
|
{ |
15
|
|
|
static public function depends_on() |
16
|
|
|
{ |
17
|
|
|
return array( |
18
|
|
|
'\ernadoo\phpbbdirectory\migrations\converter\convert_module', |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function update_schema() |
23
|
|
|
{ |
24
|
|
|
return array( |
25
|
|
|
'add_tables' => array( |
26
|
|
|
$this->table_prefix . 'directory_cats' => array( |
27
|
|
|
'COLUMNS' => array( |
28
|
|
|
'cat_id' => array('UINT', null, 'auto_increment'), |
29
|
|
|
'parent_id' => array('UINT', 0), |
30
|
|
|
'left_id' => array('UINT', 0), |
31
|
|
|
'right_id' => array('UINT', 0), |
32
|
|
|
'cat_parents' => array('MTEXT_UNI', ''), |
33
|
|
|
'cat_name' => array('VCHAR', ''), |
34
|
|
|
'cat_desc' => array('TEXT_UNI', ''), |
35
|
|
|
'cat_desc_bitfield' => array('VCHAR', ''), |
36
|
|
|
'cat_desc_options' => array('TIMESTAMP', 7), |
37
|
|
|
'cat_desc_uid' => array('VCHAR:8', ''), |
38
|
|
|
'cat_links' => array('UINT', 0), |
39
|
|
|
'cat_icon' => array('VCHAR', ''), |
40
|
|
|
'display_subcat_list' => array('BOOL', 1), |
41
|
|
|
'cat_allow_comments' => array('BOOL', 1), |
42
|
|
|
'cat_allow_votes' => array('BOOL', 1), |
43
|
|
|
'cat_must_describe' => array('BOOL', 1), |
44
|
|
|
'cat_count_all' => array('BOOL', 0), |
45
|
|
|
'cat_validate' => array('BOOL', 1), |
46
|
|
|
'cat_link_back' => array('BOOL', 0), |
47
|
|
|
'cat_cron_enable' => array('BOOL', 0), |
48
|
|
|
'cat_cron_next' => array('TIMESTAMP', 0), |
49
|
|
|
'cat_cron_freq' => array('UINT', 7), |
50
|
|
|
'cat_cron_nb_check' => array('UINT', 1), |
51
|
|
|
), |
52
|
|
|
|
53
|
|
|
'PRIMARY_KEY' => array('cat_id'), |
54
|
|
|
|
55
|
|
|
'KEYS' => array( |
56
|
|
|
'l_r_id' => array('INDEX', array('left_id', 'right_id')), |
57
|
|
|
), |
58
|
|
|
), |
59
|
|
|
|
60
|
|
|
$this->table_prefix . 'directory_comments' => array( |
61
|
|
|
'COLUMNS' => array( |
62
|
|
|
'comment_id' => array('UINT', null, 'auto_increment'), |
63
|
|
|
'comment_date' => array('TIMESTAMP', 0), |
64
|
|
|
'comment_link_id' => array('UINT', 0), |
65
|
|
|
'comment_user_id' => array('UINT', 0), |
66
|
|
|
'comment_user_ip' => array('VCHAR:40', ''), |
67
|
|
|
'comment_text' => array('MTEXT_UNI', ''), |
68
|
|
|
'comment_uid' => array('VCHAR:8', 0), |
69
|
|
|
'comment_flags' => array('TIMESTAMP', 0), |
70
|
|
|
'comment_bitfield' => array('VCHAR', ''), |
71
|
|
|
), |
72
|
|
|
|
73
|
|
|
'PRIMARY_KEY' => array('comment_id'), |
74
|
|
|
), |
75
|
|
|
|
76
|
|
|
$this->table_prefix . 'directory_links' => array( |
77
|
|
|
'COLUMNS' => array( |
78
|
|
|
'link_id' => array('UINT', null, 'auto_increment'), |
79
|
|
|
'link_time' => array('TIMESTAMP', 0), |
80
|
|
|
'link_uid' => array('VCHAR:8', ''), |
81
|
|
|
'link_flags' => array('TIMESTAMP', 0), |
82
|
|
|
'link_bitfield' => array('VCHAR', ''), |
83
|
|
|
'link_url' => array('VCHAR', ''), |
84
|
|
|
'link_description' => array('MTEXT_UNI', ''), |
85
|
|
|
'link_view' => array('UINT', 0), |
86
|
|
|
'link_active' => array('BOOL', 0), |
87
|
|
|
'link_cat' => array('UINT', 0), |
88
|
|
|
'link_user_id' => array('UINT', 0), |
89
|
|
|
'link_name' => array('XSTEXT_UNI', ''), |
90
|
|
|
'link_rss' => array('VCHAR', ''), |
91
|
|
|
'link_banner' => array('VCHAR', ''), |
92
|
|
|
'link_back' => array('VCHAR', ''), |
93
|
|
|
'link_nb_check' => array('TINT:3', 0), |
94
|
|
|
'link_flag' => array('VCHAR', ''), |
95
|
|
|
'link_guest_email' => array('XSTEXT_UNI', ''), |
96
|
|
|
'link_vote' => array('UINT', 0), |
97
|
|
|
'link_comment' => array('TIMESTAMP', 0), |
98
|
|
|
'link_note' => array('UINT', 0), |
99
|
|
|
'link_pagerank' => array('CHAR:2', ''), |
100
|
|
|
'link_thumb' => array('VCHAR', ''), |
101
|
|
|
), |
102
|
|
|
|
103
|
|
|
'PRIMARY_KEY' => array('link_id'), |
104
|
|
|
|
105
|
|
|
'KEYS' => array( |
106
|
|
|
'link_id' => array('UNIQUE', array('link_id')), |
107
|
|
|
'link_c_a' => array('INDEX', array('link_cat', 'link_active')), |
108
|
|
|
'link_time' => array('INDEX', array('link_time')), |
109
|
|
|
'link_u_id' => array('INDEX', array('link_user_id')), |
110
|
|
|
), |
111
|
|
|
), |
112
|
|
|
|
113
|
|
|
$this->table_prefix . 'directory_watch' => array( |
114
|
|
|
'COLUMNS' => array( |
115
|
|
|
'cat_id' => array('UINT', 0), |
116
|
|
|
'user_id' => array('UINT', 0), |
117
|
|
|
'notify_status' => array('UINT', 0), |
118
|
|
|
), |
119
|
|
|
|
120
|
|
|
'KEYS' => array( |
121
|
|
|
'c_id' => array('INDEX', array('cat_id')), |
122
|
|
|
'u_id' => array('INDEX', array('user_id')), |
123
|
|
|
'n_stat' => array('INDEX', array('notify_status')), |
124
|
|
|
), |
125
|
|
|
|
126
|
|
|
), |
127
|
|
|
|
128
|
|
|
$this->table_prefix . 'directory_votes' => array( |
129
|
|
|
'COLUMNS' => array( |
130
|
|
|
'vote_id' => array('UINT', null, 'auto_increment'), |
131
|
|
|
'vote_link_id' => array('UINT', 0), |
132
|
|
|
'vote_user_id' => array('UINT', 0), |
133
|
|
|
'vote_note' => array('TINT:2', 0), |
134
|
|
|
), |
135
|
|
|
|
136
|
|
|
'PRIMARY_KEY' => array('vote_id'), |
137
|
|
|
|
138
|
|
|
'KEYS' => array( |
139
|
|
|
'v_l_id' => array('INDEX', array('vote_link_id')), |
140
|
|
|
'v_u_id' => array('INDEX', array('vote_user_id')), |
141
|
|
|
), |
142
|
|
|
), |
143
|
|
|
), |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function revert_schema() |
148
|
|
|
{ |
149
|
|
|
return array( |
150
|
|
|
'drop_tables' => array( |
151
|
|
|
$this->table_prefix . 'directory_cats', |
152
|
|
|
$this->table_prefix . 'directory_comments', |
153
|
|
|
$this->table_prefix . 'directory_links', |
154
|
|
|
$this->table_prefix . 'directory_votes', |
155
|
|
|
$this->table_prefix . 'directory_watch', |
156
|
|
|
), |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function update_data() |
161
|
|
|
{ |
162
|
|
|
return array( |
163
|
|
|
array('config.add', array('dir_mail', '1')), |
164
|
|
|
array('config.add', array('dir_activ_flag', '1')), |
165
|
|
|
array('config.add', array('dir_show', '10')), |
166
|
|
|
array('config.add', array('dir_default_order', 't d')), |
167
|
|
|
array('config.add', array('dir_allow_bbcode', '1')), |
168
|
|
|
array('config.add', array('dir_allow_flash', '1')), |
169
|
|
|
array('config.add', array('dir_allow_links', '1')), |
170
|
|
|
array('config.add', array('dir_allow_smilies', '1')), |
171
|
|
|
array('config.add', array('dir_length_describe', '255')), |
172
|
|
|
array('config.add', array('dir_activ_banner', '1')), |
173
|
|
|
array('config.add', array('dir_banner_height', '60')), |
174
|
|
|
array('config.add', array('dir_banner_width', '480')), |
175
|
|
|
array('config.add', array('dir_activ_checkurl', '1')), |
176
|
|
|
array('config.add', array('dir_activ_pagerank', '1')), |
177
|
|
|
array('config.add', array('dir_activ_thumb', '1')), |
178
|
|
|
array('config.add', array('dir_activ_thumb_remote', '1')), |
179
|
|
|
array('config.add', array('dir_visual_confirm', '1')), |
180
|
|
|
array('config.add', array('dir_visual_confirm_max_attempts', '3')), |
181
|
|
|
array('config.add', array('dir_length_comments', '256')), |
182
|
|
|
array('config.add', array('dir_new_time', '7')), |
183
|
|
|
array('config.add', array('dir_comments_per_page', '10')), |
184
|
|
|
array('config.add', array('dir_storage_banner', '1')), |
185
|
|
|
array('config.add', array('dir_banner_filesize', '30000')), |
186
|
|
|
array('config.add', array('dir_thumb_service', 'http://www.apercite.fr/apercite/120x90/oui/oui/')), |
187
|
|
|
array('config.add', array('dir_thumb_service_reverse', '0')), |
188
|
|
|
array('config.add', array('dir_activ_rss', '1')), |
189
|
|
|
array('config.add', array('dir_recent_block', '1')), |
190
|
|
|
array('config.add', array('dir_recent_exclude', '1')), |
191
|
|
|
array('config.add', array('dir_recent_rows', '1')), |
192
|
|
|
array('config.add', array('dir_recent_columns', '5')), |
193
|
|
|
array('config.add', array('dir_root_path', './')), |
194
|
|
|
array('config.add', array('dir_activ_rewrite', '0')), |
195
|
|
|
|
196
|
|
|
array('module.add', array( |
197
|
|
|
'acp', |
198
|
|
|
'ACP_CAT_DOT_MODS', |
199
|
|
|
'ACP_DIRECTORY' |
200
|
|
|
)), |
201
|
|
|
|
202
|
|
|
array('module.add', array( |
203
|
|
|
'acp', |
204
|
|
|
'ACP_DIRECTORY', |
205
|
|
|
array( |
206
|
|
|
'module_basename' => '\ernadoo\phpbbdirectory\acp\phpbbdirectory_module', |
207
|
|
|
'modes' => array('main', 'settings', 'cat', 'val'), |
208
|
|
|
), |
209
|
|
|
)), |
210
|
|
|
|
211
|
|
|
array('permission.add', array('u_comment_dir')), |
212
|
|
|
array('permission.add', array('u_search_dir')), |
213
|
|
|
array('permission.add', array('u_submit_dir')), |
214
|
|
|
array('permission.add', array('u_vote_dir')), |
215
|
|
|
array('permission.add', array('u_edit_comment_dir')), |
216
|
|
|
array('permission.add', array('u_delete_comment_dir')), |
217
|
|
|
array('permission.add', array('u_edit_dir')), |
218
|
|
|
array('permission.add', array('u_delete_dir')), |
219
|
|
|
array('permission.add', array('m_edit_dir')), |
220
|
|
|
array('permission.add', array('m_delete_dir')), |
221
|
|
|
array('permission.add', array('m_edit_comment_dir')), |
222
|
|
|
array('permission.add', array('m_delete_comment_dir')), |
223
|
|
|
|
224
|
|
|
array('permission.permission_set', |
225
|
|
|
array('ROLE_USER_FULL', |
226
|
|
|
array( |
227
|
|
|
'u_comment_dir', |
228
|
|
|
'u_search_dir', |
229
|
|
|
'u_submit_dir', |
230
|
|
|
'u_vote_dir', |
231
|
|
|
'u_edit_comment_dir', |
232
|
|
|
'u_delete_comment_dir', |
233
|
|
|
'u_edit_dir', |
234
|
|
|
'u_delete_dir', |
235
|
|
|
) |
236
|
|
|
) |
237
|
|
|
), |
238
|
|
|
|
239
|
|
|
array('permission.permission_set', |
240
|
|
|
array('ROLE_MOD_FULL', |
241
|
|
|
array( |
242
|
|
|
'm_edit_dir', |
243
|
|
|
'm_delete_dir', |
244
|
|
|
'm_edit_comment_dir', |
245
|
|
|
'm_delete_comment_dir', |
246
|
|
|
) |
247
|
|
|
) |
248
|
|
|
), |
249
|
|
|
|
250
|
|
|
array('custom', array(array(&$this, 'create_directories'))), |
251
|
|
|
); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function revert_data() |
255
|
|
|
{ |
256
|
|
|
return array( |
257
|
|
|
array('custom', array(array(&$this, 'remove_directories'))), |
258
|
|
|
); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Create directories for banners/icons uploaded |
263
|
|
|
* |
264
|
|
|
* @return null |
265
|
|
|
*/ |
266
|
|
|
public function create_directories() |
267
|
|
|
{ |
268
|
|
|
$directories = array( |
269
|
|
|
'files/ext/ernadoo/phpbbdirectory/banners/', |
270
|
|
|
'files/ext/ernadoo/phpbbdirectory/icons/', |
271
|
|
|
); |
272
|
|
|
|
273
|
|
|
foreach ($directories as $dir) |
274
|
|
|
{ |
275
|
|
|
if (!file_exists($this->phpbb_root_path . $dir)) |
276
|
|
|
{ |
277
|
|
|
@mkdir($this->phpbb_root_path . $dir, 0777, true); |
278
|
|
|
phpbb_chmod($this->phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE); |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Remove directories for banners/icons uploaded |
285
|
|
|
* |
286
|
|
|
* @return null |
287
|
|
|
*/ |
288
|
|
|
public function remove_directories() |
289
|
|
|
{ |
290
|
|
|
$dir = $this->phpbb_root_path . 'files/ext/ernadoo/phpbbdirectory/'; |
291
|
|
|
|
292
|
|
|
$this->_recursive_rmdir($dir); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Attempts to remove recursively the directory named by dirname. |
297
|
|
|
* |
298
|
|
|
* @author Mehdi Kabab <http://pioupioum.fr> |
299
|
|
|
* @copyright Copyright (C) 2009 Mehdi Kabab |
300
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU GPL version 3 or later |
301
|
|
|
* |
302
|
|
|
* @param string $dirname Path to the directory. |
303
|
|
|
* @return null |
304
|
|
|
*/ |
305
|
|
|
private function _recursive_rmdir($dirname) |
306
|
|
|
{ |
307
|
|
|
if (is_dir($dirname) && !is_link($dirname)) |
308
|
|
|
{ |
309
|
|
|
$iterator = new \RecursiveIteratorIterator( |
310
|
|
|
new \RecursiveDirectoryIterator($dirname), |
311
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST |
312
|
|
|
); |
313
|
|
|
|
314
|
|
|
while ($iterator->valid()) |
315
|
|
|
{ |
316
|
|
|
if (!$iterator->isDot()) |
317
|
|
|
{ |
318
|
|
|
if ($iterator->isFile()) |
319
|
|
|
{ |
320
|
|
|
unlink($iterator->getPathName()); |
321
|
|
|
} |
322
|
|
|
else if ($iterator->isDir()) |
323
|
|
|
{ |
324
|
|
|
rmdir($iterator->getPathName()); |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
$iterator->next(); |
329
|
|
|
} |
330
|
|
|
unset($iterator); // Fix for Windows. |
331
|
|
|
|
332
|
|
|
rmdir($dirname); |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|