Changeset 13739 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/upgrade.php
- Timestamp:
- 05/21/2024 11:43:05 AM (20 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
r13683 r13739 3 3 namespace Wporg\TranslationEvents; 4 4 5 use Exception; 6 use WP_Query; 7 5 8 class Upgrade { 6 private const VERSION = 2;9 private const VERSION = 3; 7 10 private const VERSION_OPTION = 'wporg_gp_translations_events_version'; 8 11 … … 23 26 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 24 27 dbDelta( self::get_database_schema_sql() ); 28 29 // Run version-specific upgrades. 30 $is_running_tests = 'yes' === getenv( 'WPORG_TRANSLATION_EVENTS_TESTS' ); 31 if ( $previous_version < 3 && ! $is_running_tests ) { 32 try { 33 self::v3_set_is_new_contributor(); 34 } catch ( Exception $e ) { 35 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log 36 error_log( $e ); 37 } 38 } 25 39 26 40 update_option( self::VERSION_OPTION, self::VERSION ); … … 48 62 `user_id` int(10) NOT NULL COMMENT 'ID of the user who is attending the event', 49 63 `is_host` tinyint(1) default 0 not null comment 'Whether the user is a host of the event', 64 `is_new_contributor` tinyint(1) default 0 not null comment 'Whether the user is a new translation contributor', 50 65 PRIMARY KEY (`translate_event_attendees_id`), 51 66 UNIQUE KEY `event_per_user` (`event_id`,`user_id`), … … 54 69 "; 55 70 } 71 72 /** 73 * Set is_new_contributor in attendees table for all events. 74 */ 75 private static function v3_set_is_new_contributor(): void { 76 global $wpdb, $gp_table_prefix; 77 78 $query = new WP_Query( 79 array( 80 'post_type' => Translation_Events::CPT, 81 'post_status' => 'publish', 82 ) 83 ); 84 85 $events = $query->get_posts(); 86 $event_repository = Translation_Events::get_event_repository(); 87 $attendee_repository = Translation_Events::get_attendee_repository(); 88 89 foreach ( $events as $post ) { 90 $event = $event_repository->get_event( $post->ID ); 91 if ( ! $event ) { 92 continue; 93 } 94 95 $attendees = $attendee_repository->get_attendees( $event->id() ); 96 97 foreach ( $attendees as $attendee ) { 98 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared 99 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery 100 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching 101 $translation_count = $wpdb->get_var( 102 $wpdb->prepare( 103 " 104 select count(*) as cnt 105 from {$gp_table_prefix}translations 106 where user_id = %d 107 and date_added < %s 108 ", 109 array( 110 $attendee->user_id(), 111 $event->start()->format( 'Y-m-d H:i:s' ), 112 ), 113 ) 114 ); 115 116 if ( $translation_count > 10 ) { 117 // Not a new contributor. 118 continue; 119 } 120 121 $wpdb->update( 122 "{$gp_table_prefix}event_attendees", 123 array( 'is_new_contributor' => 1 ), 124 array( 125 'event_id' => $attendee->event_id(), 126 'user_id' => $attendee->user_id(), 127 ) 128 ); 129 // phpcs:enable 130 } 131 } 132 } 56 133 }
Note: See TracChangeset
for help on using the changeset viewer.