Making WordPress.org


Ignore:
Timestamp:
12/18/2024 06:25:51 AM (22 months ago)
Author:
dd32
Message:

Plugin Directory: SVN: Add SVN::copy().

See ​https://github.com/WordPress/wordpress.org/pull/343.
See ​https://github.com/WordPress/wordpress.org/pull/407.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php

    r14313 r14314  
    446446         */
    447447        public static function rename( $from, $to, $options = array() ) {
     448                return SVN::_copy_rename_helper( 'mv', $from, $to, $options );
     449        }
     450
     451        /**
     452         * Copy a file or folder in a SVN checkout.
     453         *
     454         * @static
     455         *
     456         * @param string $source      The path of the file to copy. May be a URL.
     457         * @param string $destination The path to copy the file to. May be a URL.
     458         * @param array  $options  Optional. A list of options to pass to SVN. Default: empty array.
     459         * @return array {
     460         *    @type bool        $result   The result of the operation.
     461         *    @type int         $revision The revision.
     462         *    @type false|array $errors   Whether any errors or warnings were encountered.
     463         * }
     464         */
     465        public static function copy( $from, $to, $options = array() ) {
     466                return SVN::_copy_rename_helper( 'cp', $from, $to, $options = array() );
     467        }
     468
     469        /**
     470         * Helper function for copy and rename operations.
     471         *
     472         * @static
     473         * @param string $svn_op  The SVN operation to perform. 'cp' or 'mv'.
     474         * @param string $from    The path of the SVN folder to rename. May be a URL.
     475         * @param string $to      The new path of the SVN folder. May be a URL.
     476         * @param array  $options Optional. A list of options to pass to SVN. Default: empty array.
     477         * @return array {
     478         *    @type bool        $result   The result of the operation.
     479         *    @type int         $revision The revision.
     480         *    @type false|array $errors   Whether any errors or warnings were encountered.
     481         * }
     482         */
     483        public static function _copy_rename_helper( $svn_op, $from, $to, $options = array() ) {
    448484                $options[] = 'non-interactive';
    449485                $is_url    = ( preg_match( '#https?://#i', $from ) && preg_match( '#https?://#i', $to ) );
    … …  
    452488                        // Set the message if not provided.
    453489                        if ( ! isset( $options['message'] ) && ! isset( $options['m'] ) ) {
    454                                 $options['message'] = sprintf( "Rename %s to %s.", basename( $from ), basename( $to ) );
     490                                $options['message'] = sprintf(
     491                                        "%s %s to %s.",
     492                                        'mv' === $svn_op ? 'Rename' : 'Copy',
     493                                        basename( $from ),
     494                                        basename( $to )
     495                                );
    455496                        }
    456497
    … …  
    463504                $esc_options = self::parse_esc_parameters( $options );
    464505
     506                $esc_op   = escapeshellarg( $svn_op );
    465507                $esc_from = escapeshellarg( $from );
    466508                $esc_to   = escapeshellarg( $to );
    467509
    468                 $output = self::shell_exec( "svn mv $esc_from $esc_to $esc_options 2>&1" );
     510                $output = self::shell_exec( "svn $esc_op $esc_from $esc_to $esc_options 2>&1" );
    469511                if ( $is_url && preg_match( '/Committed revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
    470512                        $revision = (int) $m['revision'];
Note: See TracChangeset for help on using the changeset viewer.