Making WordPress.org


Ignore:
Timestamp:
03/13/2017 05:56:27 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: ZIPs: Do not build zips on demand, instead store them within a SVN repository.

See #1578

File:
1 edited

Legend:

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

    r3512 r5147  
    2222     * }
    2323     */
    24     public static function import( $path, $url, $message ) {
    25         $options     = array(
    26             'non-interactive',
    27             'm'    => $message,
    28             'user' => PLUGIN_SVN_MANAGEMENT_USER,
    29             'pass' => PLUGIN_SVN_MANAGEMENT_PASS,
    30         );
     24    public static function import( $path, $url, $message, $options = array() ) {
     25        $options[] = 'non-interactive';
     26        $options['m'] = $message;
     27        if ( empty( $options['username'] ) ) {
     28            $options['username'] = PLUGIN_SVN_MANAGEMENT_USER;
     29            $options['password'] = PLUGIN_SVN_MANAGEMENT_PASS;
     30        }
     31
    3132        $esc_options = self::parse_esc_parameters( $options );
    3233
     
    6869        $output = self::shell_exec( "svn export $esc_options $esc_url $esc_destination 2>&1" );
    6970        if ( preg_match( '/Exported revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
     71            $revision = (int) $m['revision'];
     72            $result   = true;
     73        } else {
     74            $result = false;
     75            $errors = self::parse_svn_errors( $output );
     76        }
     77
     78        return compact( 'result', 'revision', 'errors' );
     79    }
     80
     81    /**
     82     * Create an SVN Checkout of a URL to a local directory.
     83     *
     84     * @static
     85     *
     86     * @param string $url         The URL to export.
     87     * @param string $destination The local folder to checkout into.
     88     * @param array  $options     Optional. A list of options to pass to SVN. Default: empty array.
     89     * @return array {
     90     *     @type bool $result   The result of the operation.
     91     *     @type int  $revision The revision exported.
     92     * }
     93     */
     94    public static function checkout( $url, $destination, $options = array() ) {
     95        $options[]   = 'non-interactive';
     96        $esc_options = self::parse_esc_parameters( $options );
     97
     98        $esc_url         = escapeshellarg( $url );
     99        $esc_destination = escapeshellarg( $destination );
     100
     101        $output = self::shell_exec( "svn checkout $esc_options $esc_url $esc_destination 2>&1" );
     102        if ( preg_match( '/Checked out revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
     103            $revision = (int) $m['revision'];
     104            $result   = true;
     105        } else {
     106            $result = false;
     107            $errors = self::parse_svn_errors( $output );
     108        }
     109
     110        return compact( 'result', 'revision', 'errors' );
     111    }
     112
     113    /**
     114     * Update a SVN checkout.
     115     *
     116     * @static
     117     *
     118     * @param string $checkout The path of the SVN checkout to update.
     119     * @param array  $options  Optional. A list of options to pass to SVN. Default: empty array.
     120     * @return array {
     121     *     @type bool $result   The result of the operation.
     122     *     @type int  $revision The revision exported.
     123     * }
     124     */
     125    public static function up( $checkout, $options = array() ) {
     126        $options[]   = 'non-interactive';
     127        $esc_options = self::parse_esc_parameters( $options );
     128
     129        $esc_checkout = escapeshellarg( $checkout );
     130
     131        $output = self::shell_exec( "svn up $esc_options $esc_checkout 2>&1" );
     132        if ( preg_match( '/Updated to revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
     133            $revision = (int) $m['revision'];
     134            $result   = true;
     135        } else {
     136            $result = false;
     137            $errors = self::parse_svn_errors( $output );
     138        }
     139
     140        return compact( 'result', 'revision', 'errors' );
     141    }
     142
     143    /**
     144     * Add a file in a SVN checkout to be revisioned.
     145     *
     146     * @static
     147     *
     148     * @param string $checkout The path of the file to add to SVN.
     149     * @return array {
     150     *     @type bool $result   The result of the operation.
     151     * }
     152     */
     153    public static function add( $file ) {
     154        $options[]   = 'non-interactive';
     155        $esc_options = self::parse_esc_parameters( $options );
     156
     157        $esc_file     = escapeshellarg( $file );
     158
     159        $output = self::shell_exec( "svn add $esc_options $esc_file 2>&1" );
     160        if ( preg_match( "/^A/i", $output ) ) {;
     161            $result   = true;
     162        } else {
     163            $result = false;
     164            $errors = self::parse_svn_errors( $output );
     165        }
     166
     167        return compact( 'result', 'errors' );
     168    }
     169
     170    /**
     171     * Commit changes in a SVN checkout.
     172     *
     173     * @static
     174     *
     175     * @param string $checkout The local folder to import into SVN.
     176     * @param string $message  The commit message.
     177     * @param array  $options  Any specific options to pass to SVN.
     178     * @return array {
     179     *     @type bool $result   The result of the operation.
     180     *     @type int  $revision The revision imported.
     181     * }
     182     */
     183    public static function commit( $checkout, $message, $options = array() ) {
     184        $options[] = 'non-interactive';
     185        $options['m'] = $message;
     186        if ( empty( $options['username'] ) ) {
     187            $options['username'] = PLUGIN_SVN_MANAGEMENT_USER;
     188            $options['password'] = PLUGIN_SVN_MANAGEMENT_PASS;
     189        }
     190
     191        $esc_options = self::parse_esc_parameters( $options );
     192
     193        $esc_checkout = escapeshellarg( $checkout );
     194
     195        $output = self::shell_exec( "svn commit $esc_options $esc_checkout 2>&1" );
     196        if ( preg_match( '/Committed revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
    70197            $revision = (int) $m['revision'];
    71198            $result   = true;
Note: See TracChangeset for help on using the changeset viewer.