fix bulk edit primary key violation adding terms #69

This commit is contained in:
Leo Germani 2018-08-29 15:40:47 -03:00
parent 067898c7dc
commit a569a87ed6
2 changed files with 62 additions and 2 deletions

View File

@ -386,7 +386,7 @@ class Bulk_Edit {
$insert_q = $this->_build_select( $wpdb->prepare("post_id, %d", $term['term_taxonomy_id']) );
$query = "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) $insert_q";
$query = "INSERT IGNORE INTO $wpdb->term_relationships (object_id, term_taxonomy_id) $insert_q";
return $wpdb->query($query);
@ -401,7 +401,7 @@ class Bulk_Edit {
$insert_q = $this->_build_select( $wpdb->prepare("post_id, %s, %s", $metadatum->get_id(), $value) );
$query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) $insert_q";
$query = "INSERT IGNORE INTO $wpdb->postmeta (post_id, meta_key, meta_value) $insert_q";
$affected = $wpdb->query($query);

View File

@ -1006,5 +1006,65 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
}
/**
* @group testt
*/
function test_repeated_terms() {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$query = [
'meta_query' => [
[
'key' => $this->metadatum->get_id(),
'value' => 'even'
]
],
'posts_per_page' => -1
];
$bulk = new \Tainacan\Bulk_Edit([
'query' => $query,
'collection_id' => $this->collection->get_id()
]);
$bulk->add_value($this->category, 'test');
$items = $Tainacan_Items->fetch([
'tax_query' => [
[
'taxonomy' => $this->taxonomy->get_db_identifier(),
'field' => 'name',
'terms' => 'test'
]
],
'posts_per_page' => -1
]);
$this->assertEquals(20, $items->found_posts);
$bulk = new \Tainacan\Bulk_Edit([
'items_ids' => $this->items_ids,
]);
$bulk->add_value($this->category, 'test');
$items = $Tainacan_Items->fetch([
'tax_query' => [
[
'taxonomy' => $this->taxonomy->get_db_identifier(),
'field' => 'name',
'terms' => 'test'
]
],
'posts_per_page' => -1
]);
$this->assertEquals(40, $items->found_posts);
}
}