Changeset 5446 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin-to-glotpress.php
- Timestamp:
- 04/30/2017 04:20:16 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin-to-glotpress.php
r5435 r5446 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory; 3 4 use Exception; 5 use WordPressdotorg\Plugin_Directory\Clients\Slack; 3 6 4 7 // This script should only be called in a CLI environment. … … 7 10 } 8 11 9 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'tag:', 'type:' ) );12 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'tag:', 'type:', 'no-slack' ) ); 10 13 11 14 // Guess the default parameters: … … 30 33 } 31 34 35 if ( ! in_array( $opts['type'], [ 'code', 'readme' ] ) ) { 36 fwrite( STDERR, "Invalid value for type argument: {$opts['type']}\n" ); 37 die(); 38 } 39 32 40 // Bootstrap WordPress 33 41 $_SERVER['HTTP_HOST'] = parse_url( $opts['url'], PHP_URL_HOST ); … … 50 58 $start_time = microtime( 1 ); 51 59 60 $plugin = Plugin_Directory::get_plugin_post( $plugin_slug ); 61 if ( ! $plugin ) { 62 fwrite( STDERR, "[{$plugin_slug}] Plugin I18N Import Failed: Plugin doesn't exist.\n" ); 63 exit( 1 ); 64 } 65 66 // Prepare Slack notification. 67 $send_slack = defined( 'PLUGIN_IMPORTS_SLACK_WEBHOOK' ) && ! isset( $opts['no-slack'] ); 68 if ( $send_slack ) { 69 $slack_client = new Slack( PLUGIN_IMPORTS_SLACK_WEBHOOK ); 70 $slack_client->add_attachment( 'ts', time() ); 71 $slack_client->add_attachment( 'fallback', "{$plugin->post_title} has been imported." ); 72 $slack_client->add_attachment( 'title', "{$plugin->post_title} has been imported" ); 73 $slack_client->add_attachment( 'title_link', "https://translate.wordpress.org/projects/wp-plugins/{$plugin_slug}" ); 74 $fields = [ 75 [ 76 'title' => 'Type', 77 'value' => ( 'readme' === $type ) ? 'Readme' : 'Code', 78 'short' => true, 79 ], 80 [ 81 'title' => 'Version', 82 'value' => $tag, 83 'short' => true, 84 ], 85 ]; 86 } 87 52 88 echo "Processing I18N Import for $plugin_slug...\n"; 53 89 try { … … 60 96 } 61 97 62 echo "OK. Took " . round( microtime(1) - $start_time, 2 ) . "s\n"; 63 } catch( \Exception $e ) { 64 echo "Failed. Took " . round( microtime(1) - $start_time, 2 ) . "s\n"; 98 $runtime = round( microtime( 1 ) - $start_time, 2 ); 99 100 // Send Slack notification. 101 if ( $send_slack ) { 102 $fields[] = [ 103 'title' => 'Status', 104 'value' => sprintf( '%s Successfully imported! (%ss)', $slack_client->get_success_emoji(), $runtime ), 105 'short' => false, 106 ]; 107 $fields[] = [ 108 'title' => 'Plugin', 109 'value' => sprintf( 110 '<%1$s|%2$s> | <https://plugins.trac.wordpress.org/log/%3$s|Log> | <%4$s|SVN>', 111 get_permalink( $plugin ), 112 $plugin->post_title, 113 $plugin_slug, 114 $importer->get_plugin_svn_url( $tag ) 115 ), 116 'short' => false, 117 ]; 118 $slack_client->add_attachment( 'fields', $fields ); 119 $slack_client->set_status( 'success' ); 120 $slack_client->send( '#meta-language-packs' ); 121 } 122 123 echo "OK. Took {$runtime}s\n"; 124 } catch ( Exception $e ) { 125 $runtime = round( microtime( 1 ) - $start_time, 2 ); 126 127 // Send Slack notification. 128 if ( $send_slack ) { 129 $fields[] = [ 130 'title' => 'Status', 131 'value' => sprintf( '%s %s (%ss)', $slack_client->get_failure_emoji(), $e->getMessage(), $runtime ), 132 'short' => false, 133 ]; 134 $fields[] = [ 135 'title' => 'Plugin', 136 'value' => sprintf( 137 '<%1$s|%2$s> | <https://plugins.trac.wordpress.org/log/%3$s|Log> | <%4$s|SVN>', 138 get_permalink( $plugin ), 139 $plugin->post_title, 140 $plugin_slug, 141 $importer->get_plugin_svn_url( $tag ) 142 ), 143 'short' => false, 144 ]; 145 $slack_client->add_attachment( 'fields', $fields ); 146 $slack_client->set_status( 'failure' ); 147 $slack_client->send( '#meta-language-packs' ); 148 } 149 150 echo "Failed. Took {$runtime}s\n"; 65 151 66 152 fwrite( STDERR, "[{$plugin_slug}] Plugin I18N Import Failed: " . $e->getMessage() . "\n" ); 67 exit( 1);153 exit( 2 ); 68 154 }
Note: See TracChangeset
for help on using the changeset viewer.