Refactoring
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 44s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 54s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 57s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Has been cancelled

* Delete unused function
* Modularize logic
This commit is contained in:
André Menrath 2025-01-04 12:27:09 +01:00
parent ddeb5c6cca
commit c291c81ecc
2 changed files with 24 additions and 30 deletions

View file

@ -313,22 +313,15 @@ class Event_Sources {
return;
}
self::delete_events_by_event_source( $post_id);
self::delete_events_by_event_source( $post_id );
$thumbnail_id = get_post_thumbnail_id( $post_id );
$deleted = $event_source->delete();
if ( $thumbnail_id ) {
wp_delete_attachment( $thumbnail_id, true );
}
$result = wp_delete_post( $post_id, false );
// If the deletion was successful delete all transients regarding event sources.
if ( $result ) {
if ( $deleted ) {
self::queue_unfollow_actor( $activitypub_id );
}
return $result;
return $deleted;
}
/**

View file

@ -30,7 +30,7 @@ class Event_Source extends Actor {
const ACTIVITYPUB_USER_HANDLE_REGEXP = '(?:([A-Za-z0-9_.-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))';
/**
* The complete remote ActivityPub profile of the Event Source.
* The WordPress Post ID which stores the event source.
*
* @var int
*/
@ -101,24 +101,6 @@ class Event_Source extends Actor {
return $actor['outbox'];
}
/**
* Get the WordPress post which stores the Event Source by the ActivityPub actor id of the event source.
*
* @param string $actor_id The ActivityPub actor ID.
* @return ?WP_Post The WordPress post if the actor is found, null if not.
*/
private static function get_wp_post_by_activitypub_actor_id( $actor_id ) {
global $wpdb;
$post_id = $wpdb->get_var(
$wpdb->prepare(
"SELECT ID FROM $wpdb->posts WHERE guid=%s AND post_type=%s",
esc_sql( $actor_id ),
Event_Sources::POST_TYPE
)
);
return $post_id ? get_post( $post_id ) : null;
}
/**
* Get the Event Source by the ActivityPub ID.
*
@ -296,4 +278,23 @@ class Event_Source extends Actor {
return $post_id;
}
/**
* Delete an Event Source and it's profile image.
*/
public function delete() {
$post_id = $this->get__id();
if ( ! $post_id ) {
return false;
}
$thumbnail_id = get_post_thumbnail_id( $post_id );
if ( $thumbnail_id ) {
wp_delete_attachment( $thumbnail_id, true );
}
return wp_delete_post( $post_id, false ) ?? false;
}
}