Skip to content

Commit

Permalink
Scheduled Updates: Check if load function exists before using it. (#3…
Browse files Browse the repository at this point in the history
…7081)

* Scheduled Updates: Check if load function exists before using it.

In #36915 we introduced an alternative load path for the endpoint file, which can lead to undefined function errors when loaded outside of the context of Jetpack.

* Fix up versions

* Remove unneeded collection callback

It doesn't do anything currently and creates fatal errors when update-schedules endpoints get called internally. Let's just remove it for now.

* Only call rest_get_server() if we're in a REST API request.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/8837785914

Upstream-Ref: Automattic/jetpack@5c9eae6
  • Loading branch information
obenland authored and matticbot committed Apr 25, 2024
1 parent 450e6a0 commit b27e8bf
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 68 deletions.
42 changes: 21 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/automattic/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"automattic/jetpack-redirect": "^2.0.2",
"automattic/jetpack-stats-admin": "^0.18.3",
"automattic/jetpack-status": "^3.0.0",
"automattic/scheduled-updates": "^0.9.0"
"automattic/scheduled-updates": "^0.9.1-alpha"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
Expand Down
8 changes: 8 additions & 0 deletions vendor/automattic/scheduled-updates/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.1-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- Adds an exists check before using wpcom_rest_api_v2_load_plugin() in the API endpoint.

## [0.9.0] - 2024-04-25
### Added
- Add health paths to scheduled updates. [#36990]
Expand Down Expand Up @@ -134,6 +141,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Generate initial package for Scheduled Updates [#35796]

[0.9.1-alpha]: https://github.com/Automattic/scheduled-updates/compare/v0.9.0...v0.9.1-alpha
[0.9.0]: https://github.com/Automattic/scheduled-updates/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/Automattic/scheduled-updates/compare/v0.7.2...v0.8.0
[0.7.2]: https://github.com/Automattic/scheduled-updates/compare/v0.7.1...v0.7.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Scheduled_Updates {
*
* @var string
*/
const PACKAGE_VERSION = '0.9.0';
const PACKAGE_VERSION = '0.9.1-alpha';

/**
* The cron event hook for the scheduled plugins update.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,16 @@ public function prepare_response_for_collection( $response ) {
return $response;
}

$data = (array) $response->get_data();
$server = rest_get_server();
$links = $server::get_compact_response_links( $response );
$data = (array) $response->get_data();

if ( ! empty( $links ) ) {
$data['_links'] = $links;
// Only call rest_get_server() if we're in a REST API request.
if ( did_action( 'rest_api_init' ) ) {
$server = rest_get_server();
$links = $server::get_compact_response_links( $response );

if ( ! empty( $links ) ) {
$data['_links'] = $links;
}
}

return $data;
Expand Down Expand Up @@ -834,4 +838,6 @@ public function get_object_params() {
}
}

wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Update_Schedules' );
if ( function_exists( 'wpcom_rest_api_v2_load_plugin' ) ) {
wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Update_Schedules' );
}
Loading

0 comments on commit b27e8bf

Please sign in to comment.