Changeset 7895
- Timestamp:
- 11/24/2018 03:13:59 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/cli/class-set-theme-project.php
r7338 r7895 3 3 namespace WordPressdotorg\GlotPress\Theme_Directory\CLI; 4 4 5 use Exception; 5 6 use GP; 6 7 use MakePOT; … … 25 26 private $temp_dir; 26 27 27 /**28 * MakePot instance.29 *30 * @var MakePot31 */32 private $makepot;33 34 28 public function __construct() { 35 29 if ( ! file_exists( '/tmp/wporg-themes-i18n/' ) ) { … … 42 36 WP_CLI::error( "Couldn't create temporary directory." ); 43 37 } 44 45 $this->checkout_tools();46 if ( ! file_exists( $this->temp_dir . '/i18n-tools/makepot.php' ) ) {47 WP_CLI::error( "Couldn't find MakePot." );48 }49 require_once $this->temp_dir . '/i18n-tools/makepot.php';50 $this->makepot = new MakePot();51 38 } 52 39 … … 82 69 83 70 $project = $this->find_create_update_glotpress_project( $theme_slug, $theme_data ); 84 $pot = $this->generate_pot( $theme_slug, $theme_dir ); 71 72 try { 73 $pot = $this->generate_pot( $theme_slug, $theme_dir ); 74 } catch ( Exception $exception ) { 75 $this->cleanup_theme( $theme_slug ); 76 WP_CLI::error( "{$theme_slug} {$theme_version} not imported: " . $exception->getMessage() ); 77 } 78 85 79 $this->import_pot_to_glotpress( $pot, $project ); 86 80 … … 157 151 */ 158 152 private function generate_pot( $theme_slug, $theme_dir ) { 153 if ( ! defined( 'WPORGTRANSLATE_WPCLI' ) ) { 154 throw new Exception( 'Missing configuration for WPORGTRANSLATE_WPCLI.' ); 155 } 156 159 157 $pot_file = "{$this->temp_dir}/{$theme_slug}.pot"; 160 $this->makepot->wp_theme( $theme_dir, $pot_file ); 158 159 $cmd = sprintf( 160 '%s i18n make-pot %s %s --slug=%s --ignore-domain --skip-audit', 161 WPORGTRANSLATE_WPCLI, 162 escapeshellarg( $theme_dir ), 163 escapeshellarg( $pot_file ), 164 escapeshellarg( $theme_slug ) 165 ); 166 167 exec( $cmd, $output, $return_code ); 168 169 if ( 0 !== $return_code || ! file_exists( $pot_file ) ) { 170 throw new Exception( "POT file couldn't be created." ); 171 } 172 161 173 return $pot_file; 162 174 } … … 178 190 'description' => $theme_data['description'] . "<br><br><a href='https://wordpress.org/themes/{$theme_slug}'>WordPress.org Theme Page</a>", 179 191 'parent_project_id' => $parent_project->id, 180 'source_url_template' => "https://themes.trac.wordpress.org/browser/$theme_slug/{$theme_data['version']}/%file% #L%line%",192 'source_url_template' => "https://themes.trac.wordpress.org/browser/$theme_slug/{$theme_data['version']}/%file%?marks=%line%#L%line%", 181 193 'active' => 1, 182 194 ); … … 290 302 $priorities = array( 291 303 // These are important strings that we need translated 292 'Plugin Name of the plugin/theme' => 1, 293 'Theme Name of the plugin/theme' => 1, 294 'Description of the plugin/theme' => 1, 304 'Theme Name of the theme' => 1, 305 'Description of the theme' => 1, 295 306 // Regular strings are more important than these: 296 'Plugin URI of the plugin/theme' => -1, 297 'Theme URI of the plugin/theme' => -1, 298 'Author of the plugin/theme' => -1, 299 'Author URI of the plugin/theme' => -1, 307 'Theme URI of the theme' => -1, 308 'Author of the theme' => -1, 309 'Author URI of the theme' => -1, 300 310 ); 311 301 312 if ( isset( $priorities[ $data['comment'] ] ) ) { 302 313 $data['priority'] = $priorities[ $data['comment'] ]; 303 } 314 } else { 315 $data['priority'] = 0; 316 } 317 304 318 return $data; 305 }306 307 /**308 * Creates an i18n-tools checkout so we have MakePot available.309 */310 private function checkout_tools() {311 $tools_dir = "{$this->temp_dir}/i18n-tools/";312 if ( ! file_exists( $tools_dir ) ) {313 $esc_tools_dir = escapeshellarg( $tools_dir );314 `svn export --non-interactive https://i18n.svn.wordpress.org/tools/trunk {$esc_tools_dir}`;315 }316 319 } 317 320
Note: See TracChangeset
for help on using the changeset viewer.