diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index 5b6f38101..8559c26fa 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -537,7 +537,22 @@ abstract class Repository { foreach ($map as $prop => $mapped) { if($old_entity->get_mapped_property($prop) != $new_entity->get_mapped_property($prop) ) { - $diff[$prop] = ['new' => $new_entity->get_mapped_property($prop), 'old' => $old_entity->get_mapped_property($prop)]; + if($mapped['map'] == 'meta_multi') { + $meta_diff = array_diff( $new_entity->get_mapped_property($prop), $old_entity->get_mapped_property($prop) ); + if( !empty($meta_diff) ) { + $diff[$prop] = [ + 'new' => $new_entity->get_mapped_property($prop), + 'old' => $old_entity->get_mapped_property($prop), + 'diff' => $meta_diff //TODO better expose difference + ]; + } + } + else { + $diff[$prop] = [ + 'new' => $new_entity->get_mapped_property($prop), + 'old' => $old_entity->get_mapped_property($prop) + ]; + } } } $diff = apply_filters('tainacan-entity-diff', $diff, $new, $old); diff --git a/tests/test-collections.php b/tests/test-collections.php index dea0f6aaf..745e2e97f 100644 --- a/tests/test-collections.php +++ b/tests/test-collections.php @@ -228,21 +228,25 @@ class Collections extends TAINACAN_UnitTestCase { $x = $this->tainacan_entity_factory->create_entity( 'collection', array( - 'name' => 'testeDiff', - 'description' => 'adasdasdsa', - 'default_order' => 'DESC' + 'name' => 'testeDiff', + 'description' => 'adasdasdsa', + 'default_order' => 'DESC', + 'moderators_ids' => [1,2,3] ), true ); $x->set_name('OtherValue'); $x->set_description('testeDiff2'); + $x->set_moderators_ids([3,4,5]); $diff = $x->diff(); - $this->assertEquals(2, count($diff)); + $this->assertEquals(3, count($diff)); $this->assertEquals($diff['name']['new'], 'OtherValue'); $this->assertEquals($diff['name']['old'], 'testeDiff'); $this->assertEquals($diff['description']['new'], 'testeDiff2'); $this->assertEquals($diff['description']['old'], 'adasdasdsa'); + $this->assertEquals([1 => 4, 2 => 5], $diff['moderators_ids']['diff']); + } }