prepare( "SELECT legacy.post_id FROM {$wpdb->postmeta} AS legacy INNER JOIN {$wpdb->posts} AS posts ON posts.ID = legacy.post_id AND posts.post_type = 'product_variation' LEFT JOIN {$wpdb->postmeta} AS disabled ON disabled.post_id = legacy.post_id AND disabled.meta_key = %s WHERE legacy.meta_key = %s AND legacy.meta_value <> '' AND disabled.post_id IS NULL GROUP BY legacy.post_id ORDER BY legacy.post_id ASC LIMIT %d", $fallback_disabled, $legacy_meta_key, $limit ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared immediately above. return array_map( 'intval', $wpdb->get_col( $query ) ); }; $variation_ids = $select_variation_ids( self::BATCH_SIZE ); foreach ( $variation_ids as $variation_id ) { $legacy_gallery_image_ids = array_values( array_filter( wp_parse_id_list( get_post_meta( $variation_id, $legacy_meta_key, true ) ) ) ); $core_gallery_image_ids = wp_parse_id_list( get_post_meta( $variation_id, $core_gallery_meta, true ) ); if ( empty( $core_gallery_image_ids ) && ! empty( $legacy_gallery_image_ids ) ) { update_post_meta( $variation_id, $core_gallery_meta, implode( ',', $legacy_gallery_image_ids ) ); } // Keep legacy meta for third-party readers; disable fallback via the sentinel instead. LegacyVariationGalleryCompatibility::mark_variation_id_core_managed( $variation_id ); } $has_more = ! empty( $select_variation_ids( 1 ) ); // Guard against duplicate completion events if this runner is invoked twice. if ( ! $has_more && ! get_option( self::COMPLETED_OPTION ) ) { update_option( self::COMPLETED_OPTION, time() ); Telemetry::record_event( Telemetry::EVENT_MIGRATION_COMPLETED ); } return $has_more; } }