fix: call the function update on clone metadata_order #365

This commit is contained in:
vnmedeiros 2020-10-09 11:52:55 -03:00
parent 60c1e12b05
commit 8bbba55be1
1 changed files with 13 additions and 8 deletions

View File

@ -296,10 +296,10 @@ class Collections extends Repository {
$this->pre_process( $collection );
$this->handle_parent_order_metadata_clone( $collection );
$new_collection = parent::insert( $collection );
$this->handle_core_metadata( $new_collection );
$this->handle_childen_order_metadata_clone( $new_collection );
$collection->register_collection_item_post_type();
flush_rewrite_rules( false ); // needed to activate items post type archive url
@ -400,17 +400,22 @@ class Collections extends Repository {
}
}
function handle_childen_order_metadata_clone( $collection ) {
/**
* This function guarantees that children collections has its own clone
* of "metadata_order" from the parent collention.
*
* @param \Tainacan\Entities\Collection $collection, children collection
*
* @return void
*/
function handle_parent_order_metadata_clone( &$collection ) {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
if ($collection instanceof Entities\Collection && $collection->get_parent() != 0 ) {
if ($collection instanceof Entities\Collection && $collection->get_parent() != 0) {
$parent_collection = $this->fetch( $collection->get_parent() );
$collection->set_metadata_order($parent_collection->get_metadata_order());
if ($collection->validate()) {
parent::update($collection);
} else {
throw new \Exception( implode("," $collection->get_errors()) );
if (!$collection->validate()) {
throw new \Exception( implode(",", $collection->get_errors()) );
}
}
}