Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add DELETE private/ai/pattern endpoint #11890

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Patterns/PatternsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public static function get_patterns_ai_data_post() {
return $posts[0] ?? null;
}

/**
* Delete the post that has the generated data by the AI for the patterns.
*
* @return \WP_Post|null
*/
public static function delete_patterns_ai_data_post() {
$patterns_ai_data_post = self::get_patterns_ai_data_post();

if ( isset( $patterns_ai_data_post ) ) {
return wp_delete_post( $patterns_ai_data_post->ID, true );
}
}


/**
* Upsert the patterns AI data.
*
Expand Down
18 changes: 18 additions & 0 deletions src/StoreApi/Routes/V1/AI/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Automattic\WooCommerce\StoreApi\Routes\V1\AI;

use Automattic\WooCommerce\Blocks\AI\Connection;
use Automattic\WooCommerce\Blocks\Patterns\PatternsHelper;
use Automattic\WooCommerce\Blocks\Patterns\PatternUpdater;
use Automattic\WooCommerce\StoreApi\Routes\V1\AbstractRoute;

Expand Down Expand Up @@ -57,6 +58,11 @@ public function get_args() {
],
],
],
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'get_response' ],
'permission_callback' => [ Middleware::class, 'is_authorized' ],
],
'schema' => [ $this->schema, 'get_public_item_schema' ],
'allow_batch' => [ 'v1' => true ],
];
Expand Down Expand Up @@ -91,4 +97,16 @@ protected function get_route_post_response( \WP_REST_Request $request ) {
return $this->error_to_response( $e );
}
}

/**
* Remove patterns generated by AI.
*
* @param \WP_REST_Request $request Request object.
*
* @return bool|string|\WP_Error|\WP_REST_Response
*/
protected function get_route_delete_response( \WP_REST_Request $request ) {
PatternsHelper::delete_patterns_ai_data_post();
return rest_ensure_response( array( 'removed' => true ) );
}
}
Loading