Skip to content

Commit

Permalink
Fix User Post same ID (#45)
Browse files Browse the repository at this point in the history
* Fix User Post same ID

* Fix User Post same ID
  • Loading branch information
anhdoanmis committed Jun 24, 2021
1 parent 0767854 commit bee433a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions inc/database/storage-handler.php
Expand Up @@ -85,7 +85,12 @@ public function delete_object_data( $object_id ) {
$object_type = str_replace( array( 'deleted_', 'delete_' ), '', current_filter() );
$relationships = $this->factory->filter_by( $object_type );
foreach ( $relationships as $relationship ) {
$this->delete_object_relationships( $object_id, $relationship->id );
$setting = $this->factory->get_settings( $relationship->id );
$target = null;
if ( $setting['from']['object_type'] !== $setting['to']['object_type'] ) {
$target = $setting['from']['object_type'] === $object_type ? 'from' : 'to';
}
$this->delete_object_relationships( $object_id, $relationship->id, $target );
}
}

Expand All @@ -94,14 +99,17 @@ public function delete_object_data( $object_id ) {
*
* @param int $object_id ID of the object metadata is for.
* @param string $type The relationship type.
* @param string $target The relationship target.
*/
protected function delete_object_relationships( $object_id, $type ) {
protected function delete_object_relationships( $object_id, $type, $target ) {
global $wpdb;
$sql = $target
? "DELETE FROM $wpdb->mb_relationships WHERE `type`=%s AND `$target`=%d"
: "DELETE FROM $wpdb->mb_relationships WHERE `type`=%s AND (`from`=%d OR `to`=%d)";
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->mb_relationships WHERE `type`=%s AND (`from`=%d OR `to`=%d)",
$sql,
$type,
$object_id,
$object_id
)
);
Expand Down

0 comments on commit bee433a

Please sign in to comment.