dev: backport refactor changes from One*#74
Conversation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 58 out of 62 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
up1512001
left a comment
There was a problem hiding this comment.
Added few comments & hoping some of them are from legacy code.
|
|
||
| useEffect( () => { | ||
| const token = NONCE; | ||
| const token = ( NONCE ); |
There was a problem hiding this comment.
why need to make const out of NONCE, i think its from old code base.
There was a problem hiding this comment.
Yup legacy from OneDesign to keep the diff small. Since I want to rip this file out and replace it with tsx/apiFetch anyway, I'm leaving for now.
| 'X-OneSearch-Plugins-Token' => $public_key, | ||
| 'Accept' => 'application/json', | ||
| 'Content-Type' => 'application/json', | ||
| 'X-OneSearch-Token' => $public_key, |
There was a problem hiding this comment.
just as remainder here public_key should be api_key
There was a problem hiding this comment.
You're referring to the name of PHP variable used inside the class, or something else?
(either way, the plan is to refactor all this)
|
|
||
| $base_size = strlen( wp_json_encode( $base_record ) ?: '' ); | ||
| $available_space = 8000 - $base_size; // Per-chunk allowed size (left size). | ||
| $base_size = strlen( wp_json_encode( $base_record, JSON_INVALID_UTF8_SUBSTITUTE ) ?: '' ); |
There was a problem hiding this comment.
better to add check since wp_json_encode could return false as well.
There was a problem hiding this comment.
Good eyes. Will make sure to include this in the followup PR.
| [ | ||
| 'methods' => WP_REST_Server::CREATABLE, | ||
| 'callback' => [ $this, 'set_shared_sites' ], | ||
| 'permission_callback' => static fn () => current_user_can( 'manage_options' ), |
There was a problem hiding this comment.
can we create method into abstract class which needs to check for manage_options?
There was a problem hiding this comment.
Why would we want to abstract a one-line function call with a single parameter?
It's just extra boilerplate we need to context-switch, review and maintain.
I could see the argument to abstract the capability itself into a constant or filterable static function, on a long-term release roadmap. But at the same time the reason we're using manage_options is because they're wp_option, so really we should be getting rid of these endpoints entirely and replacing them with wp/v2/settings
| } | ||
|
|
||
| // Check X-OneSearch-Token header. | ||
| $token = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_ONESEARCH_TOKEN'] ) ); |
There was a problem hiding this comment.
remainder as assuming cleanup is pending.
There was a problem hiding this comment.
What specifically here needs cleanup?
There was a problem hiding this comment.
usage of global vars instead of request.
| */ | ||
| public function health_check(): WP_REST_Response|\WP_Error { | ||
| $requesting_origin = ''; | ||
| if ( isset( $_SERVER['HTTP_X_ONESEARCH_REQUESTING_ORIGIN'] ) && ! empty( $_SERVER['HTTP_X_ONESEARCH_REQUESTING_ORIGIN'] ) ) { |
There was a problem hiding this comment.
remainder to cleanup using check_api_permissions permission callback.
There was a problem hiding this comment.
Yup, rn the plugin has separate endpoints for local/cross-site. This will be handled in a followup PR when I dedupe.
| $index->delete()->wait(); | ||
| } catch ( \Throwable $e ) { | ||
| // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- We need visibility. | ||
| error_log( 'Algolia Exception: ' . $e->getMessage() ); |
There was a problem hiding this comment.
Imo, we need visibility that extends beyond dev-mode here.
Just for our own QA, we need these for our onepress-vip sites, and if we're using this on rtcamp-com then we definitely need this.
Possibly but unlikely that my Algolia refactor will get rid of these horrible try/catches that are hiding all bugs, and a logger class (shared or otherwise) is beyond the scope.
| 'format' => 'uri', | ||
| ], | ||
| 'publicKey' => [ | ||
| 'logo_id' => [ |
There was a problem hiding this comment.
if logo is not required then can we remove it?
There was a problem hiding this comment.
Your call.
I want to keep the diffs as close to each other, so it feels like keeping it in code but hiding it in js-land is the safest approach (especially since most the codebases arent defining or enforcing array shapes).
up1512001
left a comment
There was a problem hiding this comment.
LGTM, adding one suggestion which I think we can address in next round.
| 'X-OneSearch-Plugins-Token' => $our_public_key, | ||
| 'Accept' => 'application/json', | ||
| 'Content-Type' => 'application/json', | ||
| 'X-OneSearch-Token' => $our_public_key, |
There was a problem hiding this comment.
Just a suggestion can we stick to one terminology either api_key or public_key.
|
Merging. Leaving the comments open so I can track against the next PR. |
Description
This provides the first round of OneDesign backports to this plugin.
Technical Details
Does not make any attempts to refactor legacy code or fix existing bugs. Specifically:
inc/classes/*inc/Modules/Rest/*inc/Utilshave been left untouched.
Checklist
Screenshots
To-do
Fixes/Covers issue
Fixes #