_migrate_awards( string $type )
Migrate deprecated meta values for user awards by type.
Description Description
Queries 50 earned awards at a time and migrates their data by moving meta data to the new location and then deleting the deprecated meta values.
Parameters Parameters
- $type
-
(string) (Required) Award type, either "achievement" or "certificate".
Return Return
(boolean) Returns true
if there are more results and false
if there are no further results.
Source Source
File: includes/functions/updates/llms-functions-updates-600.php
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | function _migrate_awards( $type ) { $per_page = llms_update_util_get_items_per_page(); $query_args = array ( 'orderby' => array ( 'ID' => 'ASC' ), 'post_type' => "llms_my_{$type}" , 'post_status' => 'any' , 'posts_per_page' => $per_page , 'no_found_rows' => true, // We don't care about found rows since we'll run the query as many times as needed anyway. 'fields' => 'ids' , // We just need the ID for the updates we'll perform. 'meta_query' => array ( 'relation' => 'OR' , array ( 'key' => "_llms_{$type}_title" , 'compare' => 'EXISTS' , ), array ( 'key' => "_llms_{$type}_template" , 'compare' => 'EXISTS' , ), array ( 'key' => "_llms_{$type}_image" , 'compare' => 'EXISTS' , ), ), ); if ( 'achievement' === $type ) { $query_args [ 'meta_query' ][] = array ( 'key' => '_llms_achievement_content' , 'compare' => 'EXISTS' , ); } $query = new \WP_Query( $query_args ); // Don't trigger deprecations. remove_filter( 'get_post_metadata' , 'llms_engagement_handle_deprecated_meta_keys' , 20, 3 ); // Don't trigger save hooks. remove_action( "save_post_llms_my_{$type}" , array ( 'LLMS_Controller_Awards' , 'on_save' ), 20 ); $legacy_option_added = false; foreach ( $query ->posts as $post_id ) { $image_migrated = _migrate_award( $post_id , $type ); if ( ! $legacy_option_added && ! $image_migrated ) { _add_legacy_opt( $type ); $legacy_option_added = true; } } // Re-enable deprecations. add_filter( 'get_post_metadata' , 'llms_engagement_handle_deprecated_meta_keys' , 20, 3 ); // Re-enabled save hooks. add_action( "save_post_llms_my_{$type}" , array ( 'LLMS_Controller_Awards' , 'on_save' ), 20 ); // If there was 50 results assume there's another page and run again, otherwise we're done. return ( count ( $query ->posts ) === $per_page ); } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
6.0.0 | Introduced. |