Changeset 13729
- Timestamp:
- 05/17/2024 06:14:37 AM (11 months 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/admin/class-customizations.php
r13522 r13729 4 4 use \WordPressdotorg\Plugin_Directory; 5 5 use \WordPressdotorg\Plugin_Directory\Tools; 6 use \WordPressdotorg\Plugin_Directory\Tools\SVN; 6 7 use \WordPressdotorg\Plugin_Directory\Template; 7 8 use \WordPressdotorg\Plugin_Directory\Readme\Validator; … … 562 563 */ 563 564 function check_existing_plugin_slug_on_post_update( $data, $postarr ) { 565 global $wpdb; 566 564 567 if ( 'plugin' !== $data['post_type'] || ! isset( $postarr['ID'] ) ) { 565 568 return $data; 566 569 } 567 570 568 $existing_plugin = Plugin_Directory\Plugin_Directory::get_plugin_post( $data['post_name'] ); 571 // If we can't locate the existing plugin, we can't check for a conflict. 572 $plugin = get_post( $postarr['ID'] ); 573 if ( ! $plugin ) { 574 return $data; 575 } 576 577 $old_slug = $plugin->post_name; 578 $new_slug = $data['post_name']; 579 $existing_plugin = Plugin_Directory\Plugin_Directory::get_plugin_post( $new_slug ); 569 580 570 581 // Is there already a plugin with the same slug? 571 if ( $existing_plugin && $existing_plugin->ID != $p ostarr['ID']) {582 if ( $existing_plugin && $existing_plugin->ID != $plugin->ID ) { 572 583 wp_die( sprintf( 573 584 /* translators: %s: plugin slug */ 574 585 __( 'Error: The plugin %s already exists.', 'wporg-plugins' ), 575 $ data['post_name']586 $new_slug 576 587 ) ); 577 588 } 578 589 590 // If the plugin is approved, we'll need to perform a folder rename, and re-grant SVN access. 591 if ( 'approved' === $plugin->post_status ) { 592 // SVN Rename $old_slug to $new_slug 593 $result = SVN::rename( 594 "http://plugins.svn.wordpress.org/{$old_slug}/", 595 "http://plugins.svn.wordpress.org/{$new_slug}/", 596 array( 597 'message' => sprintf( 'Renaming %1$s to %2$s.', $old_slug, $new_slug ), 598 ) 599 ); 600 if ( $result['errors'] ) { 601 $error = 'Error renaming SVN repository: ' . var_export( $result['errors'], true ); 602 Tools::audit_log( $error, $plugin->ID ); 603 wp_die( $error ); // Abort before the post is altered. 604 } else { 605 Tools::audit_log( 606 sprintf( 607 'Renamed SVN repository in %s.', 608 'https://plugins.svn.wordpress.org/changeset/' . $result['revision'] 609 ), 610 $plugin->ID 611 ); 612 613 /* 614 * Migrate Committers to new path. 615 * As no committers have changed as part of this operation, just update the database. 616 */ 617 $wpdb->update( 618 PLUGINS_TABLE_PREFIX . 'svn_access', 619 [ 'path' => '/' . $new_slug ], 620 [ 'path' => '/' . $old_slug ] 621 ); 622 } 623 } 624 579 625 // Record the slug change. 580 $plugin = get_post( $postarr['ID'] ); 581 if ( $plugin && $plugin->post_name !== $data['post_name'] ) { 626 if ( $old_slug !== $new_slug ) { 582 627 // Only log if the slugs don't appear to be rejection-related. 583 628 if ( 584 ! preg_match( '!^rejected-.+-rejected$!', $ post->post_name) &&585 ! preg_match( '!^rejected-.+-rejected$!', $ data['post_name'])629 ! preg_match( '!^rejected-.+-rejected$!', $old_slug ) && 630 ! preg_match( '!^rejected-.+-rejected$!', $new_slug ) 586 631 ) { 587 632 Tools::audit_log( sprintf( 588 633 "Slug changed from '%s' to '%s'.", 589 $ plugin->post_name,590 $ data['post_name']634 $old_slug, 635 $new_slug 591 636 ), $plugin->ID ); 592 637 } … … 736 781 remove_meta_box( 'commentstatusdiv', 'plugin', 'normal' ); 737 782 738 // Remove slug metabox unless the slug is editable forthe current user.739 if ( ! in_array( $post->post_status, array( 'new', 'pending' ) ) || ! current_user_can( 'plugin_approve', $post ) ) {783 // Remove slug metabox unless the slug is editable by the current user. 784 if ( ! in_array( $post->post_status, array( 'new', 'pending', 'approved' ) ) || ! current_user_can( 'plugin_approve', $post ) ) { 740 785 remove_meta_box( 'slugdiv', 'plugin', 'normal' ); 741 786 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php
r13709 r13729 430 430 431 431 /** 432 * Rename a SVN path (or url). 433 * 434 * @static 435 * 436 * @param string $from The path of the SVN folder to rename. May be a URL. 437 * @param string $to The new path of the SVN folder. May be a URL. 438 * @param array $options Optional. A list of options to pass to SVN. Default: empty array. 439 * @return array { 440 * @type bool $result The result of the operation. 441 * @type int $revision The revision. 442 * @type false|array $errors Whether any errors or warnings were encountered. 443 * } 444 */ 445 public static function rename( $from, $to, $options = array() ) { 446 $options[] = 'non-interactive'; 447 $is_url = ( preg_match( '#https?://#i', $from ) && preg_match( '#https?://#i', $to ) ); 448 449 if ( $is_url ) { 450 // Set the message if not provided. 451 if ( ! isset( $options['message'] ) && ! isset( $options['m'] ) ) { 452 $options['message'] = sprintf( "Rename %s to %s.", basename( $from ), basename( $to ) ); 453 } 454 455 if ( empty( $options['username'] ) ) { 456 $options['username'] = PLUGIN_SVN_MANAGEMENT_USER; 457 $options['password'] = PLUGIN_SVN_MANAGEMENT_PASS; 458 } 459 } 460 461 $esc_options = self::parse_esc_parameters( $options ); 462 463 $esc_from = escapeshellarg( $from ); 464 $esc_to = escapeshellarg( $to ); 465 466 $output = self::shell_exec( "svn mv $esc_from $esc_to $esc_options 2>&1" ); 467 if ( $is_url && preg_match( '/Committed revision (?P<revision>\d+)[.]/i', $output, $m ) ) { 468 $revision = (int) $m['revision']; 469 $result = true; 470 $errors = false; 471 } else { 472 $errors = self::parse_svn_errors( $output ); 473 $revision = false; 474 475 if ( $is_url || $errors ) { 476 $result = false; 477 } else { 478 $result = true; 479 } 480 } 481 482 return compact( 'result', 'revision', 'errors' ); 483 } 484 485 /** 432 486 * Parse and escape the provided SVN arguements for usage on the CLI. 433 487 *
Note: See TracChangeset
for help on using the changeset viewer.