Final refactors

This commit is contained in:
Rodrigo de Oliveira 2021-05-10 20:53:27 -03:00
parent 05781fe68a
commit 0fa80a2bc2
1 changed files with 9 additions and 7 deletions

View File

@ -520,7 +520,7 @@ class CSV extends Importer {
if ($this->get_option('document_import_mode') === 'replace' ) {
$this->add_log('Item Document will be replaced ... ');
$this->delete_previous_document_imgs($item_inserted->get_id(), $item_inserted->get_document());
$this->add_log('Deleted all previous Item Documents ... ');
$this->add_log('Deleted previous Item Documents ... ');
}
$id = $TainacanMedia->insert_attachment_from_url($correct_value, $item_inserted->get_id());
@ -1078,16 +1078,18 @@ class CSV extends Importer {
return $message;
}
private function delete_previous_document_imgs($item_id, $curent_document) {
private function delete_previous_document_imgs($item_id, $item_document) {
$previous_imgs = [
'post_parent' => $item_id,
'post_type' => 'attachment',
'post_status' => 'any',
'post__not_in' => [$curent_document]
'post__not_in' => [$item_document]
];
$attchs = new \WP_Query($previous_imgs);
foreach ($attchs as $_att) {
wp_delete_attachment($_att->ID, true);
$posts_query = new \WP_Query();
$attachs = $posts_query->query($previous_imgs);
foreach ($attachs as $att) {
$this->add_log( "Deleting attachment [". $att->ID . "] " . $att->post_title);
wp_delete_attachment($att->ID, true);
}
}