Importer fix
This commit is contained in:
parent
8d1e5fa7d9
commit
f3a413a289
|
@ -220,10 +220,9 @@ class Items extends Repository {
|
|||
$collections_objects[] = $col;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach ( $collections_objects as $collection ) {
|
||||
|
||||
foreach ( $collections_objects as $collection ) {
|
||||
/**
|
||||
* If no specific status is defined in the query, WordPress will fetch
|
||||
* public items and private items for users withe the correct permission.
|
||||
|
|
|
@ -401,19 +401,18 @@ abstract class Importer {
|
|||
}
|
||||
}
|
||||
|
||||
$item->set_status('publish' );
|
||||
$insertedItem->set_status('publish' );
|
||||
|
||||
// inserted the id on processed item with its index as array index
|
||||
$this->processed_items[ $index ] = $item->get_id();
|
||||
|
||||
if($item->validate()) {
|
||||
$Tainacan_Items->update( $item );
|
||||
$this->processed_items[ $index ] = $insertedItem->get_id();
|
||||
if($insertedItem->validate()) {
|
||||
$Tainacan_Items->update( $insertedItem );
|
||||
} else {
|
||||
$this->add_log( 'error', 'Item ' . $index . ': ' ); // TODO add the $item->get_errors() array
|
||||
$this->add_log( 'error', 'Item ' . $index . ': ' . $insertedItem->get_errors()[0] ); // TODO add the $item->get_errors() array
|
||||
return false;
|
||||
}
|
||||
|
||||
return $item;
|
||||
return $insertedItem;
|
||||
} else {
|
||||
$this->add_log( 'error', 'Collection not set');
|
||||
return false;
|
||||
|
|
|
@ -93,4 +93,49 @@ class CoreFieldTypes extends TAINACAN_UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
function test_validate_required_title() {
|
||||
|
||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'test',
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$i = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'description' => 'adasdasdsa',
|
||||
'collection' => $collection,
|
||||
'status' => 'draft'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$fields = $Tainacan_Fields->fetch_by_collection( $collection, [], 'OBJECT' ) ;
|
||||
|
||||
foreach ( $fields as $index => $field ){
|
||||
if ( $field->get_field_type_object()->get_core() && $field->get_field_type_object()->get_related_mapped_prop() == 'title') {
|
||||
$core_title = $field;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $core_title);
|
||||
$item_metadata->set_value('title');
|
||||
$item_metadata->validate();
|
||||
$Tainacan_Item_Metadata->insert($item_metadata);
|
||||
|
||||
$i->set_status('publish' );
|
||||
|
||||
$this->assertTrue($i->validate(), 'Item with empy title should validate because core title field has value');
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
|
||||
}
|
||||
|
||||
/*public function test_automapping_old_tainacan()
|
||||
/* public function test_automapping_old_tainacan()
|
||||
{
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
@ -228,13 +228,11 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals(2, $_SESSION['tainacan_importer'][$id]->run(), 'first step should import 2 items');
|
||||
$this->assertEquals(4, $_SESSION['tainacan_importer'][$id]->run(), 'second step should import 2 items');
|
||||
$this->assertEquals(5, $_SESSION['tainacan_importer'][$id]->run(), 'third step should import 3 items');
|
||||
|
||||
$this->assertEquals(5, $_SESSION['tainacan_importer'][$id]->run(), 'if call run again after finish, do nothing');
|
||||
|
||||
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
|
||||
|
||||
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,7 +241,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
public function test_fetch_file(){
|
||||
$csv_importer = new Importer\CSV();
|
||||
$id = $csv_importer->get_id();
|
||||
//$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wordpress-test/wp-json' );
|
||||
//$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||
$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wordpress-test/wp-json' );
|
||||
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue