delete_filter_when_metadata_deleted in progress
This commit is contained in:
parent
3df60abead
commit
a4ad04c072
|
@ -24,6 +24,7 @@ class Filters extends Repository {
|
|||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
add_action( 'tainacan-deleted', array( &$this, 'hook_delete_when_metadata_deleted' ) );
|
||||
}
|
||||
|
||||
public function get_map() {
|
||||
|
@ -540,4 +541,19 @@ class Filters extends Repository {
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function hook_delete_when_metadata_deleted($entity) {
|
||||
|
||||
if ( $entity instanceof Entities\Metadatum ) {
|
||||
$metadatum_id = $entity->get_id();
|
||||
var_dump($metadatum_id);
|
||||
$filters = $this->fetch(['metadatum_id' => $metadatum_id], 'OBJECT');
|
||||
foreach ($filters as $filter) {
|
||||
var_dump($filter->get_id());
|
||||
$this->delete($filter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -558,7 +558,8 @@ class Metadata extends Repository {
|
|||
*/
|
||||
public function delete( $metadatum_id ) {
|
||||
$deleted = new Entities\Metadatum( wp_delete_post( $metadatum_id, true ) );
|
||||
|
||||
var_dump($deleted);
|
||||
var_dump($deleted->get_id());
|
||||
if ( $deleted && $this->use_logs) {
|
||||
$this->logs_repository->insert_log( $deleted, [], false, true );
|
||||
|
||||
|
|
|
@ -367,4 +367,50 @@ class Filters extends TAINACAN_UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
|
||||
function test_delete_filter_when_metadata_deleted() {
|
||||
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'Collection filtered',
|
||||
'description' => 'Is filtered',
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'Other filtered',
|
||||
'description' => 'Is filtered',
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||
'collection_id' => $collection->get_id()
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$filter = $this->tainacan_entity_factory->create_entity(
|
||||
'filter',
|
||||
array(
|
||||
'name' => 'filtro',
|
||||
'collection' => $collection,
|
||||
'description' => 'descricao',
|
||||
'metadatum' => $metadatum2,
|
||||
'filter_type' => 'Tainacan\Filter_Types\Autocomplete'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$Tainacan_Metadata->delete($metadatum2);
|
||||
|
||||
$x = $Tainacan_Filters->fetch( $filter->get_id() );
|
||||
|
||||
$this->assertEmpty($x);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue