Squash bugs mercilessly
This commit is contained in:
parent
7693700ba3
commit
5b80c555d7
@ -60,7 +60,7 @@ function post_to_object( $post ) {
|
||||
function get_existing_object( $permalink ) {
|
||||
global $wpdb;
|
||||
return $wpdb->get_row( $wpdb->prepare(
|
||||
'SELECT * FROM pterotype_objects WHERE object->"$.url" = %s', $permalink
|
||||
"SELECT * FROM {$wpdb->prefix}pterotype_objects WHERE object->\"$.url\" = %s", $permalink
|
||||
) );
|
||||
}
|
||||
?>
|
||||
|
@ -17,6 +17,7 @@ add_action( 'user_register', function( $user_id ) {
|
||||
} );
|
||||
|
||||
add_action( 'pterotype_init', function() {
|
||||
\schema\run_migrations();
|
||||
\actors\initialize_actors();
|
||||
} );
|
||||
|
||||
|
@ -50,9 +50,9 @@ function handle_inbox( $actor_slug, $activity ) {
|
||||
);
|
||||
}
|
||||
$object = $activity['object'];
|
||||
$object = \objects\upsert_object( $object );
|
||||
if ( is_wp_error( $object ) ) {
|
||||
return $object;
|
||||
$object_row = \objects\upsert_object( $object );
|
||||
if ( is_wp_error( $object_row ) ) {
|
||||
return $object_row;
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
namespace activities\undo;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '../../util.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '../activities.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '../actors.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '../objects.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '../likes.php';
|
||||
|
@ -72,9 +72,9 @@ function handle_inbox( $actor_slug, $activity ) {
|
||||
if ( is_wp_error( $authorized ) ) {
|
||||
return $authorized;
|
||||
}
|
||||
$object = \objects\upsert_object( $object );
|
||||
if ( is_wp_error( $object ) ) {
|
||||
return $object;
|
||||
$object_row = \objects\upsert_object( $object );
|
||||
if ( is_wp_error( $object_row ) ) {
|
||||
return $object_row;
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
@ -122,10 +122,11 @@ function references_local_object( $object, $depth ) {
|
||||
|
||||
function persist_activity( $actor_slug, $activity ) {
|
||||
global $wpdb;
|
||||
$activity = \objects\upsert_object( $activity );
|
||||
if ( is_wp_error( $activity ) ) {
|
||||
return $activity;
|
||||
$row = \objects\upsert_object( $activity );
|
||||
if ( is_wp_error( $row ) ) {
|
||||
return $row;
|
||||
}
|
||||
$activity = $row->object;
|
||||
$activity_id = \objects\get_object_id( $activity['id'] );
|
||||
if ( !$activity_id ) {
|
||||
return new \WP_Error(
|
||||
@ -184,7 +185,7 @@ function get_inbox( $actor_slug ) {
|
||||
), ARRAY_A );
|
||||
return \collections\make_ordered_collection( array_map(
|
||||
function ( $result ) {
|
||||
return json_decode( $result['activity'], true );
|
||||
return json_decode( $result['object'], true );
|
||||
},
|
||||
$results
|
||||
) );
|
||||
|
@ -104,11 +104,12 @@ function upsert_object( $object ) {
|
||||
'%s',
|
||||
'%d'
|
||||
);
|
||||
$id = $row->id;
|
||||
$row = new \stdClass();
|
||||
$row->id = $wpdb->insert_id;
|
||||
$row->id = $id;
|
||||
update_referencing_activities( $object );
|
||||
}
|
||||
if ( !$res ) {
|
||||
if ( $res === false ) {
|
||||
return new \WP_Error(
|
||||
'db_error', __( 'Failed to upsert object row', 'pterotype' )
|
||||
);
|
||||
@ -142,7 +143,7 @@ function update_object( $object ) {
|
||||
$wpdb->prefix . 'pterotype_objects',
|
||||
array( 'object' => $object_json, 'type' => $object['type'] ),
|
||||
array( 'activitypub_id' => $object['id'] ),
|
||||
'%s', '%d' );
|
||||
'%s', '%s' );
|
||||
if ( !$res ) {
|
||||
return new \WP_Error(
|
||||
'db_error', __( 'Failed to update object row', 'pterotype' )
|
||||
@ -162,7 +163,7 @@ function update_referencing_activities( $object ) {
|
||||
) );
|
||||
if ( $referencing_activities ) {
|
||||
foreach ( $referencing_activities as $activity_row ) {
|
||||
$activity = json_decode( $activity_row->activity, true );
|
||||
$activity = json_decode( $activity_row->object, true );
|
||||
$activity['object'] = $object;
|
||||
update_object( $activity );
|
||||
}
|
||||
|
@ -112,10 +112,11 @@ function handle_activity( $actor_slug, $activity ) {
|
||||
return $activity;
|
||||
}
|
||||
// the activity may have changed while processing side effects, so persist the new version
|
||||
$activity = \objects\upsert_object( $activity );
|
||||
if ( is_wp_error( $activity ) ) {
|
||||
return $activity;
|
||||
$row = \objects\upsert_object( $activity );
|
||||
if ( is_wp_error( $row) ) {
|
||||
return $row;
|
||||
}
|
||||
$activity = $row->object;
|
||||
deliver_activity( $actor_slug, $activity );
|
||||
$res = new \WP_REST_Response();
|
||||
$res->set_status(201);
|
||||
@ -150,7 +151,7 @@ function get_outbox( $actor_slug ) {
|
||||
// TODO return PagedCollection if $activites is too big
|
||||
return \collections\make_ordered_collection( array_map(
|
||||
function ( $result) {
|
||||
return json_decode( $result['activity'], true);
|
||||
return json_decode( $result['object'], true);
|
||||
},
|
||||
$results
|
||||
) );
|
||||
|
@ -14,7 +14,7 @@ function pterotype_init() {
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
function pterotype_deactive() {
|
||||
function pterotype_deactivate() {
|
||||
do_action( 'pterotype_deactivate' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user