WordPress.org

Making WordPress.org

Changeset 6114


Ignore:
Timestamp:
11/10/2017 05:23:33 AM (8 months ago)
Author:
dd32
Message:

Plugin Directory: Checksums: Combine the md5 and sha256 fields back into the files property.

See #3192

File:
1 edited

Legend:

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

    r6062 r6114  
    207207        $existing_json_checksum_file = file_exists( $this->checksum_file );
    208208
    209         $checksums = array(
    210             'md5' => array(),
    211             'sha256' => array()
    212         );
     209        $checksums = array();
    213210        foreach ( array( 'md5' => 'md5sum', 'sha256' => 'sha256sum' ) as $checksum_type => $checksum_bin ) {
    214211            $this->exec( sprintf(
     
    227224                $filename = trim( preg_replace( '!^./!', '', $filename ) );
    228225                $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;
    230232            }
    231233        }
    232234
    233235        $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,
    240241        );
    241242
     
    262263
    263264            // 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 ]
    282276                        ) );
     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                        }
    283281                    }
    284282                }
    285 
    286             }
    287         }
     283            }
     284
     285        }
     286
     287        ksort( $json_checksum_file->files );
    288288
    289289        file_put_contents( $this->checksum_file, wp_json_encode( $json_checksum_file ) );
Note: See TracChangeset for help on using the changeset viewer.