Making WordPress.org

Changeset 13711


Ignore:
Timestamp:
05/16/2024 03:06:24 AM (8 months ago)
Author:
dd32
Message:

Plugin Direcrory: When Release Confirmation is enabled, and a tag for a non-confirmed release is deleted, remove the release.

Fixes #5900.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r13674 r13711  
    17841784    /**
    17851785     * Fetch a specific release of the plugin, by tag.
     1786     *
     1787     * @param string $plugin Plugin slug.
     1788     * @param string $tag    Release tag.
     1789     * @return array|bool
    17861790     */
    17871791    public static function get_release( $plugin, $tag ) {
     
    17991803    /**
    18001804     * Add a Plugin Release to the internal storage.
     1805     *
     1806     * @param string $plugin Plugin slug.
     1807     * @param array  $data   Release data.
     1808     * @return bool
    18011809     */
    18021810    public static function add_release( $plugin, $data ) {
     
    18441852
    18451853        return update_post_meta( $plugin->ID, 'releases', $releases );
     1854    }
     1855
     1856    /**
     1857     * Remove a Plugin Release from the internal storage.
     1858     *
     1859     * @param string $plugin Plugin slug.
     1860     * @param string $tag    Release tag.
     1861     * @return bool
     1862     */
     1863    public static function remove_release( $plugin, $tag ) {
     1864        $result   = false;
     1865        $plugin   = self::get_plugin_post( $plugin );
     1866        $releases = self::get_releases( $plugin );
     1867
     1868        // Remove the release in question.
     1869        foreach ( $releases as $i => $r ) {
     1870            if ( $r['tag'] === $tag && ! $r['confirmed'] ) {
     1871                unset( $releases[ $i ] );
     1872
     1873                $result = update_post_meta( $plugin->ID, 'releases', $releases );
     1874            }
     1875        }
     1876
     1877        return $result;
    18461878    }
    18471879
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r13637 r13711  
    7878     * @param string $plugin_slug            The slug of the plugin to import.
    7979     * @param array  $svn_changed_tags       A list of tags/trunk which the SVN change touched. Optional.
     80     * @param array  $svn_tags_deleted       A list of tags/trunk which were deleted in the SVN change. Optional.
    8081     * @param array  $svn_revision_triggered The SVN revision which this import has been triggered by. Optional.
    8182     */
    82     public function import_from_svn( $plugin_slug, $svn_changed_tags = array( 'trunk' ), $svn_revision_triggered = 0 ) {
     83    public function import_from_svn( $plugin_slug, $svn_changed_tags = array( 'trunk' ), $svn_tags_deleted = array(), $svn_revision_triggered = 0 ) {
    8384        // Reset properties.
    8485        $this->warnings = [];
     
    192193
    193194                    echo "Plugin release {$svn_changed_tag} not confirmed; email triggered.\n";
     195                }
     196            }
     197
     198            // Check to see if any of the releases were deleted.
     199            foreach ( $svn_tags_deleted as $svn_deleted_tag ) {
     200                // Note: Confirmed releases will not be deleted, only unconfirmed ones.
     201                if ( Plugin_Directory::remove_release( $plugin, $svn_deleted_tag ) ) {
     202                    echo "Plugin tag {$svn_deleted_tag} deleted; release removed.\n";
    194203                }
    195204            }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-import.php

    r13234 r13711  
    1414    public static function queue( $plugin_slug, $plugin_data ) {
    1515        // To avoid a situation where two imports run concurrently, if one is already scheduled, run it 1hr later (We'll trigger it after the current one finishes).
    16         $when_to_run = time() + 10;
     16        $when_to_run = time() + 5;
    1717        if ( $next_scheduled = Manager::get_scheduled_time( "import_plugin:{$plugin_slug}", 'last' ) ) {
    1818            $when_to_run = $next_scheduled + HOUR_IN_SECONDS;
     
    3636        // Set some default values if not included from the caller.
    3737        $plugin_data['tags_touched']   ??= array( 'trunk' );
     38        $plugin_data['tags_deleted']   ??= array();
    3839        $plugin_data['revisions']      ??= [ 0 ];
    3940        $plugin_data['readme_touched'] ??= true;
     
    4243
    4344        $tags_touched = $plugin_data['tags_touched'];
     45        $tags_deleted = $plugin_data['tags_deleted'];
    4446        $revision     = max( (array) $plugin_data['revisions'] );
    4547
    4648        $importer = new CLI\Import();
    4749        try {
    48             $importer->import_from_svn( $plugin_slug, $tags_touched, $revision );
     50            $importer->import_from_svn( $plugin_slug, $tags_touched, $tags_deleted, $revision );
    4951        } catch ( Exception $e ) {
    5052            fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" );
Note: See TracChangeset for help on using the changeset viewer.