Changeset 3057
- Timestamp:
- 05/02/2016 02:32:40 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/sync/class-translation-sync.php
r3046 r3057 31 31 * Starts the sync of plugin translations between two projects. 32 32 * 33 * Gets trigge d by the cron API and the hook `sync_plugin_translations`.33 * Gets triggered by the cron API and the hook `sync_plugin_translations`. 34 34 * 35 35 * @param array $args Arguments from the job. Should include the path -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/class-plugin.php
r3056 r3057 41 41 */ 42 42 public function plugins_loaded() { 43 add_action( 'wporg_translate_import_or_update_theme', array( $this, 'import_or_update_theme_on_status_change' ) ); 44 43 45 if ( defined( 'WP_CLI' ) && WP_CLI ) { 44 46 $this->register_cli_commands(); … … 47 49 48 50 /** 51 * Starts the import of a theme. 52 * 53 * Gets triggered by the cron API and the hook `wporg_translate_import_or_update_theme`. 54 * 55 * @param array $args Arguments from the job. Should include the slug and the version 56 * of the theme. 57 * @return bool False on failure, true on success. 58 */ 59 public function import_or_update_theme_on_status_change( $args ) { 60 $time = date( 'r' ); 61 $message = "_Time: {$time}_\nImport of theme {$args['theme']} {$args['version']} in process...\n"; 62 63 // Import in a separate process. 64 $cmd = WPORGTRANSLATE_WPCLI . ' wporg-translate set-theme-project ' . escapeshellarg( $args['theme'] ) . ' ' . escapeshellarg( $args['version'] ); 65 $output = ''; 66 $return_var = 0; 67 exec( $cmd, $output, $return_var ); 68 if ( $return_var ) { 69 $message .= "\tFailure: " . implode( "\n\t", $output ) . "\n"; 70 } else { 71 $message .= "\t" . implode( "\n\t", $output ) . "\n"; 72 $message .= 'Import was successfully processed.'; 73 } 74 75 $attachment = [ 76 'title' => "Import of {$args['theme']}", 77 'title_link' => "https://translate.wordpress.org/projects/wp-themes/{$args['theme']}", 78 'text' => $message, 79 'fallback' => "Theme {$args['theme']} was imported.", 80 'color' => '#82878c', 81 'mrkdwn_in' => [ 'text' ], 82 ]; 83 $this->slack( $attachment ); 84 85 return true; 86 } 87 88 /** 49 89 * Registers CLI commands if WP-CLI is loaded. 50 90 */ 51 function register_cli_commands() {91 public function register_cli_commands() { 52 92 WP_CLI::add_command( 'wporg-translate set-theme-project', __NAMESPACE__ . '\CLI\Set_Theme_Project' ); 53 93 } 94 95 /** 96 * Sends a notifcation to the the Slack channel. 97 * 98 * @param array $attachment The attachment of a notification. 99 */ 100 private function slack( $attachment ) { 101 if ( ! defined( 'GLOTPRESS_SLACK_WEBHOOK' ) ) { 102 return; 103 } 104 105 require_once API_WPORGPATH . 'includes/slack-config.php'; 106 $send = new \Dotorg\Slack\Send( GLOTPRESS_SLACK_WEBHOOK ); 107 $send->add_attachment( $attachment ); 108 $send->set_username( 'Theme Imports' ); 109 $send->send( '#meta-language-packs' ); 110 } 54 111 }
Note: See TracChangeset
for help on using the changeset viewer.