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 copied

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/rebuild-zip.php

    r5139 r5147  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3use WordPressdotorg\Plugin_Directory\Tools\SVN;
    34
    45// This script should only be called in a CLI environment.
     
    78}
    89
    9 ob_start();
     10//ob_start();
    1011
    11 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'changed-tags:', 'async' ) );
     12$opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'versions:', 'async' ) );
    1213
    1314// Guess the default parameters:
     
    1516    $opts['plugin'] = $argv[1];
    1617    $argv[1] = '--plugin ' . $argv[1];
     18}
     19if ( empty( $opts ) && $argc == 3 ) {
     20    $opts['plugin'] = $argv[1];
     21    $argv[1] = '--plugin ' . $argv[1];
     22
     23    $opts['versions'] = $argv[2];
     24    $argv[2] = '--versions ' . $argv[2];
    1725}
    1826if ( empty( $opts['url'] ) ) {
     
    2230    $opts['abspath'] = substr( __DIR__, 0, strpos( __DIR__, 'wp-content' ) );
    2331}
    24 
    25 if ( empty( $opts['changed-tags'] ) ) {
    26     $opts['changed-tags'] = array( 'trunk' );
    27 } else {
    28     $opts['changed-tags'] = explode( ',', $opts['changed-tags'] );
     32if ( empty( $opts['versions'] ) ) {
     33    $opts['versions'] = '';
    2934}
    30 
    31 $opts['async'] = isset( $opts['async'] );
    3235
    3336foreach ( array( 'url', 'abspath', 'plugin' ) as $opt ) {
     
    3639        fwrite( STDERR, "Usage: php {$argv[0]} --plugin hello-dolly --abspath /home/example/public_html --url https://wordpress.org/plugins/\n" );
    3740        fwrite( STDERR, "--url and --abspath will be guessed if possible.\n" );
    38         die();
     41        exit(1);
    3942    }
    4043}
     
    5255        fwrite( STDERR, "\tphp " . implode( ' ', $argv ) . " --url " . get_site_url( WPORG_PLUGIN_DIRECTORY_BLOGID, '/' ) . "\n" );
    5356    }
    54     die();
     57    exit(1);
    5558}
    5659
    57 $plugin_slug  = $opts['plugin'];
    58 $changed_tags = $opts['changed-tags'];
    59 $start_time   = microtime(1);
     60$plugin_slug = $opts['plugin'];
     61$versions    = array_filter( array_unique( array_map( 'trim', (array) explode( ',', $opts['versions'] ) ) ), 'strlen' );
     62$start_time  = microtime(1);
    6063
    61 // If async, queue it to be parsed instead.
    62 if ( $opts['async'] ) {
    63     Jobs\Plugin_Import::queue( $plugin_slug, array( 'tags_touched' => $changed_tags ) );
    64     echo "Queueing Import for $plugin_slug... OK\n";
    65     die();
     64if ( empty( $versions ) ) {
     65    // Rebuild them all!
     66    $svn_tags = SVN::ls( "http://plugins.svn.wordpress.org/{$plugin_slug}/tags/" );
     67    if ( false === $svn_tags ) {
     68        fwrite( STDERR, "Error! Failed to retrieve SVN tag listing." );
     69        exit(1);
     70    }
     71
     72    $versions = array_map(
     73        function( $dir ) { return trim( $dir, '/' ); },
     74        $svn_tags
     75    );
     76    $versions[] = 'trunk';
    6677}
    6778
    68 echo "Processing Import for $plugin_slug... ";
     79if ( ! $versions ) {
     80    fwrite( STDERR, "Error! No versions specified (or we couldn't find any)" );
     81    exit(1);
     82}
     83
     84echo "Rebuilding ZIPs for $plugin_slug... ";
    6985try {
    70     $importer = new CLI\Import;
    71     $importer->import_from_svn( $plugin_slug, $changed_tags );
     86    $zip_builder = new ZIP\Builder();
     87    $zip_builder->build(
     88        $plugin_slug,
     89        $versions,
     90        "{$plugin_slug}: Rebuild triggered by " . php_uname('n' )
     91    );
     92
    7293    echo "OK. Took " . round( microtime(1) - $start_time, 2 )  . "s\n";
    7394} catch( \Exception $e ) {
    74     echo "Failed. Took " . round( microtime(1) - $start_time, 2 )  . "s\n";
    75 
    76     fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" );
     95    fwrite( STDERR, "{$plugin_slug}: Zip Rebuild failed: " . $e->getMessage() . "\n" );
    7796    exit(1);
    7897}
Note: See TracChangeset for help on using the changeset viewer.