fix bulk edit primary key violation adding terms #69
This commit is contained in:
parent
067898c7dc
commit
a569a87ed6
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue