Making WordPress.org


Ignore:
Timestamp:
05/09/2024 08:33:51 AM (19 months ago)
Author:
amieiro
Message:

Translate: Sync "Translation Events" from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/upgrade.php

    r13541 r13683  
    22
    33namespace Wporg\TranslationEvents;
    4 
    5 use Exception;
    6 use WP_Query;
    7 use Wporg\TranslationEvents\Attendee\Attendee;
    8 use Wporg\TranslationEvents\Stats\Stats_Calculator;
    94
    105class Upgrade {
     
    2823        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    2924        dbDelta( self::get_database_schema_sql() );
    30 
    31         // Run version-specific upgrades.
    32         $is_running_tests = 'yes' === getenv( 'WPORG_TRANSLATION_EVENTS_TESTS' );
    33         if ( $previous_version < 2 && ! $is_running_tests ) {
    34             try {
    35                 self::v2_import_legacy_attendees();
    36             } catch ( Exception $e ) {
    37                 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
    38                 error_log( $e );
    39             }
    40         }
    4125
    4226        update_option( self::VERSION_OPTION, self::VERSION );
     
    7054        ";
    7155    }
    72 
    73     /**
    74      * Previously, event attendance was tracked through user_meta.
    75      * This function imports this legacy attendance information into the attendees table.
    76      *
    77      * Instead of looping through all users, we consider only users who have contributed to an event.
    78      *
    79      * @throws Exception
    80      */
    81     private static function v2_import_legacy_attendees(): void {
    82         $query = new WP_Query(
    83             array(
    84                 'post_type'   => Translation_Events::CPT,
    85                 'post_status' => 'publish',
    86             )
    87         );
    88 
    89         $events              = $query->get_posts();
    90         $stats_calculator    = new Stats_Calculator();
    91         $attendee_repository = Translation_Events::get_attendee_repository();
    92         foreach ( $events as $event ) {
    93             $host_attendee = new Attendee( $event->ID, intval( $event->post_author ) );
    94             $host_attendee->mark_as_host();
    95             $attendee_repository->insert_attendee( $host_attendee );
    96 
    97             foreach ( $stats_calculator->get_contributors( $event->ID ) as $user ) {
    98                 $attendee = $attendee_repository->get_attendee( $event->ID, $user->id );
    99                 if ( ! $attendee ) {
    100                     $attendee = new Attendee( $event->ID, $user->ID );
    101                     $attendee_repository->insert_attendee( $attendee );
    102                 }
    103             }
    104         }
    105     }
    10656}
Note: See TracChangeset for help on using the changeset viewer.