Ticket #5242: 5242.diff
File 5242.diff, 5.9 KB (added by , 5 years ago) |
---|
-
cli/class-import.php
73 73 $headers = $data['plugin_headers']; 74 74 $stable_tag = $data['stable_tag']; 75 75 $tagged_versions = $data['tagged_versions']; 76 $last_modified = $data['last_modified']; 76 77 $blocks = $data['blocks']; 77 78 $block_files = $data['block_files']; 78 79 … … 101 102 $plugin->post_modified == '0000-00-00 00:00:00' || 102 103 ( $svn_changed_tags && in_array( ( $stable_tag ?: 'trunk' ), $svn_changed_tags, true ) ) 103 104 ) { 104 $plugin->post_modified = $plugin->post_modified_gmt = current_time( 'mysql' ); 105 if ( $last_modified ) { 106 $plugin->post_modified = $plugin->post_modified_gmt = $last_modified; 107 } else { 108 $plugin->post_modified = $plugin->post_modified_gmt = current_time( 'mysql' ); 109 } 105 110 } 106 111 107 112 // Plugins should move from 'approved' to 'publish' on first parse … … 342 347 $stable_tag = $trunk_readme->stable_tag; 343 348 } 344 349 345 $exported = false; 346 if ( $stable_tag && 'trunk' != $stable_tag ) { 347 $svn_export = SVN::export( 348 self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}", 349 $tmp_dir . '/export', 350 array( 351 'ignore-externals', 352 ) 353 ); 350 $stable_url = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}"; 351 $svn_info = SVN::info( $stable_url ); 352 if ( ! $svn_info['result'] && '0.' === substr( $stable_tag, 0, 2 ) ) { 354 353 // Handle tags which we store as 0.blah but are in /tags/.blah 355 if ( ! $svn_export['result'] && '0.' == substr( $stable_tag, 0, 2 ) ) { 356 $_stable_tag = substr( $stable_tag, 1 ); 357 $svn_export = SVN::export( 358 self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$_stable_tag}", 359 $tmp_dir . '/export', 360 array( 361 'ignore-externals', 362 ) 363 ); 364 } 365 if ( $svn_export['result'] && false !== $this->find_readme_file( $tmp_dir . '/export' ) ) { 366 $exported = true; 367 } else { 368 // Clear out any files that exist in the export. 369 Filesystem::rmdir( $tmp_dir . '/export' ); 370 } 354 $_stable_tag = substr( $stable_tag, 1 ); 355 $stable_url = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$_stable_tag}"; 356 $svn_info = SVN::info( $stable_url ); 371 357 } 372 if ( ! $exported ) { 358 if ( ! $svn_info['result'] ) { 359 $stable_tag = 'trunk'; 360 $stable_url = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk"; 361 $svn_info = SVN::info( $stable_url ); 362 } 363 if ( ! $svn_info['result'] ) { 364 throw new Exception( 'Could not find stable SVN URL: ' . implode( ' ', reset( $svn_info['errors'] ) ) ); 365 } 366 367 $last_modified = $svn_info['result']['Last Changed Date'] ?? ''; 368 if ( preg_match( '/([0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{1,2}:[0-9]{2}:[0-9]{2})/', $last_modified, $m ) ) { 369 $last_modified = $m[0]; 370 } 371 372 $svn_export = SVN::export( 373 $stable_url, 374 $tmp_dir . '/export', 375 array( 376 'ignore-externals', 377 ) 378 ); 379 380 if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) { 373 381 // Catch the case where exporting a tag finds nothing, but there was nothing in trunk either. 374 382 if ( ! $trunk_files ) { 375 383 throw new Exception( 'Plugin has no files in trunk, nor tags.' ); 376 384 } 377 385 378 $stable_tag = 'trunk'; 379 // Either stable_tag = trunk, or the stable_tag tag didn't exist. 380 $svn_export = SVN::export( 381 self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk", 382 $tmp_dir . '/export', 383 array( 384 'ignore-externals', 385 ) 386 ); 387 if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) { 388 throw new Exception( 'Could not create SVN export: ' . implode( ' ', reset( $svn_export['errors'] ) ) ); 389 } 386 throw new Exception( 'Could not create SVN export: ' . implode( ' ', reset( $svn_export['errors'] ) ) ); 390 387 } 391 388 392 389 // The readme may not actually exist, but that's okay. … … 555 552 return preg_match( '!\.(?:js|jsx|css)$!i', $filename ); 556 553 } ) ); 557 554 558 return compact( 'readme', 'stable_tag', ' tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks', 'block_files' );555 return compact( 'readme', 'stable_tag', 'last_modified', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks', 'block_files' ); 559 556 } 560 557 561 558 /** -
tools/class-svn.php
7 7 * @package WordPressdotorg\Plugin_Directory\Tools 8 8 */ 9 9 class SVN { 10 /** 11 * Get SVN info about a URL. 12 * 13 * @static 14 * 15 * @param string $url The URL of the svn repo. 16 * @param array $options Optional. A list of options to pass to SVN. Default: empty array. 17 * 18 * @return array { 19 * @type bool|array $result False on failure. Otherwise an associative array. 20 * @type bool|array $errors Whether any errors or warnings were encountered. 21 * } 22 */ 23 public static function info( $url, $options = array() ) { 24 $esc_url = escapeshellarg( $url ); 10 25 26 $options[] = 'non-interactive'; 27 if ( empty( $options['username'] ) ) { 28 $options['username'] = PLUGIN_SVN_MANAGEMENT_USER; 29 $options['password'] = PLUGIN_SVN_MANAGEMENT_PASS; 30 } 31 $esc_options = self::parse_esc_parameters( $options ); 32 33 $output = self::shell_exec( "svn info $esc_options $esc_url 2>&1" ); 34 if ( preg_match( '!URL: ' . untrailingslashit( $url ) . '\n!i', $output ) ) { 35 $lines = explode( "\n", $output ); 36 $result = array_filter( array_reduce( 37 $lines, 38 function( $carry, $item ) { 39 $pair = explode( ':', $item, 2 ); 40 if ( isset( $pair[1] ) ) { 41 $key = trim( $pair[0] ); 42 $carry[ $key ] = trim( $pair[1] ); 43 } else { 44 $carry[] = trim( $pair[0] ); 45 } 46 47 return $carry; 48 }, 49 array() 50 ) ); 51 $errors = false; 52 } else { 53 $result = false; 54 $errors = self::parse_svn_errors( $output ); 55 } 56 57 return compact( 'result', 'errors' ); 58 } 59 11 60 /** 12 61 * Import a local directory to a SVN path. 13 62 *