Changeset 6114
- Timestamp:
- 11/10/2017 05:23:33 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php
r6062 r6114 207 207 $existing_json_checksum_file = file_exists( $this->checksum_file ); 208 208 209 $checksums = array( 210 'md5' => array(), 211 'sha256' => array() 212 ); 209 $checksums = array(); 213 210 foreach ( array( 'md5' => 'md5sum', 'sha256' => 'sha256sum' ) as $checksum_type => $checksum_bin ) { 214 211 $this->exec( sprintf( … … 227 224 $filename = trim( preg_replace( '!^./!', '', $filename ) ); 228 225 $checksum = trim( $checksum ); 229 $checksums[ $checksum_type][ $filename ] = $checksum; 226 227 if ( ! isset( $checksums[ $filename ] ) ) { 228 $checksums[ $filename ] = array( 'md5' => array(), 'sha256' => array() ); 229 } 230 231 $checksums[ $filename ][ $checksum_type ] = $checksum; 230 232 } 231 233 } 232 234 233 235 $json_checksum_file = (object) array( 234 'plugin' => $this->slug, 235 'version' => $plugin_version, 236 'source' => $this->plugin_version_svn_url, 237 'zip' => 'https://downloads.wordpress.org/plugins/' . basename( $this->zip_file ), 238 'md5' => $checksums['md5'], 239 'sha256' => $checksums['sha256'], 236 'plugin' => $this->slug, 237 'version' => $plugin_version, 238 'source' => $this->plugin_version_svn_url, 239 'zip' => 'https://downloads.wordpress.org/plugins/' . basename( $this->zip_file ), 240 'files' => $checksums, 240 241 ); 241 242 … … 262 263 263 264 // Combine Checksums from existing files and the new files 264 foreach ( array( 'md5', 'sha256' ) as $checksum_type ) { 265 if ( ! $existing_json_checksum_file || empty( $existing_json_checksum_file->{$checksum_type} ) ) { 266 continue; 267 } 268 $existing_checksums = (array) $existing_json_checksum_file->{$checksum_type}; // Assoc array => Object in JSON 269 $new_checksums = &$json_checksum_file->{$checksum_type}; // byref to update new array 270 271 foreach ( $existing_checksums as $file => $checksums ) { 272 if ( ! isset( $new_checksums[ $file ] ) ) { 273 // Deleted file, include it in checksums. 274 $new_checksums[ $file ] = $existing_checksums[ $file ]; 275 276 } elseif ( $new_checksums[ $file ] != $existing_checksums[ $file ] ) { 277 // Checksum has changed, include both in the resulting json file. 278 279 $new_checksums[ $file ] = array_unique( array_merge( 280 (array) $existing_checksums[ $file ], // May already be an array 281 (array) $new_checksums[ $file ] 265 foreach ( $existing_json_checksum_file->files as $file => $checksums ) { 266 if ( ! isset( $json_checksum_file->files[ $file ] ) ) { 267 // Deleted file, use existing checksums. 268 $json_checksum_file->files[ $file ] = $checksums; 269 270 } elseif ( $checksums !== $json_checksum_file->files[ $file ] ) { 271 // Checksum has changed, include both in the resulting json file. 272 foreach ( array( 'md5', 'sha256' ) as $checksum_type ) { 273 $json_checksum_file->files[ $file ][ $checksum_type ] = array_unique( array_merge( 274 (array) $checksums->{$checksum_type}, // May already be an array 275 (array) $json_checksum_file->files[ $file ][ $checksum_type ] 282 276 ) ); 277 // Reduce single arrays back to a string when possible. 278 if ( 1 == count( $json_checksum_file->files[ $file ][ $checksum_type ] ) ) { 279 $json_checksum_file->files[ $file ][ $checksum_type ] = array_shift( $json_checksum_file->files[ $file ][ $checksum_type ] ); 280 } 283 281 } 284 282 } 285 286 } 287 } 283 } 284 285 } 286 287 ksort( $json_checksum_file->files ); 288 288 289 289 file_put_contents( $this->checksum_file, wp_json_encode( $json_checksum_file ) );
Note: See TracChangeset
for help on using the changeset viewer.