From 63a0328648c877b6ec1512dae5e2cf75baf53497 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 1 Sep 2018 10:14:11 -0400 Subject: [PATCH] Implement delete --- inc/activities/delete.php | 19 +++++++++++++++++++ inc/objects.php | 22 +++++++++++++++++++++- inc/outbox.php | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 inc/activities/delete.php diff --git a/inc/activities/delete.php b/inc/activities/delete.php new file mode 100644 index 0000000..40d9367 --- /dev/null +++ b/inc/activities/delete.php @@ -0,0 +1,19 @@ + diff --git a/inc/objects.php b/inc/objects.php index 120f58c..aa5095c 100644 --- a/inc/objects.php +++ b/inc/objects.php @@ -1,6 +1,9 @@ insert( @@ -46,7 +49,7 @@ function get_object( $id ) { ) ); if ( is_null( $object_json ) ) { return new \WP_Error( - 'not_found', __( 'Object not found', 'activitypub' ), array ( 'status' => 404 ) + 'not_found', __( 'Object not found', 'activitypub' ), array( 'status' => 404 ) ); } $object = json_decode( $object_json, true ); @@ -54,6 +57,23 @@ function get_object( $id ) { return $object; } +function delete_object( $object ) { + global $wpdb; + if ( !array_key_exists( 'id', $object ) ) { + return new \WP_Error( + 'invalid_object', + __( 'Object must have an "id" parameter', 'activitypub' ), + array( 'status' => 400 ) + ); + } + $id = get_id_from_url( $object['id'] ); + $res = $wpdb->delete( 'activitypub_objects', array( 'id' => $id ), '%d' ); + if ( !$res ) { + return new \WP_Error( 'db_error', __( 'Error deleting object', 'activitypub' ) ); + } + return $res; +} + function get_id_from_url( $url ) { global $wpdb; $matches = array(); diff --git a/inc/outbox.php b/inc/outbox.php index e49af3d..540a40d 100644 --- a/inc/outbox.php +++ b/inc/outbox.php @@ -15,6 +15,7 @@ namespace outbox; require_once plugin_dir_path( __FILE__ ) . '/activities.php'; require_once plugin_dir_path( __FILE__ ) . '/activities/create.php'; require_once plugin_dir_path( __FILE__ ) . '/activities/update.php'; +require_once plugin_dir_path( __FILE__ ) . '/activities/delete.php'; function handle_activity( $actor, $activity ) { // TODO handle authentication/authorization @@ -33,6 +34,7 @@ function handle_activity( $actor, $activity ) { $activity = \activities\update\handle( $actor, $activity ); break; case 'Delete': + $activity = \activities\delete\handle( $actor, $activity ); break; case 'Follow': break;