Changeset 13234
- Timestamp:
- 02/22/2024 05:30:26 AM (10 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r13233 r13234 8 8 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 9 9 use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation as Release_Confirmation_Email; 10 use WordPressdotorg\Plugin_Directory\Readme\ Parser;10 use WordPressdotorg\Plugin_Directory\Readme\{ Parser as Readme_Parser, Validator as Readme_Validator }; 11 11 use WordPressdotorg\Plugin_Directory\Standalone\Plugins_Info_API; 12 12 use WordPressdotorg\Plugin_Directory\Template; … … 58 58 59 59 /** 60 * List of warnings generated during the import process. 61 * 62 * @var array 63 */ 64 public $warnings = array(); 65 66 /** 67 * The last plugin imported. 68 * 69 * @var \WP_Post 70 */ 71 public $plugin; 72 73 /** 60 74 * Process an import for a Plugin into the Plugin Directory. 61 75 * … … 67 81 */ 68 82 public function import_from_svn( $plugin_slug, $svn_changed_tags = array( 'trunk' ), $svn_revision_triggered = 0 ) { 69 $plugin = Plugin_Directory::get_plugin_post( $plugin_slug ); 83 // Reset properties. 84 $this->warnings = []; 85 86 $plugin = $this->plugin = Plugin_Directory::get_plugin_post( $plugin_slug ); 70 87 if ( ! $plugin ) { 71 88 throw new Exception( 'Unknown Plugin' ); … … 87 104 $touches_stable_tag = (bool) array_intersect( [ $stable_tag, $current_stable_tag ], $svn_changed_tags ); 88 105 106 // If the readme generated any warnings, raise it to self::$import_warnings; 107 if ( $readme->warnings ) { 108 // Convert the warnings to a human readable format. 109 $readme_warnings = Readme_Validator::instance()->validate_content( $readme->raw_contents ); 110 111 foreach ( [ 'errors', 'warnings' ] as $field ) { 112 foreach ( $readme_warnings[ $field ] ?? [] as $warning ) { 113 $this->warnings[] = "Readme: {$warning}"; 114 } 115 } 116 } 117 89 118 // Validate various headers: 90 119 … … 99 128 $update_uri_valid = preg_match( '!^(https?://)?(wordpress.org|w.org)/plugins?/(?P<slug>[^/]+)/?$!i', $headers->UpdateURI, $update_uri_matches ); 100 129 if ( ! $update_uri_valid || $update_uri_matches['slug'] !== $plugin_slug ) { 101 throw new Exception( 'Invalid Update URI header detected: ' . $headers->UpdateURI ); 130 $this->warnings['invalid_update_uri'] = 'Invalid Update URI header detected: ' . $headers->UpdateURI; 131 132 throw new Exception( $this->warnings['invalid_update_uri'] ); 102 133 } 103 134 } … … 122 153 123 154 if ( $unmet_dependencies ) { 124 throw new Exception( 'Invalid plugin dependencies specified. The following dependencies could not be resolved: ' . implode( ', ', $requires_plugins_unmet ) ); 155 $this->warnings['unmet_dependencies'] = 'Invalid plugin dependencies specified. The following dependencies could not be resolved: ' . implode( ', ', $requires_plugins_unmet ); 156 157 throw new Exception( $this->warnings['unmet_dependencies'] ); 125 158 } 126 159 unset( $_requires_plugins, $unmet_dependencies ); … … 412 445 * @param array $changed_tags The list of SVN tags/trunk affected to trigger the import. 413 446 * @param int $svn_revision The SVN revision that triggered the import. 447 * @param array $warnings The list of warnings generated during the import process. 414 448 */ 415 do_action( 'wporg_plugins_imported', $plugin, $stable_tag, $current_stable_tag, $svn_changed_tags, $svn_revision_triggered );449 do_action( 'wporg_plugins_imported', $plugin, $stable_tag, $current_stable_tag, $svn_changed_tags, $svn_revision_triggered, $this->warnings ); 416 450 417 451 return true; … … 564 598 565 599 $trunk_readme_file = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk/{$trunk_readme_file}"; 566 $trunk_readme = new Parser( $trunk_readme_file );600 $trunk_readme = new Readme_Parser( $trunk_readme_file ); 567 601 568 602 $stable_tag = $trunk_readme->stable_tag; … … 624 658 // The readme may not actually exist, but that's okay. 625 659 $readme = $this->find_readme_file( $tmp_dir . '/export' ); 626 $readme = new Parser( $readme );660 $readme = new Readme_Parser( $readme ); 627 661 628 662 // There must be valid plugin headers though. -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-import.php
r12606 r13234 44 44 $revision = max( (array) $plugin_data['revisions'] ); 45 45 46 $importer = new CLI\Import(); 46 47 try { 47 $importer = new CLI\Import();48 48 $importer->import_from_svn( $plugin_slug, $tags_touched, $revision ); 49 49 } catch ( Exception $e ) { 50 50 fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" ); 51 } finally { 52 if ( $importer->plugin ) { 53 update_post_meta( $importer->plugin->ID, '_last_import', time() ); 54 update_post_meta( $importer->plugin->ID, '_import_warnings', $importer->warnings ); 55 } 51 56 } 52 57
Note: See TracChangeset
for help on using the changeset viewer.