Changeset 9724
- Timestamp:
- 04/15/2020 03:02:45 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-stats/stats/user.php
r9709 r9724 60 60 } 61 61 62 $this->user_project_stats[ "{$translation->user_id},{$project->id},{$translation_set->locale},{$translation_set->slug}" ] = true; 62 $key = "{$translation->user_id},{$project->id},{$translation_set->locale},{$translation_set->slug}"; 63 if ( ! isset( $this->user_project_stats[ $key ] ) ) { 64 $this->user_project_stats[ $key ] = 0; 65 } 66 $this->user_project_stats[ $key ]++; 63 67 } 64 68 } … … 117 121 } 118 122 119 // Process the project stats too.123 // Process the user project stats too. 120 124 $values = []; 121 foreach ( $this->user_project_stats as $key => $ dummy) {125 foreach ( $this->user_project_stats as $key => $string_count ) { 122 126 list( $user_id, $project_id, $locale, $locale_slug ) = explode( ',', $key ); 123 127 124 $values[] = $wpdb->prepare( '(%d, %d, %s, %s, %s)', 125 $user_id, 126 $project_id, 127 $locale, 128 $locale_slug, 129 $now 130 ); 131 132 if ( count( $values ) > 50 ) { 133 $wpdb->query( 134 "INSERT INTO {$wpdb->user_projects} (`user_id`, `project_id`, `locale`, `locale_slug`, `last_modified`) 135 VALUES " . implode( ', ', $values ) . " 136 ON DUPLICATE KEY UPDATE `last_modified` = GREATEST( `last_modified`, VALUES(`last_modified`) )" 137 ); 138 $values = []; 139 } 140 } 141 if ( $values ) { 142 $wpdb->query( 143 "INSERT INTO {$wpdb->user_projects} (`user_id`, `project_id`, `locale`, `locale_slug`, `last_modified`) 144 VALUES " . implode( ', ', $values ) . " 145 ON DUPLICATE KEY UPDATE `last_modified` = GREATEST( `last_modified`, VALUES(`last_modified`) )" 146 ); 147 $values = []; 128 // Step 1 - Does this user already have the project listed? Just Bump the date. 129 if ( $id = $wpdb->get_var( $wpdb->prepare( 130 "SELECT id FROM {$wpdb->user_projects} 131 WHERE user_id = %d AND project_id = %d AND locale = %s AND locale_slug = %s", 132 $user_id, $project_id, $locale, $locale_slug 133 ) ) ) { 134 $wpdb->update( 135 $wpdb->user_projects, 136 [ 'last_modified' => $now ], 137 [ 'id' => $id ] 138 ); 139 continue; 140 } 141 142 // Step 2 - More than 5 strings? Import Maybe? Just insert. 143 if ( $string_count >= 5 ) { 144 $wpdb->insert( 145 $wpdb->user_projects, 146 [ 147 'user_id' => $user_id, 148 'project_id' => $project_id, 149 'locale' => $locale, 150 'locale_slug' => $locale_slug, 151 'last_modified' => $now 152 ] 153 ); 154 continue; 155 } 156 157 // Step 3 - If not, find all the sub-project IDs, then all the translation sets, count strings by user. 158 $this_project = GP::$project->get( $project_id ); 159 $translation_set_ids = []; 160 161 if ( ! $this_project->active ) { 162 continue; 163 } 164 165 if ( $set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $locale_slug, $locale ) ) { 166 $translation_set_ids[] = (int) $set->id; 167 } 168 169 // Fetch the strings from the sub projects too 170 foreach ( $this_project->sub_projects() as $project ) { 171 if ( ! $project->active ) { 172 continue; 173 } 174 if ( $set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $locale_slug, $locale ) ) { 175 $translation_set_ids[] = (int) $set->id; 176 } 177 } 178 179 $user_translations = GP::$translation->find_many_no_map( [ 180 'user_id' => $user_id, 181 'translation_set_id' => $translation_set_ids 182 ] ); 183 184 if ( $user_translations && count( $user_translations ) >= 5 ) { 185 $wpdb->insert( 186 $wpdb->user_projects, 187 [ 188 'user_id' => $user_id, 189 'project_id' => $project_id, 190 'locale' => $locale, 191 'locale_slug' => $locale_slug, 192 'last_modified' => $now 193 ] 194 ); 195 continue; 196 } 148 197 } 149 198 }
Note: See TracChangeset
for help on using the changeset viewer.