PluginProbe
bbPress / trunk
bbPress vtrunk
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / includes / admin / converters / Drupal7.php

Drupal7.php in bbPress trunk, at includes/admin/converters/Drupal7.php

678 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Drupal7 Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of Drupal v7.x Forum converter.
12 *
13 * @since 2.5.0 bbPress (r5138)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/drupal
16 */
17 class Drupal7 extends BBP_Converter_Base {
18
19 /**
20 * Sets up the field mappings
21 */
22 public function setup_globals() {
23
24 /** Forum Section *****************************************************/
25
26 // Old forum id (Stored in postmeta)
27 $this->field_map[] = array(
28 'from_tablename' => 'taxonomy_term_data',
29 'from_fieldname' => 'tid',
30 'to_type' => 'forum',
31 'to_fieldname' => '_bbp_old_forum_id'
32 );
33
34 // Forum parent id (If no parent, then 0, Stored in postmeta)
35 $this->field_map[] = array(
36 'from_tablename' => 'taxonomy_term_hierarchy',
37 'from_fieldname' => 'parent',
38 'join_tablename' => 'taxonomy_term_data',
39 'join_type' => 'INNER',
40 'join_expression' => 'USING (tid)',
41 'from_expression' => 'LEFT JOIN taxonomy_vocabulary AS taxonomy_vocabulary USING (vid) WHERE module = "forum"',
42 'to_type' => 'forum',
43 'to_fieldname' => '_bbp_old_forum_parent_id'
44 );
45
46 // Forum title.
47 $this->field_map[] = array(
48 'from_tablename' => 'taxonomy_term_data',
49 'from_fieldname' => 'name',
50 'to_type' => 'forum',
51 'to_fieldname' => 'post_title'
52 );
53
54 // Forum slug (Clean name to avoid conflicts)
55 $this->field_map[] = array(
56 'from_tablename' => 'taxonomy_term_data',
57 'from_fieldname' => 'name',
58 'to_type' => 'forum',
59 'to_fieldname' => 'post_name',
60 'callback_method' => 'callback_slug'
61 );
62
63 // Forum description.
64 $this->field_map[] = array(
65 'from_tablename' => 'taxonomy_term_data',
66 'from_fieldname' => 'description',
67 'to_type' => 'forum',
68 'to_fieldname' => 'post_content',
69 'callback_method' => 'callback_null'
70 );
71
72 // Forum display order (Starts from 1)
73 $this->field_map[] = array(
74 'from_tablename' => 'taxonomy_term_data',
75 'from_fieldname' => 'weight',
76 'to_type' => 'forum',
77 'to_fieldname' => 'menu_order'
78 );
79
80 // Forum type (Set a default value 'forum', Stored in postmeta)
81 $this->field_map[] = array(
82 'to_type' => 'forum',
83 'to_fieldname' => '_bbp_forum_type',
84 'default' => 'forum'
85 );
86
87 // Forum status (Set a default value 'open', Stored in postmeta)
88 $this->field_map[] = array(
89 'to_type' => 'forum',
90 'to_fieldname' => '_bbp_status',
91 'default' => 'open'
92 );
93
94 // Forum dates.
95 $this->field_map[] = array(
96 'to_type' => 'forum',
97 'to_fieldname' => 'post_date',
98 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
99 );
100 $this->field_map[] = array(
101 'to_type' => 'forum',
102 'to_fieldname' => 'post_date_gmt',
103 'default' => gmdate( 'Y-m-d H:i:s' )
104 );
105 $this->field_map[] = array(
106 'to_type' => 'forum',
107 'to_fieldname' => 'post_modified',
108 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
109 );
110 $this->field_map[] = array(
111 'to_type' => 'forum',
112 'to_fieldname' => 'post_modified_gmt',
113 'default' => gmdate( 'Y-m-d H:i:s' )
114 );
115
116 /** Topic Section *****************************************************/
117
118 // Old topic id (Stored in postmeta)
119 $this->field_map[] = array(
120 'from_tablename' => 'forum_index',
121 'from_fieldname' => 'nid',
122 'to_type' => 'topic',
123 'to_fieldname' => '_bbp_old_topic_id'
124 );
125
126 // Topic reply count (Stored in postmeta)
127 $this->field_map[] = array(
128 'from_tablename' => 'forum_index',
129 'from_fieldname' => 'comment_count',
130 'to_type' => 'topic',
131 'to_fieldname' => '_bbp_reply_count',
132 'callback_method' => 'callback_topic_reply_count'
133 );
134
135 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
136 $this->field_map[] = array(
137 'from_tablename' => 'forum_index',
138 'from_fieldname' => 'comment_count',
139 'to_type' => 'topic',
140 'to_fieldname' => '_bbp_total_reply_count',
141 'callback_method' => 'callback_topic_reply_count'
142 );
143
144 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
145 $this->field_map[] = array(
146 'from_tablename' => 'forum_index',
147 'from_fieldname' => 'tid',
148 'to_type' => 'topic',
149 'to_fieldname' => '_bbp_forum_id',
150 'callback_method' => 'callback_forumid'
151 );
152
153 // Topic author.
154 // Note: We join the 'node' table because 'forum_index' table does not include author id.
155 $this->field_map[] = array(
156 'from_tablename' => 'node',
157 'from_fieldname' => 'uid',
158 'join_tablename' => 'forum_index',
159 'join_type' => 'INNER',
160 'join_expression' => 'ON node.nid = forum_index.nid',
161 'to_type' => 'topic',
162 'to_fieldname' => 'post_author',
163 'callback_method' => 'callback_userid'
164 );
165
166 // Topic author name (Stored in postmeta as _bbp_anonymous_name)
167 $this->field_map[] = array(
168 'to_type' => 'topic',
169 'to_fieldname' => '_bbp_old_topic_author_name_id',
170 'default' => 'Anonymous'
171 );
172
173 // Is the topic anonymous (Stored in postmeta)
174 $this->field_map[] = array(
175 'from_tablename' => 'node',
176 'from_fieldname' => 'uid',
177 'join_tablename' => 'forum_index',
178 'join_type' => 'INNER',
179 'join_expression' => 'ON node.nid = forum_index.nid',
180 'to_type' => 'topic',
181 'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
182 'callback_method' => 'callback_check_anonymous'
183 );
184
185 // Topic content.
186 // Note: We join the 'field_data_body' table because 'node' or 'forum_index' table does not include topic content.
187 $this->field_map[] = array(
188 'from_tablename' => 'field_data_body',
189 'from_fieldname' => 'body_value',
190 'join_tablename' => 'node',
191 'join_type' => 'INNER',
192 'join_expression' => 'ON field_data_body.revision_id = node.vid',
193 'to_type' => 'topic',
194 'to_fieldname' => 'post_content',
195 'callback_method' => 'callback_html'
196 );
197
198 // Topic title.
199 $this->field_map[] = array(
200 'from_tablename' => 'forum_index',
201 'from_fieldname' => 'title',
202 'to_type' => 'topic',
203 'to_fieldname' => 'post_title'
204 );
205
206 // Topic slug (Clean name to avoid conflicts)
207 $this->field_map[] = array(
208 'from_tablename' => 'forum_index',
209 'from_fieldname' => 'title',
210 'to_type' => 'topic',
211 'to_fieldname' => 'post_name',
212 'callback_method' => 'callback_slug'
213 );
214
215 // Topic parent forum id (If no parent, then 0)
216 $this->field_map[] = array(
217 'from_tablename' => 'forum_index',
218 'from_fieldname' => 'tid',
219 'to_type' => 'topic',
220 'to_fieldname' => 'post_parent',
221 'callback_method' => 'callback_forumid'
222 );
223
224 // Topic status (Publish or Unpublished, Drupal v7.x publish = 1, pending = 0)
225 $this->field_map[] = array(
226 'from_tablename' => 'node',
227 'from_fieldname' => 'status',
228 'join_tablename' => 'forum_index',
229 'join_type' => 'INNER',
230 'join_expression' => 'ON node.nid = forum_index.nid',
231 'to_type' => 'topic',
232 'to_fieldname' => 'post_status',
233 'callback_method' => 'callback_status'
234 );
235
236 // Sticky status (Stored in postmeta)
237 $this->field_map[] = array(
238 'from_tablename' => 'forum_index',
239 'from_fieldname' => 'sticky',
240 'to_type' => 'topic',
241 'to_fieldname' => '_bbp_old_sticky_status_id',
242 'callback_method' => 'callback_sticky_status'
243 );
244
245 // Topic dates.
246 $this->field_map[] = array(
247 'from_tablename' => 'forum_index',
248 'from_fieldname' => 'created',
249 'to_type' => 'topic',
250 'to_fieldname' => 'post_date',
251 'callback_method' => 'callback_datetime'
252 );
253 $this->field_map[] = array(
254 'from_tablename' => 'forum_index',
255 'from_fieldname' => 'created',
256 'to_type' => 'topic',
257 'to_fieldname' => 'post_date_gmt',
258 'callback_method' => 'callback_datetime'
259 );
260 $this->field_map[] = array(
261 'from_tablename' => 'forum_index',
262 'from_fieldname' => 'last_comment_timestamp',
263 'to_type' => 'topic',
264 'to_fieldname' => 'post_modified',
265 'callback_method' => 'callback_datetime'
266 );
267 $this->field_map[] = array(
268 'from_tablename' => 'forum_index',
269 'from_fieldname' => 'last_comment_timestamp',
270 'to_type' => 'topic',
271 'to_fieldname' => 'post_modified_gmt',
272 'callback_method' => 'callback_datetime'
273 );
274 $this->field_map[] = array(
275 'from_tablename' => 'forum_index',
276 'from_fieldname' => 'last_comment_timestamp',
277 'to_type' => 'topic',
278 'to_fieldname' => '_bbp_last_active_time',
279 'callback_method' => 'callback_datetime'
280 );
281
282 // Topic status (Drupal v7.x Comments Enabled no = 0, closed = 1 & open = 2)
283 $this->field_map[] = array(
284 'from_tablename' => 'node',
285 'from_fieldname' => 'comment',
286 'join_tablename' => 'forum_index',
287 'join_type' => 'INNER',
288 'join_expression' => 'ON node.nid = forum_index.nid',
289 'to_type' => 'topic',
290 'to_fieldname' => '_bbp_old_closed_status_id',
291 'callback_method' => 'callback_topic_status'
292 );
293
294 /** Tags Section ******************************************************/
295
296 // Topic id.
297 $this->field_map[] = array(
298 'from_tablename' => 'field_data_field_tags',
299 'from_fieldname' => 'entity_id',
300 'to_type' => 'tags',
301 'to_fieldname' => 'objectid',
302 'callback_method' => 'callback_topicid'
303 );
304
305 // Taxonomy ID.
306 $this->field_map[] = array(
307 'from_tablename' => 'field_data_field_tags',
308 'from_fieldname' => 'field_tags_tid',
309 'to_type' => 'tags',
310 'to_fieldname' => 'taxonomy'
311 );
312
313 // Term name.
314 $this->field_map[] = array(
315 'from_tablename' => 'taxonomy_term_data',
316 'from_fieldname' => 'name',
317 'join_tablename' => 'field_data_field_tags',
318 'join_type' => 'INNER',
319 'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid',
320 'to_type' => 'tags',
321 'to_fieldname' => 'name'
322 );
323
324 // Term slug.
325 $this->field_map[] = array(
326 'from_tablename' => 'taxonomy_term_data',
327 'from_fieldname' => 'name',
328 'join_tablename' => 'field_data_field_tags',
329 'join_type' => 'INNER',
330 'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid',
331 'to_type' => 'tags',
332 'to_fieldname' => 'slug',
333 'callback_method' => 'callback_slug'
334 );
335
336 // Term description.
337 $this->field_map[] = array(
338 'from_tablename' => 'taxonomy_term_data',
339 'from_fieldname' => 'description',
340 'join_tablename' => 'field_data_field_tags',
341 'join_type' => 'INNER',
342 'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid',
343 'to_type' => 'tags',
344 'to_fieldname' => 'description'
345 );
346
347 /** Reply Section *****************************************************/
348
349 // Old reply id (Stored in postmeta)
350 $this->field_map[] = array(
351 'from_tablename' => 'comment',
352 'from_fieldname' => 'cid',
353 'to_type' => 'reply',
354 'to_fieldname' => '_bbp_old_reply_id'
355 );
356
357 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
358 $this->field_map[] = array(
359 'from_tablename' => 'comment',
360 'from_fieldname' => 'nid',
361 'to_type' => 'reply',
362 'to_fieldname' => '_bbp_forum_id',
363 'callback_method' => 'callback_topicid_to_forumid'
364 );
365
366 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
367 $this->field_map[] = array(
368 'from_tablename' => 'comment',
369 'from_fieldname' => 'nid',
370 'to_type' => 'reply',
371 'to_fieldname' => '_bbp_topic_id',
372 'callback_method' => 'callback_topicid'
373 );
374
375 // Reply parent reply id (If no parent, then 0. Stored in postmeta)
376 $this->field_map[] = array(
377 'from_tablename' => 'comment',
378 'from_fieldname' => 'pid',
379 'to_type' => 'reply',
380 'to_fieldname' => '_bbp_old_reply_to_id'
381 );
382
383 // Reply author ip (Stored in postmeta)
384 $this->field_map[] = array(
385 'from_tablename' => 'comment',
386 'from_fieldname' => 'hostname',
387 'to_type' => 'reply',
388 'to_fieldname' => '_bbp_author_ip'
389 );
390
391 // Reply author.
392 $this->field_map[] = array(
393 'from_tablename' => 'comment',
394 'from_fieldname' => 'uid',
395 'to_type' => 'reply',
396 'to_fieldname' => 'post_author',
397 'callback_method' => 'callback_userid'
398 );
399
400 // Reply status (Publish or Unpublished, Drupal v7.x publish = 1, pending = 0)
401 $this->field_map[] = array(
402 'from_tablename' => 'comment',
403 'from_fieldname' => 'status',
404 'to_type' => 'reply',
405 'to_fieldname' => 'post_status',
406 'callback_method' => 'callback_status'
407 );
408
409 // Reply author name (Stored in postmeta as _bbp_anonymous_name)
410 $this->field_map[] = array(
411 'from_tablename' => 'comment',
412 'from_fieldname' => 'name',
413 'to_type' => 'reply',
414 'to_fieldname' => '_bbp_old_reply_author_name_id'
415 );
416
417 // Is the reply anonymous (Stored in postmeta)
418 $this->field_map[] = array(
419 'from_tablename' => 'comment',
420 'from_fieldname' => 'uid',
421 'to_type' => 'reply',
422 'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
423 'callback_method' => 'callback_check_anonymous'
424 );
425
426 // Reply content.
427 // Note: We join the 'field_data_comment_body' table because 'comment' table does not include reply content.
428 $this->field_map[] = array(
429 'from_tablename' => 'field_data_comment_body',
430 'from_fieldname' => 'comment_body_value',
431 'join_tablename' => 'comment',
432 'join_type' => 'INNER',
433 'join_expression' => 'ON field_data_comment_body.entity_id = comment.cid',
434 'to_type' => 'reply',
435 'to_fieldname' => 'post_content',
436 'callback_method' => 'callback_html'
437 );
438
439 // Reply parent topic id (If no parent, then 0)
440 $this->field_map[] = array(
441 'from_tablename' => 'comment',
442 'from_fieldname' => 'nid',
443 'to_type' => 'reply',
444 'to_fieldname' => 'post_parent',
445 'callback_method' => 'callback_topicid'
446 );
447
448 // Reply dates.
449 $this->field_map[] = array(
450 'from_tablename' => 'comment',
451 'from_fieldname' => 'created',
452 'to_type' => 'reply',
453 'to_fieldname' => 'post_date',
454 'callback_method' => 'callback_datetime'
455 );
456 $this->field_map[] = array(
457 'from_tablename' => 'comment',
458 'from_fieldname' => 'created',
459 'to_type' => 'reply',
460 'to_fieldname' => 'post_date_gmt',
461 'callback_method' => 'callback_datetime'
462 );
463 $this->field_map[] = array(
464 'from_tablename' => 'comment',
465 'from_fieldname' => 'changed',
466 'to_type' => 'reply',
467 'to_fieldname' => 'post_modified',
468 'callback_method' => 'callback_datetime'
469 );
470 $this->field_map[] = array(
471 'from_tablename' => 'comment',
472 'from_fieldname' => 'changed',
473 'to_type' => 'reply',
474 'to_fieldname' => 'post_modified_gmt',
475 'callback_method' => 'callback_datetime'
476 );
477
478 /** User Section ******************************************************/
479
480 // Store old user id (Stored in usermeta)
481 // Don't import user uid = 0, this is Drupal 7's guest user
482 $this->field_map[] = array(
483 'from_tablename' => 'users',
484 'from_fieldname' => 'uid',
485 'from_expression' => 'WHERE uid != 0',
486 'to_type' => 'user',
487 'to_fieldname' => '_bbp_old_user_id'
488 );
489
490 // Store old user password (Stored in usermeta serialized with salt)
491 $this->field_map[] = array(
492 'from_tablename' => 'users',
493 'from_fieldname' => 'pass',
494 'to_type' => 'user',
495 'to_fieldname' => '_bbp_password'
496 // 'callback_method' => 'callback_savepass'
497 );
498
499 // Store old user salt (This is only used for the SELECT row info for the above password save)
500 $this->field_map[] = array(
501 'from_tablename' => 'users',
502 'from_fieldname' => 'pass',
503 'to_type' => 'user',
504 'to_fieldname' => ''
505 );
506
507 // User password verify class (Stored in usermeta for verifying password)
508 $this->field_map[] = array(
509 'to_type' => 'users',
510 'to_fieldname' => '_bbp_class',
511 'default' => 'Drupal7'
512 );
513
514 // User name.
515 $this->field_map[] = array(
516 'from_tablename' => 'users',
517 'from_fieldname' => 'name',
518 'to_type' => 'user',
519 'to_fieldname' => 'user_login'
520 );
521
522 // User nice name.
523 $this->field_map[] = array(
524 'from_tablename' => 'users',
525 'from_fieldname' => 'name',
526 'to_type' => 'user',
527 'to_fieldname' => 'user_nicename'
528 );
529
530 // User email.
531 $this->field_map[] = array(
532 'from_tablename' => 'users',
533 'from_fieldname' => 'mail',
534 'to_type' => 'user',
535 'to_fieldname' => 'user_email'
536 );
537
538 // User registered.
539 $this->field_map[] = array(
540 'from_tablename' => 'users',
541 'from_fieldname' => 'created',
542 'to_type' => 'user',
543 'to_fieldname' => 'user_registered',
544 'callback_method' => 'callback_datetime'
545 );
546
547 // Store Signature (Stored in usermeta)
548 $this->field_map[] = array(
549 'from_tablename' => 'users',
550 'from_fieldname' => 'signature',
551 'to_fieldname' => '_bbp_drupal7_user_sig',
552 'to_type' => 'user',
553 'callback_method' => 'callback_html'
554 );
555 }
556
557 /**
558 * This method allows us to indicates what is or is not converted for each
559 * converter.
560 */
561 public function info() {
562 return '';
563 }
564
565 /**
566 * This method is to save the salt and password together. That
567 * way when we authenticate it we can get it out of the database
568 * as one value. Array values are auto sanitized by WordPress.
569 */
570 public function callback_savepass( $field, $row ) {
571 $pass_array = array(
572 'hash' => $field,
573 'salt' => $row['salt']
574 );
575
576 return $pass_array;
577 }
578
579 /**
580 * This method is to take the pass out of the database and compare
581 * to a pass the user has typed in.
582 */
583 public function authenticate_pass( $password, $serialized_pass ) {
584
585 // Unserialize the password, with safeguards
586 $pass_array = unserialize(
587 $serialized_pass,
588 array(
589 'allowed_classes' => false,
590 'max_depth' => 1,
591 )
592 );
593
594 // Bail if missing values
595 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['salt'] ) ) {
596 return false;
597 }
598
599 // Return comparison
600 return hash_equals(
601 $pass_array['hash'],
602 md5( md5( $password ) . $pass_array['salt'] )
603 );
604 }
605
606 /**
607 * Translate the post status from Drupal v7.x numerics to WordPress's
608 * strings.
609 *
610 * @param int $status Drupal v7.x numeric post status
611 * @return string WordPress safe
612 */
613 public function callback_status( $status = 1 ) {
614 switch ( $status ) {
615 case 0 :
616 $status = 'pending'; // bbp_get_pending_status_id()
617 break;
618
619 case 1 :
620 default :
621 $status = 'publish'; // bbp_get_public_status_id()
622 break;
623 }
624 return $status;
625 }
626
627 /**
628 * Translate the post status from Drupal v7.x numerics to WordPress's strings.
629 *
630 * @param int $status Drupal v7.x numeric topic status
631 * @return string WordPress safe
632 */
633 public function callback_topic_status( $status = 2 ) {
634 switch ( $status ) {
635 case 1 :
636 $status = 'closed';
637 break;
638
639 case 2 :
640 default :
641 $status = 'publish';
642 break;
643 }
644 return $status;
645 }
646
647 /**
648 * Translate the topic sticky status type from Drupal v7.x numerics to WordPress's strings.
649 *
650 * @param int $status Drupal v7.x numeric forum type
651 * @return string WordPress safe
652 */
653 public function callback_sticky_status( $status = 0 ) {
654 switch ( $status ) {
655 case 1 :
656 $status = 'sticky'; // Drupal Sticky 'topic_sticky = 1'
657 break;
658
659 case 0 :
660 default :
661 $status = 'normal'; // Drupal Normal Topic 'sticky = 0'
662 break;
663 }
664 return $status;
665 }
666
667 /**
668 * Verify the topic/reply count.
669 *
670 * @param int $count Drupal v7.x topic/reply counts
671 * @return string WordPress safe
672 */
673 public function callback_topic_reply_count( $count = 1 ) {
674 $count = absint( (int) $count - 1 );
675 return $count;
676 }
677 }
678