diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc69b0b..ea850091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ LifterLMS REST API Changelog ============================ +v1.0.5 - 2026-04-10 +------------------- + +##### Updates and Enhancements + ++ Handle removal of depreciated SQL_CALC_FOUND_ROWS for counting query results. + + v1.0.4 - 2026-04-10 ------------------- diff --git a/class-lifterlms-rest-api.php b/class-lifterlms-rest-api.php index f1529050..faf3335a 100644 --- a/class-lifterlms-rest-api.php +++ b/class-lifterlms-rest-api.php @@ -26,7 +26,7 @@ final class LifterLMS_REST_API { * * @var string */ - public $version = '1.0.4'; + public $version = '1.0.5'; /** * Constructor. diff --git a/i18n/lifterlms-rest.pot b/i18n/lifterlms-rest.pot index a4807221..f1d6bfb4 100644 --- a/i18n/lifterlms-rest.pot +++ b/i18n/lifterlms-rest.pot @@ -2,14 +2,14 @@ # This file is distributed under the GPLv3. msgid "" msgstr "" -"Project-Id-Version: LifterLMS REST API 1.0.4\n" +"Project-Id-Version: LifterLMS REST API 1.0.5\n" "Report-Msgid-Bugs-To: https://lifterlms.com/my-account/my-tickets\n" "Last-Translator: Team LifterLMS \n" "Language-Team: Team LifterLMS \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2026-04-10T12:22:26+00:00\n" +"POT-Creation-Date: 2026-04-10T13:45:41+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: llms/dev 0.2.1\n" "X-Domain: lifterlms\n" diff --git a/includes/class-llms-rest-api-keys-query.php b/includes/class-llms-rest-api-keys-query.php index 4ff89060..e516d6c2 100644 --- a/includes/class-llms-rest-api-keys-query.php +++ b/includes/class-llms-rest-api-keys-query.php @@ -125,6 +125,7 @@ protected function parse_args() { * @since 1.0.0-beta.1 * @since 1.0.0-beta.16 Use `$this->sql_select_columns({columns})` to determine the columns to select. * @since 1.0.0-beta.22 Renamed from `preprare_query()`. + * @since 1.0.5 Set `$this->count_query` for found results without `SQL_CALC_FOUND_ROWS`. * * @return string */ @@ -132,9 +133,16 @@ protected function prepare_query() { global $wpdb; + $from = "FROM {$wpdb->prefix}lifterlms_api_keys"; + $where = $this->sql_where(); + + if ( ! $this->get( 'no_found_rows' ) ) { + $this->count_query = "SELECT COUNT(*) {$from} {$where}"; + } + return "SELECT {$this->sql_select_columns( 'id' )} - FROM {$wpdb->prefix}lifterlms_api_keys - {$this->sql_where()} + {$from} + {$where} {$this->sql_orderby()} {$this->sql_limit()};"; diff --git a/includes/class-llms-rest-webhooks-query.php b/includes/class-llms-rest-webhooks-query.php index 3bd0a022..14bfbb77 100644 --- a/includes/class-llms-rest-webhooks-query.php +++ b/includes/class-llms-rest-webhooks-query.php @@ -123,6 +123,7 @@ protected function parse_args() { * @since 1.0.0-beta.1 * @since 1.0.0-beta.16 Use `$this->sql_select_columns({columns})` to determine the columns to select. * @since 1.0.0-beta.22 Renamed from `preprare_query()`. + * @since 1.0.5 Set `$this->count_query` for found results without `SQL_CALC_FOUND_ROWS`. * * @return string */ @@ -130,9 +131,16 @@ protected function prepare_query() { global $wpdb; + $from = "FROM {$wpdb->prefix}lifterlms_webhooks"; + $where = $this->sql_where(); + + if ( ! $this->get( 'no_found_rows' ) ) { + $this->count_query = "SELECT COUNT(*) {$from} {$where}"; + } + return "SELECT {$this->sql_select_columns( 'id' )} - FROM {$wpdb->prefix}lifterlms_webhooks - {$this->sql_where()} + {$from} + {$where} {$this->sql_orderby()} {$this->sql_limit()};"; diff --git a/includes/server/class-llms-rest-enrollments-controller.php b/includes/server/class-llms-rest-enrollments-controller.php index d48933a0..f479e22f 100644 --- a/includes/server/class-llms-rest-enrollments-controller.php +++ b/includes/server/class-llms-rest-enrollments-controller.php @@ -889,6 +889,7 @@ protected function prepare_items_query( $prepared_args = array(), $request = nul * @since 1.0.0-beta.4 Enrollment's post_id and student_id casted to integer. * @since 1.0.0-beta.10 Added subquery to retrieve the enrollments trigger. * @since 1.0.0-beta.18 Fixed wrong trigger retrieved when multiple trigger were present for the same user,post pair. + * @since 1.0.5 Replaced `SQL_CALC_FOUND_ROWS` / `FOUND_ROWS()` with a separate `COUNT(DISTINCT)` query. * * @param array $query_args Array of collection arguments. * @param WP_REST_Request $request Optional. Full details about the request. Default null. @@ -989,19 +990,18 @@ protected function get_objects_query( $query_args, $request = null ) { $query = new stdClass(); - $select_found_rows = empty( $query_args['no_found_rows'] ) ? esc_sql( 'SQL_CALC_FOUND_ROWS' ) : ''; - - // the query. - $query->items = $wpdb->get_results( - $wpdb->prepare( - " - SELECT {$select_found_rows} DISTINCT upm.post_id AS post_id, upm.user_id as student_id, upm.updated_date as date_created, upm2.updated_date as date_updated, upm2.meta_value as status, upm3.meta_value as etrigger - FROM {$wpdb->prefix}lifterlms_user_postmeta AS upm + $from_joins_where = "FROM {$wpdb->prefix}lifterlms_user_postmeta AS upm JOIN {$updated_date_status} as upm2 ON upm.post_id = upm2.post_id AND upm.user_id = upm2.user_id JOIN {$trigger} as upm3 ON upm.post_id = upm3.post_id AND upm.user_id = upm3.user_id WHERE upm.meta_key = '_start_date' AND upm.{$id_column} = %d - {$filter} + {$filter}"; + + $query->items = $wpdb->get_results( + $wpdb->prepare( + " + SELECT DISTINCT upm.post_id AS post_id, upm.user_id as student_id, upm.updated_date as date_created, upm2.updated_date as date_updated, upm2.meta_value as status, upm3.meta_value as etrigger + {$from_joins_where} {$order} {$limit}; ", @@ -1023,7 +1023,18 @@ protected function get_objects_query( $query_args, $request = null ) { } } - $query->found_results = empty( $query_args['no_found_rows'] ) ? absint( $wpdb->get_var( 'SELECT FOUND_ROWS()' ) ) : $count; // no-cache ok. + if ( empty( $query_args['no_found_rows'] ) ) { + $query->found_results = absint( + $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $wpdb->prepare( + "SELECT COUNT(DISTINCT upm.post_id, upm.user_id) {$from_joins_where}", + array( $query_args['id'] ) + ) + ) + ); + } else { + $query->found_results = $count; + } return $query; diff --git a/lifterlms-rest.php b/lifterlms-rest.php index 4e9b0f5b..c6c69cdb 100644 --- a/lifterlms-rest.php +++ b/lifterlms-rest.php @@ -10,7 +10,7 @@ * Plugin Name: LifterLMS REST API * Plugin URI: https://lifterlms.com/ * Description: REST API feature plugin for the LifterLMS Core. - * Version: 1.0.4 + * Version: 1.0.5 * Author: LifterLMS * Author URI: https://lifterlms.com/ * Text Domain: lifterlms diff --git a/package-lock.json b/package-lock.json index 5b6a4ca9..3e5a1a7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lifterlms-rest", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index 36e36eb2..42774e47 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lifterlms-rest", - "version": "1.0.4", + "version": "1.0.5", "description": "REST API feature plugin for the LifterLMS Core.", "author": "LifterLMS", "homepage": "https://lifterlms.com/", diff --git a/spec/openapi.yaml b/spec/openapi.yaml index 3e853698..1e63c3c2 100644 --- a/spec/openapi.yaml +++ b/spec/openapi.yaml @@ -1,6 +1,6 @@ openapi: 3.0.0 info: - version: 1.0.4 + version: 1.0.5 title: LifterLMS REST API description: >- # Introduction