Changeset 10044
- Timestamp:
- 07/09/2020 07:35:02 AM (4 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r10014 r10044 75 75 $stable_tag = $data['stable_tag']; 76 76 $tagged_versions = $data['tagged_versions']; 77 $last_modified = $data['last_modified']; 77 78 $blocks = $data['blocks']; 78 79 $block_files = $data['block_files']; … … 103 104 ( $svn_changed_tags && in_array( ( $stable_tag ?: 'trunk' ), $svn_changed_tags, true ) ) 104 105 ) { 105 $plugin->post_modified = $plugin->post_modified_gmt = current_time( 'mysql' ); 106 if ( $last_modified ) { 107 $plugin->post_modified = $plugin->post_modified_gmt = $last_modified; 108 } else { 109 $plugin->post_modified = $plugin->post_modified_gmt = current_time( 'mysql' ); 110 } 106 111 } 107 112 … … 331 336 if ( $trunk_readme_files ) { 332 337 $trunk_readme_file = reset( $trunk_readme_files ); 338 // Preference readme.txt over readme.md if both exist. 333 339 foreach ( $trunk_readme_files as $f ) { 334 340 if ( '.txt' == strtolower( substr( $f, -4 ) ) ) { … … 344 350 } 345 351 346 $ exported= false;352 $svn_info = false; 347 353 if ( $stable_tag && 'trunk' != $stable_tag ) { 348 $svn_export = SVN::export( 349 self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}", 350 $tmp_dir . '/export', 351 array( 352 'ignore-externals', 353 ) 354 ); 355 // Handle tags which we store as 0.blah but are in /tags/.blah 356 if ( ! $svn_export['result'] && '0.' == substr( $stable_tag, 0, 2 ) ) { 354 $stable_url = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}"; 355 $svn_info = SVN::info( $stable_url ); 356 357 if ( ! $svn_info['result'] && '0.' === substr( $stable_tag, 0, 2 ) ) { 358 // Handle tags which we store as 0.blah but are in /tags/.blah 357 359 $_stable_tag = substr( $stable_tag, 1 ); 358 $svn_export = SVN::export( 359 self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$_stable_tag}", 360 $tmp_dir . '/export', 361 array( 362 'ignore-externals', 363 ) 364 ); 365 } 366 if ( $svn_export['result'] && false !== $this->find_readme_file( $tmp_dir . '/export' ) ) { 367 $exported = true; 368 } else { 369 // Clear out any files that exist in the export. 370 Filesystem::rmdir( $tmp_dir . '/export' ); 371 } 372 } 373 if ( ! $exported ) { 360 $stable_url = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$_stable_tag}"; 361 $svn_info = SVN::info( $stable_url ); 362 } 363 364 // Verify that the tag has files, falling back to trunk if not. 365 if ( ! SVN::ls( $stable_tag ) ) { 366 $svn_info = false; 367 } 368 } 369 370 if ( ! $svn_info || ! $svn_info['result'] ) { 371 $stable_tag = 'trunk'; 372 $stable_url = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk"; 373 $svn_info = SVN::info( $stable_url ); 374 } 375 376 if ( ! $svn_info['result'] ) { 377 throw new Exception( 'Could not find stable SVN URL: ' . implode( ' ', reset( $svn_info['errors'] ) ) ); 378 } 379 380 $last_modified = false; 381 if ( preg_match( '/^([0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{1,2}:[0-9]{2}:[0-9]{2})/', $svn_info['result']['Last Changed Date'] ?? '', $m ) ) { 382 $last_modified = $m[0]; 383 } 384 385 $svn_export = SVN::export( 386 $stable_url, 387 $tmp_dir . '/export', 388 array( 389 'ignore-externals', 390 ) 391 ); 392 393 if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) { 374 394 // Catch the case where exporting a tag finds nothing, but there was nothing in trunk either. 375 395 if ( ! $trunk_files ) { … … 377 397 } 378 398 379 $stable_tag = 'trunk'; 380 // Either stable_tag = trunk, or the stable_tag tag didn't exist. 381 $svn_export = SVN::export( 382 self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk", 383 $tmp_dir . '/export', 384 array( 385 'ignore-externals', 386 ) 387 ); 388 if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) { 389 throw new Exception( 'Could not create SVN export: ' . implode( ' ', reset( $svn_export['errors'] ) ) ); 390 } 399 throw new Exception( 'Could not create SVN export: ' . implode( ' ', reset( $svn_export['errors'] ) ) ); 391 400 } 392 401 … … 402 411 403 412 // Now we look in the /assets/ folder for banners, screenshots, and icons. 404 $assets 413 $assets = array( 405 414 'screenshot' => array(), 406 415 'banner' => array(), 407 416 'icon' => array(), 408 417 ); 418 409 419 $svn_assets_folder = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/assets/", true /* verbose */ ); 410 420 if ( $svn_assets_folder ) { // /assets/ may not exist. … … 557 567 } ) ); 558 568 559 return compact( 'readme', 'stable_tag', ' tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks', 'block_files' );569 return compact( 'readme', 'stable_tag', 'last_modified', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks', 'block_files' ); 560 570 } 561 571 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php
r9025 r10044 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 ); 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 } 10 59 11 60 /**
Note: See TracChangeset
for help on using the changeset viewer.