Making WordPress.org

Changeset 13234


Ignore:
Timestamp:
02/22/2024 05:30:26 AM (10 months ago)
Author:
dd32
Message:

Plugin Directory: Store errors encountered during the plugin import process.

See #6921, #6108.

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  
    88use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    99use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation as Release_Confirmation_Email;
    10 use WordPressdotorg\Plugin_Directory\Readme\Parser;
     10use WordPressdotorg\Plugin_Directory\Readme\{ Parser as Readme_Parser, Validator as Readme_Validator };
    1111use WordPressdotorg\Plugin_Directory\Standalone\Plugins_Info_API;
    1212use WordPressdotorg\Plugin_Directory\Template;
     
    5858
    5959    /**
     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    /**
    6074     * Process an import for a Plugin into the Plugin Directory.
    6175     *
     
    6781     */
    6882    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 );
    7087        if ( ! $plugin ) {
    7188            throw new Exception( 'Unknown Plugin' );
     
    87104        $touches_stable_tag = (bool) array_intersect( [ $stable_tag, $current_stable_tag ], $svn_changed_tags );
    88105
     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
    89118        // Validate various headers:
    90119
     
    99128            $update_uri_valid = preg_match( '!^(https?://)?(wordpress.org|w.org)/plugins?/(?P<slug>[^/]+)/?$!i', $headers->UpdateURI, $update_uri_matches );
    100129            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'] );
    102133            }
    103134        }
     
    122153
    123154        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'] );
    125158        }
    126159        unset( $_requires_plugins, $unmet_dependencies );
     
    412445         * @param array   $changed_tags   The list of SVN tags/trunk affected to trigger the import.
    413446         * @param int     $svn_revision   The SVN revision that triggered the import.
     447         * @param array   $warnings       The list of warnings generated during the import process.
    414448         */
    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 );
    416450
    417451        return true;
     
    564598
    565599            $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 );
    567601
    568602            $stable_tag = $trunk_readme->stable_tag;
     
    624658        // The readme may not actually exist, but that's okay.
    625659        $readme = $this->find_readme_file( $tmp_dir . '/export' );
    626         $readme = new Parser( $readme );
     660        $readme = new Readme_Parser( $readme );
    627661
    628662        // 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  
    4444        $revision     = max( (array) $plugin_data['revisions'] );
    4545
     46        $importer = new CLI\Import();
    4647        try {
    47             $importer = new CLI\Import();
    4848            $importer->import_from_svn( $plugin_slug, $tags_touched, $revision );
    4949        } catch ( Exception $e ) {
    5050            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            }
    5156        }
    5257
Note: See TracChangeset for help on using the changeset viewer.