Skip to content

Commit 7ae98fc

Browse files
committed
Record version of WP for which item was last imported
Also: * Updates `import_version()` to return the version number it obtained, or false. * Stores version in `_wp-parser_last_parsed_wp_version` post meta
1 parent 17cb34f commit 7ae98fc

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lib/class-importer.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class Importer implements LoggerAwareInterface {
8181
*/
8282
public $errors = array();
8383

84+
/**
85+
* Version number of codebase being parsed.
86+
*
87+
* @var string
88+
*/
89+
public $version;
90+
8491
/**
8592
* @var array Cached items of inserted terms
8693
*/
@@ -158,6 +165,12 @@ public function import( array $data, $skip_sleep = false, $import_ignored_functi
158165
exit;
159166
}
160167

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+
161174
$root = '';
162175
foreach ( $data as $file ) {
163176
$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 =
336349
sleep( 3 );
337350
}
338351
}
339-
340-
if ( 'wp-includes/version.php' === $file['path'] ) {
341-
$this->import_version( $file );
342-
}
343352
}
344353

345354
/**
@@ -477,21 +486,25 @@ protected function import_method( array $data, $parent_post_id = 0, $import_igno
477486
* Updates the 'wp_parser_imported_wp_version' option with the version from wp-includes/version.php.
478487
*
479488
* @param array $data Data
489+
* @return string|false WordPress version number, or false if not known.
480490
*/
481491
protected function import_version( $data ) {
482492

483493
$version_path = $data['root'] . '/' . $data['path'];
484494

485495
if ( ! is_readable( $version_path ) ) {
486-
return;
496+
return false;
487497
}
488498

489499
include $version_path;
490500

491501
if ( isset( $wp_version ) && $wp_version ) {
492502
update_option( 'wp_parser_imported_wp_version', $wp_version );
493503
$this->logger->info( "\t" . sprintf( 'Updated option wp_parser_imported_wp_version to "%1$s"', $wp_version ) );
504+
return $wp_version;
494505
}
506+
507+
return false;
495508
}
496509

497510
/**
@@ -747,6 +760,7 @@ public function import_item( array $data, $parent_post_id = 0, $import_ignored =
747760
$anything_updated[] = update_post_meta( $post_id, '_wp-parser_line_num', (string) $data['line'] );
748761
$anything_updated[] = update_post_meta( $post_id, '_wp-parser_end_line_num', (string) $data['end_line'] );
749762
$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 );
750764

751765
// If the post didn't need to be updated, but meta or tax changed, update it to bump last modified.
752766
if ( ! $is_new_post && ! $post_needed_update && array_filter( $anything_updated ) ) {

0 commit comments

Comments
 (0)