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

Commit

Permalink
add delete /pattern endpoint (#11890)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux authored Nov 23, 2023
1 parent 684d923 commit c9f99af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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 ) );
}
}

0 comments on commit c9f99af

Please sign in to comment.