Changeset 6287 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php
- Timestamp:
- 12/19/2017 04:22:37 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php
r6281 r6287 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Zip; 3 3 4 use WordPressdotorg\Plugin_Directory\Tools\SVN; 4 5 use Exception; … … 11 12 class Builder { 12 13 13 const TMP_DIR = '/tmp/plugin-zip-builder';14 const SVN_URL = 'https://plugins.svn.wordpress.org';14 const TMP_DIR = '/tmp/plugin-zip-builder'; 15 const SVN_URL = 'https://plugins.svn.wordpress.org'; 15 16 const ZIP_SVN_URL = PLUGIN_ZIP_SVN_URL; 16 17 … … 60 61 $this->tmp_dir, 61 62 array( 62 'depth' => 'empty',63 'depth' => 'empty', 63 64 'username' => PLUGIN_ZIP_SVN_USER, 64 65 'password' => PLUGIN_ZIP_SVN_PASS, … … 70 71 // Ensure the plugins folder exists within svn 71 72 $plugin_folder = "{$this->tmp_dir}/{$this->slug}/"; 73 72 74 $res = SVN::up( 73 75 $plugin_folder, 74 76 array( 75 'depth' => 'empty' 77 'depth' => 'empty', 76 78 ) 77 79 ); … … 105 107 // This is done within the checksum generation function due to us not knowing the checksum filename until export_plugin(). 106 108 // SVN::up( $this->checksum_file ); 107 108 109 try { 109 110 110 $this->tmp_build_dir = $this->zip_file . '-files';111 $this->tmp_build_dir = $this->zip_file . '-files'; 111 112 mkdir( $this->tmp_build_dir, 0777, true ); 112 113 … … 120 121 $this->cleanup_plugin_tmp(); 121 122 122 } catch ( Exception $e ) {123 } catch ( Exception $e ) { 123 124 // In event of error, skip this file this time. 124 125 $this->cleanup_plugin_tmp(); … … 203 204 204 205 $skip_bad_files = array(); 205 $checksums = array(); 206 foreach ( array( 'md5' => 'md5sum', 'sha256' => 'sha256sum' ) as $checksum_type => $checksum_bin ) { 206 $checksums = array(); 207 foreach ( array( 208 'md5' => 'md5sum', 209 'sha256' => 'sha256sum', 210 ) as $checksum_type => $checksum_bin ) { 207 211 $checksum_output = array(); 208 212 $this->exec( sprintf( … … 212 216 213 217 if ( $return_value ) { 214 //throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 );215 // TODO For now, just silently keep going.218 // throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 ); 219 // TODO For now, just silently keep going. 216 220 continue; 217 221 } … … 219 223 foreach ( $checksum_output as $line ) { 220 224 list( $checksum, $filename ) = preg_split( '!\s+!', $line, 2 ); 225 221 226 $filename = trim( preg_replace( '!^./!', '', $filename ) ); 222 227 $checksum = trim( $checksum ); … … 228 233 229 234 if ( ! isset( $checksums[ $filename ] ) ) { 230 $checksums[ $filename ] = array( 'md5' => array(), 'sha256' => array() ); 235 $checksums[ $filename ] = array( 236 'md5' => array(), 237 'sha256' => array(), 238 ); 231 239 } 232 240 … … 249 257 // Sometimes plugin versions exist in multiple tags/zips, include all the SVN urls & ZIP urls 250 258 foreach ( array( 'source', 'zip' ) as $maybe_different ) { 251 if ( ! empty( $existing_json_checksum_file->{$maybe_different} ) &&259 if ( ! empty( $existing_json_checksum_file->{$maybe_different} ) && 252 260 $existing_json_checksum_file->{$maybe_different} != $json_checksum_file->{$maybe_different} 253 261 ) { 254 262 $json_checksum_file->{$maybe_different} = array_unique( array_merge( 255 263 (array) $existing_json_checksum_file->{$maybe_different}, 256 (array) $json_checksum_file->{$maybe_different}264 (array) $json_checksum_file->{$maybe_different} 257 265 ) ); 258 266 … … 282 290 $json_checksum_file->files[ $file ][ $checksum_type ] = array_unique( array_merge( 283 291 (array) $checksums->{$checksum_type}, // May already be an array 284 (array) $json_checksum_file->files[ $file ][ $checksum_type ]292 (array) $json_checksum_file->files[ $file ][ $checksum_type ] 285 293 ) ); 294 286 295 // Reduce single arrays back to a string when possible. 287 296 if ( 1 == count( $json_checksum_file->files[ $file ][ $checksum_type ] ) ) { … … 291 300 } 292 301 } 293 294 302 } 295 303 … … 317 325 $i = 0; 318 326 do { 319 $rand = uniqid();327 $rand = uniqid(); 320 328 $filename = "{$dir}/{$prefix}-{$rand}{$i}{$suffix}"; 321 } while ( false === ( $fp = @fopen( $filename, 'x' ) ) && $i++ < 50 );329 } while ( false === ( $fp = @fopen( $filename, 'x' ) ) && $i++ < 50 ); 322 330 323 331 if ( $i >= 50 ) { … … 358 366 // Handle tags which we store as 0.blah but are in /tags/.blah 359 367 if ( ! $res['result'] && '0.' == substr( $this->version, 0, 2 ) ) { 360 $_version = substr( $this->version, 1 );368 $_version = substr( $this->version, 1 ); 361 369 $this->plugin_version_svn_url = self::SVN_URL . "/{$this->slug}/tags/{$_version}/"; 362 $res = SVN::export( $this->plugin_version_svn_url, $build_dir, $svn_params );370 $res = SVN::export( $this->plugin_version_svn_url, $build_dir, $svn_params ); 363 371 } 364 372 if ( ! $res['result'] ) { … … 449 457 foreach ( $plugins_downloads_load_balancer /* TODO */ as $lb ) { 450 458 $url = 'http://' . $lb . PLUGIN_ZIP_X_ACCEL_REDIRECT_LOCATION . $zip; 451 wp_remote_request( 452 $url, 453 array( 454 'method' => 'PURGE', 455 ) 456 ); 459 460 wp_remote_request( $url, array( 461 'method' => 'PURGE', 462 ) ); 457 463 } 458 464 }
Note: See TracChangeset
for help on using the changeset viewer.