@@ -95,7 +95,7 @@ public function __construct( $options = array() ) {
95
95
$ this ->mapping ['term_id ' ] = array ();
96
96
$ this ->requires_remapping = $ empty_types ;
97
97
$ this ->exists = $ empty_types ;
98
- $ this ->logger = isset ( $ options [ ' logger ' ] ) ? $ options [ ' logger ' ] : new WP_Logger ();
98
+ $ this ->logger = new Logger ();
99
99
100
100
$ this ->options = wp_parse_args (
101
101
$ options ,
@@ -126,8 +126,6 @@ public function import_entity( WP_Imported_Entity $entity ) {
126
126
case WP_Imported_Entity::TYPE_TAG :
127
127
case WP_Imported_Entity::TYPE_CATEGORY :
128
128
return $ this ->import_term ( $ data );
129
- case WP_Imported_Entity::TYPE_TERM_META :
130
- return $ this ->import_term_meta ( $ data , $ data ['term_id ' ] );
131
129
case WP_Imported_Entity::TYPE_USER :
132
130
return $ this ->import_user ( $ data );
133
131
case WP_Imported_Entity::TYPE_SITE_OPTION :
@@ -390,40 +388,6 @@ public function import_term( $data ) {
390
388
return $ term_id ;
391
389
}
392
390
393
- public function import_term_meta ( $ meta_item , $ term_id ) {
394
- if ( empty ( $ meta_item ) ) {
395
- return true ;
396
- }
397
-
398
- /**
399
- * Pre-process term meta data.
400
- *
401
- * @param array $meta_item Meta data. (Return empty to skip.)
402
- * @param int $term_id Term the meta is attached to.
403
- */
404
- $ meta_item = apply_filters ( 'wxr_importer_pre_process_term_meta ' , $ meta_item , $ term_id );
405
- if ( empty ( $ meta_item ) ) {
406
- return false ;
407
- }
408
-
409
- // Have we already processed this?
410
- if ( isset ( $ element ['_already_mapped ' ] ) ) {
411
- $ this ->logger ->debug ( 'Skipping term meta, already processed ' );
412
- return ;
413
- }
414
-
415
- if ( ! isset ( $ meta_item ['term_id ' ] ) ) {
416
- $ meta_item ['term_id ' ] = $ term_id ;
417
- }
418
-
419
- $ value = maybe_unserialize ( $ meta_item ['meta_value ' ] );
420
- $ term_meta_id = add_term_meta ( $ meta_item ['term_id ' ], wp_slash ( $ meta_item ['meta_key ' ] ), wp_slash_strings_only ( $ value ) );
421
-
422
- do_action ( 'wxr_importer_processed_term_meta ' , $ term_meta_id , $ meta_item , $ meta_item ['term_id ' ] );
423
-
424
- return $ term_meta_id ;
425
- }
426
-
427
391
/**
428
392
* Prefill existing post data.
429
393
*
@@ -480,8 +444,6 @@ protected function post_exists( $data ) {
480
444
* Note that new/updated terms, comments and meta are imported for the last of the above.
481
445
*/
482
446
public function import_post ( $ data ) {
483
- $ parent_id = isset ( $ data ['post_parent ' ] ) ? (int ) $ data ['post_parent ' ] : 0 ;
484
-
485
447
/**
486
448
* Pre-process post data.
487
449
*
@@ -490,7 +452,7 @@ public function import_post( $data ) {
490
452
* @param array $comments Comments on the post.
491
453
* @param array $terms Terms on the post.
492
454
*/
493
- $ data = apply_filters ( 'wxr_importer_pre_process_post ' , $ data, $ parent_id );
455
+ $ data = apply_filters ( 'wxr_importer_pre_process_post ' , $ data );
494
456
if ( empty ( $ data ) ) {
495
457
$ this ->logger ->debug ( 'Skipping post, empty data ' );
496
458
return false ;
@@ -659,37 +621,6 @@ public function import_post( $data ) {
659
621
}
660
622
$ this ->mark_post_exists ( $ data , $ post_id );
661
623
662
- // Add terms to the post
663
- /*if ( ! empty( $data['terms'] ) ) {
664
- $terms_to_set = array();
665
-
666
- foreach ( $data['terms'] as $term ) {
667
- // Back compat with WXR 1.0 map 'tag' to 'post_tag'
668
- $taxonomy = ( 'tag' === $term['taxonomy'] ) ? 'post_tag' : $term['taxonomy'];
669
- $term_exists = term_exists( $term['slug'], $taxonomy );
670
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
671
-
672
- if ( ! $term_id ) {
673
- // @TODO: Add a unit test with a WXR with one post and X tags without root declated tags.
674
- $new_term = wp_insert_term( $term['slug'], $taxonomy, $term );
675
-
676
- if ( ! is_wp_error( $new_term ) ) {
677
- $term_id = $new_term['term_id'];
678
-
679
- $this->topological_sorter->update_mapped_id( $new_term, $term_id );
680
- } else {
681
- continue;
682
- }
683
- }
684
- $terms_to_set[ $taxonomy ][] = intval( $term_id );
685
- }
686
-
687
- foreach ( $terms_to_set as $tax => $ids ) {
688
- // Add the post terms to the post
689
- wp_set_post_terms( $post_id, $ids, $tax );
690
- }
691
- }*/
692
-
693
624
$ this ->logger ->info (
694
625
sprintf (
695
626
/* translators: 1: post title, 2: post type name */
@@ -717,7 +648,6 @@ public function import_post( $data ) {
717
648
* @param array $terms Raw term data, already processed.
718
649
*/
719
650
do_action ( 'wxr_importer_processed_post ' , $ post_id , $ data );
720
-
721
651
return $ post_id ;
722
652
}
723
653
@@ -1289,3 +1219,57 @@ public static function sort_comments_by_id( $a, $b ) {
1289
1219
return $ a ['comment_id ' ] - $ b ['comment_id ' ];
1290
1220
}
1291
1221
}
1222
+
1223
+ /**
1224
+ * @TODO how to treat this? Should this class even exist?
1225
+ * how does WordPress handle different levels? It
1226
+ * seems useful for usage in wp-cli, Blueprints,
1227
+ * and other non-web environments.
1228
+ */
1229
+ // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
1230
+ class Logger {
1231
+ /**
1232
+ * Log a debug message.
1233
+ *
1234
+ * @param string $message Message to log
1235
+ */
1236
+ public function debug ( $ message ) {
1237
+ // echo( '[DEBUG] ' . $message );
1238
+ }
1239
+
1240
+ /**
1241
+ * Log an info message.
1242
+ *
1243
+ * @param string $message Message to log
1244
+ */
1245
+ public function info ( $ message ) {
1246
+ // echo( '[INFO] ' . $message );
1247
+ }
1248
+
1249
+ /**
1250
+ * Log a warning message.
1251
+ *
1252
+ * @param string $message Message to log
1253
+ */
1254
+ public function warning ( $ message ) {
1255
+ echo ( '[WARNING] ' . $ message );
1256
+ }
1257
+
1258
+ /**
1259
+ * Log an error message.
1260
+ *
1261
+ * @param string $message Message to log
1262
+ */
1263
+ public function error ( $ message ) {
1264
+ echo ( '[ERROR] ' . $ message );
1265
+ }
1266
+
1267
+ /**
1268
+ * Log a notice message.
1269
+ *
1270
+ * @param string $message Message to log
1271
+ */
1272
+ public function notice ( $ message ) {
1273
+ // echo( '[NOTICE] ' . $message );
1274
+ }
1275
+ }
0 commit comments