Changeset 3373
- Timestamp:
- 06/15/2016 04:47:04 AM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.php
r3164 r3373 9 9 ob_start(); 10 10 11 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:' ) );11 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'changed-tags:' ) ); 12 12 13 13 // Guess the default parameters: … … 21 21 if ( empty( $opts['abspath'] ) && false !== strpos( __DIR__, 'wp-content' ) ) { 22 22 $opts['abspath'] = substr( __DIR__, 0, strpos( __DIR__, 'wp-content' ) ); 23 } 24 25 if ( empty( $opts['changed-tags'] ) ) { 26 $opts['changed-tags'] = array( 'trunk' ); 27 } else { 28 $opts['changed-tags'] = explode( ',', $opts['changed-tags'] ); 23 29 } 24 30 … … 47 53 } 48 54 49 $plugin_slug = $opts['plugin']; 55 $plugin_slug = $opts['plugin']; 56 $changed_tags = $opts['changed-tags']; 57 $start_time = microtime(1); 50 58 51 59 echo "Processing Import for $plugin_slug... "; 52 60 try { 53 61 $importer = new CLI\Import; 54 $importer->import_from_svn( $plugin_slug );55 echo "OK \n";62 $importer->import_from_svn( $plugin_slug, $changed_tags ); 63 echo "OK. Took " . round( microtime(1) - $start_time, 2 ) . "s\n"; 56 64 } catch( \Exception $e ) { 57 echo "Failed.\n"; 65 echo "Failed. Took " . round( microtime(1) - $start_time, 2 ) . "s\n"; 66 58 67 fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" ); 59 68 exit(1); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r3357 r3373 23 23 'tested', 24 24 'requires', 25 'stable_tag',26 25 'donate_link', 27 26 'upgrade_notice', … … 46 45 * @throws \Exception 47 46 * 48 * @param string $plugin_slug The slug of the plugin to import. 49 */ 50 public function import_from_svn( $plugin_slug ) { 47 * @param string $plugin_slug The slug of the plugin to import. 48 * @param array $svn_changed_tags A list of tags/trunk which the SVN change touched. Optional. 49 */ 50 public function import_from_svn( $plugin_slug, $svn_changed_tags = array( 'trunk' ) ) { 51 51 global $wpdb; 52 52 … … 152 152 } 153 153 154 if ( 'stable_tag' == $readme_field ) { 155 // The stable_tag needs to come from the trunk readme at all times. 156 $value = $stable_tag; 157 } else { 158 $value = $readme->$readme_field; 159 } 160 161 update_post_meta( $plugin->ID, $readme_field, wp_slash( $value ) ); 154 update_post_meta( $plugin->ID, $readme_field, wp_slash( $readme->$readme_field ) ); 162 155 } 163 156 … … 190 183 } 191 184 } 185 186 $current_stable_tag = get_post_meta( $plugin->ID, 'stable_tag', true ); 187 188 $this->rebuild_invalidate_zips( $plugin_slug, $stable_tag, $current_stable_tag, $svn_changed_tags ); 189 190 // Finally, set the new version live. 191 update_post_meta( $plugin->ID, 'stable_tag', $stable_tag ); 192 } 193 194 /** 195 * Rebuild and Invalidate plugin ZIPs on all web nodes using the REST API Endpoints. 196 * 197 * @param string $plugin_slug The plugin slug. 198 * @param string $stable_tag The new stable tag. 199 * @param string $current_stable_tag The new stable tag. 200 * @param array $svn_changed_tags The list of SVN tags modified since last import. 201 */ 202 protected function rebuild_invalidate_zips( $plugin_slug, $stable_tag, $current_stable_tag, $svn_changed_tags ) { 203 global $wporg_webs; 204 $invalidate_zips = $rebuild_zips = array(); 205 206 foreach ( $svn_changed_tags as $tag ) { 207 if ( 'trunk' == $tag ) { 208 if ( 'trunk' == $stable_tag ) { 209 // Trunk is stable, so we'll need to rebuild the zip 210 $rebuild_zips[] = "{$plugin_slug}.zip"; 211 } else { 212 // Trunk isn't stable, so we'll just remove it so it's rebuilt on demand 213 $invalidate_zips[] = "{$plugin_slug}.zip"; 214 } 215 continue; 216 } 217 if ( $tag == $stable_tag || $tag == $current_stable_tag ) { 218 $rebuild_zips[] = "{$plugin_slug}.{$tag}.zip"; 219 } else { 220 $invalidate_zips[] = "{$plugin_slug}.{$tag}.zip"; 221 } 222 } 223 if ( $stable_tag != $current_stable_tag ) { 224 // plugin is updated, ensure that everything is rebuilt. 225 if ( ! in_array( $stable_tag, $svn_changed_tags ) ) { 226 $rebuild_zips[] = "{$plugin_slug}" . ( 'trunk' == $tag ? '' : ".{$stable_tag}" ) . '.zip'; 227 } 228 } 229 230 if ( empty( $wporg_webs ) || ( empty( $invalidate_zips ) && empty( $rebuild_zips ) ) ) { 231 return; 232 } 233 234 $urls = array(); 235 foreach ( $wporg_webs as $node ) { 236 $urls[] = preg_replace( '!^https?://wordpress.org/!', "http://$node/", site_url( '/wp-json/plugins/v1/zip-management' ) ); 237 } 238 $headers = array( 239 'User-Agent' => 'WordPress.org Plugin Directory', 240 'Host' => 'WordPress.org', 241 'Authorization' => 'BEARER ' . PLUGIN_API_INTERNAL_BEARER_TOKEN, 242 ); 243 $body = array( 244 'plugins' => array( 245 $plugin_slug => array( 246 'invalidate' => $invalidate_zips, 247 'rebuild' => $rebuild_zips, 248 ) 249 ) 250 ); 251 252 $results = array(); 253 foreach ( $urls as $url ) { 254 $results[ $url ] = wp_remote_post( $url, array( 255 'body' => $body, 256 'headers' => $headers, 257 'sslverify' => false 258 ) ); 259 } 260 261 // TODO Do something with $results to verify all servers said the rebuilt zip was correct or something. 192 262 } 193 263
Note: See TracChangeset
for help on using the changeset viewer.