fix creation of child collections #206

This commit is contained in:
leogermani 2019-03-01 16:24:07 -03:00
parent 624a777f29
commit 644eb28528
2 changed files with 41 additions and 1 deletions

View File

@ -414,7 +414,11 @@ class Collections extends Repository {
$Tainacan_Metadata->register_core_metadata( $collection );
if ( $this->old_collection instanceof Entities\Collection && $this->old_collection->get_parent() != $collection->get_parent() ) {
if ( $this->old_collection instanceof Entities\Collection &&
$this->old_collection->get_parent() != $collection->get_parent() &&
$this->old_core_title instanceof Entities\Metadatum &&
$this->old_core_description instanceof Entities\Metadatum
) {
$Tainacan_Metadata->maybe_update_core_metadata_meta_keys( $collection, $this->old_collection, $this->old_core_title, $this->old_core_description );
}
}

View File

@ -346,4 +346,40 @@ class Collections extends TAINACAN_UnitTestCase {
$this->assertEquals([1 => 4, 2 => 5, 0 => 3], $diff['moderators_ids']['diff_with_index']);
}
function test_create_child_collection() {
$x = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test',
'description' => 'adasdasdsa',
'default_order' => 'DESC',
),
true
);
$col = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test',
'description' => 'adasdasdsa',
'default_order' => 'DESC',
'status' => 'auto-draft'
),
true
);
$Collections = \Tainacan\Repositories\Collections::get_instance();
$col->set_parent($x->get_id());
$col->set_status('publish');
$col->validate();
$col = $Collections->insert($col);
$this->assertEquals($x->get_id(), $col->get_parent());
}
}