@@ -81,6 +81,13 @@ class Importer implements LoggerAwareInterface {
81
81
*/
82
82
public $ errors = array ();
83
83
84
+ /**
85
+ * Version number of codebase being parsed.
86
+ *
87
+ * @var string
88
+ */
89
+ public $ version ;
90
+
84
91
/**
85
92
* @var array Cached items of inserted terms
86
93
*/
@@ -158,6 +165,12 @@ public function import( array $data, $skip_sleep = false, $import_ignored_functi
158
165
exit ;
159
166
}
160
167
168
+ // Specifically import WP version file first to get version number.
169
+ $ ver_file = array_filter ( $ data , function ( $ f ) { return 'wp-includes/version.php ' === $ f ['path ' ]; } );
170
+ if ( $ ver_file ) {
171
+ $ this ->version = $ this ->import_version ( reset ( $ ver_file ) );
172
+ }
173
+
161
174
$ root = '' ;
162
175
foreach ( $ data as $ file ) {
163
176
$ this ->logger ->info ( sprintf ( 'Processing file %1$s of %2$s "%3$s". ' , number_format_i18n ( $ file_number ), number_format_i18n ( $ num_of_files ), $ file ['path ' ] ) );
@@ -336,10 +349,6 @@ public function import_file( array $file, $skip_sleep = false, $import_ignored =
336
349
sleep ( 3 );
337
350
}
338
351
}
339
-
340
- if ( 'wp-includes/version.php ' === $ file ['path ' ] ) {
341
- $ this ->import_version ( $ file );
342
- }
343
352
}
344
353
345
354
/**
@@ -477,21 +486,25 @@ protected function import_method( array $data, $parent_post_id = 0, $import_igno
477
486
* Updates the 'wp_parser_imported_wp_version' option with the version from wp-includes/version.php.
478
487
*
479
488
* @param array $data Data
489
+ * @return string|false WordPress version number, or false if not known.
480
490
*/
481
491
protected function import_version ( $ data ) {
482
492
483
493
$ version_path = $ data ['root ' ] . '/ ' . $ data ['path ' ];
484
494
485
495
if ( ! is_readable ( $ version_path ) ) {
486
- return ;
496
+ return false ;
487
497
}
488
498
489
499
include $ version_path ;
490
500
491
501
if ( isset ( $ wp_version ) && $ wp_version ) {
492
502
update_option ( 'wp_parser_imported_wp_version ' , $ wp_version );
493
503
$ this ->logger ->info ( "\t" . sprintf ( 'Updated option wp_parser_imported_wp_version to "%1$s" ' , $ wp_version ) );
504
+ return $ wp_version ;
494
505
}
506
+
507
+ return false ;
495
508
}
496
509
497
510
/**
@@ -747,6 +760,7 @@ public function import_item( array $data, $parent_post_id = 0, $import_ignored =
747
760
$ anything_updated [] = update_post_meta ( $ post_id , '_wp-parser_line_num ' , (string ) $ data ['line ' ] );
748
761
$ anything_updated [] = update_post_meta ( $ post_id , '_wp-parser_end_line_num ' , (string ) $ data ['end_line ' ] );
749
762
$ anything_updated [] = update_post_meta ( $ post_id , '_wp-parser_tags ' , $ data ['doc ' ]['tags ' ] );
763
+ $ anything_updated [] = update_post_meta ( $ post_id , '_wp-parser_last_parsed_wp_version ' , $ this ->version );
750
764
751
765
// If the post didn't need to be updated, but meta or tax changed, update it to bump last modified.
752
766
if ( ! $ is_new_post && ! $ post_needed_update && array_filter ( $ anything_updated ) ) {
0 commit comments