| 1 | #!/usr/bin/php |
|---|
| 2 | <?php |
|---|
| 3 | |
|---|
| 4 | // == Some functions == |
|---|
| 5 | |
|---|
| 6 | function prompt( $message ) { |
|---|
| 7 | fwrite( STDOUT, $message ); |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | function get_from_prompt() { |
|---|
| 11 | return str_replace("\n", '', fgets( STDIN ) ); |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | date_default_timezone_set( 'America/New_York' ); |
|---|
| 15 | |
|---|
| 16 | // == Meat and potatoes == |
|---|
| 17 | |
|---|
| 18 | prompt( 'You should be in an up-to-date checkout of the WordPress branch you want to modify. Press return to verify.' ); |
|---|
| 19 | get_from_prompt(); |
|---|
| 20 | |
|---|
| 21 | prompt( 'Old path? e.g. tags/2.9 : ' ); |
|---|
| 22 | $old = trim ( get_from_prompt(), '/ ' ); |
|---|
| 23 | prompt( 'New path? e.g. trunk : ' ); |
|---|
| 24 | $new = trim( get_from_prompt(), '/ ' ); |
|---|
| 25 | |
|---|
| 26 | exec( "svn di --summarize http://svn.automattic.com/wordpress/$old http://svn.automattic.com/wordpress/$new | awk '{ print $2 }' | grep -E '.(gif|png)$' | grep -v 'wp-content' | sed 's#http://svn.automattic.com/wordpress/$old/##' | sed 's#wp-admin/##' | sed 's#wp-includes/##'", $files ); |
|---|
| 27 | |
|---|
| 28 | // Removing existing version string on any changed files |
|---|
| 29 | $regex1 = $regex2 = '(' . implode( '|', $files ) . ')'; |
|---|
| 30 | $regex1 .= '\?ver=[0-9]{8}'; |
|---|
| 31 | exec( "find . -type f | fgrep -v '/.svn' | sed 's#./##' | xargs perl -pi -e 's#{$regex1}#\$1#g;'" ); |
|---|
| 32 | |
|---|
| 33 | // Add new versioning string |
|---|
| 34 | $version_string = date( 'Ymd' ); |
|---|
| 35 | exec( "find . -type f -not -name update-core.php -not -name manifest.php | fgrep -v '/.svn' | sed 's#./##' | xargs perl -pi -e 's#{$regex2}#\$1?ver={$version_string}#g;'" ); |
|---|
| 36 | |
|---|
| 37 | exec( "svn status | grep '^M ' | awk '{print $2}' | grep -E '.(css|js)$'", $modified ); |
|---|
| 38 | |
|---|
| 39 | $manual = array(); |
|---|
| 40 | $bump_colors = false; |
|---|
| 41 | $regex_replace = "\$1'{$version_string}'\$4"; |
|---|
| 42 | |
|---|
| 43 | foreach ( (array) $modified as $m ) { |
|---|
| 44 | $originalm = $m; |
|---|
| 45 | if ( strpos( $m, '.dev.' ) !== false || strpos( $m, '-rtl.' ) !== false ) |
|---|
| 46 | continue; // The non-dev version will accomplish the update for us |
|---|
| 47 | if ( strpos( $m, '/colors-' ) !== false ) { |
|---|
| 48 | $bump_colors = true; |
|---|
| 49 | continue; |
|---|
| 50 | } |
|---|
| 51 | $m = preg_quote( $m, '#' ); |
|---|
| 52 | $m = preg_replace( '#\\\.(css|js)$#', '(\\\$suffix)?\.$1', $m ); |
|---|
| 53 | if ( '.css' == substr( $m, -4, 4 ) ) { |
|---|
| 54 | $regex = "(styles->add *?\(.*?, *?['\"]/{$m}.*?, *?)'([0-9]+[a-z]{0,2})'( *?\);)$"; |
|---|
| 55 | } elseif ( '.js' == substr( $m, -3, 3 ) ) { |
|---|
| 56 | $regex = "(scripts->add *?\(.*?, *?['\"]/{$m}.*?, *?array *?\([^)]*?\) *?, *?)'([0-9]+[a-z]{0,2})'( *?\);)$"; |
|---|
| 57 | } |
|---|
| 58 | // echo $regex . ' => ' . $regex_replace . "\n"; |
|---|
| 59 | $sl1 = file_get_contents( 'wp-includes/script-loader.php' ); |
|---|
| 60 | exec( "perl -pi -e " . escapeshellarg( "s#{$regex}#{$regex_replace}#g;") . " wp-includes/script-loader.php" ); |
|---|
| 61 | if ( $sl1 == file_get_contents( 'wp-includes/script-loader.php' ) ) |
|---|
| 62 | $manual[] = $originalm; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | if ( $bump_colors ) { |
|---|
| 66 | $regex_replace = "\$1'{$version_string}'\$3"; |
|---|
| 67 | exec( "perl -pi -e " . escapeshellarg( "s#(\\\$colors_version = )'(.*?)'(;)#{$regex_replace}#g;") . " wp-includes/script-loader.php" ); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | if ( $manual ) { |
|---|
| 71 | echo "The following CSS/JS files have been modified. You need to update wp-includes/script-loader.php and bump their versions manually, as the automated method failed:\n\n"; |
|---|
| 72 | $manual = ' ' . implode( "\n ", $manual ) . "\n"; |
|---|
| 73 | echo $manual; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | echo "\n[DONE]\n"; |
|---|