Changeset 13683 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/upgrade.php
- Timestamp:
- 05/09/2024 08:33:51 AM (19 months ago)
- 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 2 2 3 3 namespace Wporg\TranslationEvents; 4 5 use Exception;6 use WP_Query;7 use Wporg\TranslationEvents\Attendee\Attendee;8 use Wporg\TranslationEvents\Stats\Stats_Calculator;9 4 10 5 class Upgrade { … … 28 23 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 29 24 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_log38 error_log( $e );39 }40 }41 25 42 26 update_option( self::VERSION_OPTION, self::VERSION ); … … 70 54 "; 71 55 } 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 Exception80 */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 }106 56 }
Note: See TracChangeset
for help on using the changeset viewer.