public static function create_an_import(&$export) { $custom_type = empty($export->options['cpt']) ? 'post' : $export->options['cpt'][0]; // Do not create an import for WooCommerce Orders & Refunds // if ( in_array($custom_type, array('shop_order'))) return false; if ($export->options['is_generate_import'] and wp_all_export_is_compatible()) { $import = new PMXI_Import_Record(); if (!empty($export->options['import_id'])) { $import->getById($export->options['import_id']); } if ($import->isEmpty()) { $import->set(array('parent_import_id' => 99999, 'xpath' => '/', 'type' => 'upload', 'options' => array('empty'), 'root_element' => 'root', 'path' => 'path', 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1))->save(); if (!empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session()) { PMXE_Plugin::$session->set('import_id', $import->id); } $options = $export->options; $options['import_id'] = $import->id; $export->set(array('options' => $options))->save(); } else { if ($import->parent_import_id != 99999) { $newImport = new PMXI_Import_Record(); $newImport->set(array('parent_import_id' => 99999, 'xpath' => '/', 'type' => 'upload', 'options' => array('empty'), 'root_element' => 'root', 'path' => 'path', 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1))->save(); if (!empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session()) { PMXE_Plugin::$session->set('import_id', $newImport->id); } $options = $export->options; $options['import_id'] = $newImport->id; $export->set(array('options' => $options))->save(); } else { global $wpdb; $post = new PMXI_Post_List(); $wpdb->query($wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $import->id)); } } } }
/** * Clear associations with posts * @param bool[optional] $keepPosts When set to false associated wordpress posts will be deleted as well * @return PMXI_Import_Record * @chainable */ public function deletePosts($keepPosts = TRUE, $is_deleted_images = 'auto', $is_delete_attachments = 'auto') { $post = new PMXI_Post_List(); if (!$keepPosts) { $ids = array(); foreach ($post->getBy('import_id', $this->id)->convertRecords() as $p) { // Remove attachments if ($is_delete_attachments == 'yes' or $is_delete_attachments == 'auto' and empty($this->options['is_keep_attachments'])) { wp_delete_attachments($p->post_id, true, 'files'); } else { wp_delete_attachments($p->post_id, false, 'files'); } // Remove images if ($is_deleted_images == 'yes' or $is_deleted_images == 'auto' and empty($this->options['is_keep_imgs'])) { wp_delete_attachments($p->post_id, true, 'images'); } else { wp_delete_attachments($p->post_id, false, 'images'); } $ids[] = $p->post_id; } if (!empty($ids)) { foreach ($ids as $id) { do_action('pmxi_delete_post', $id); if ($this->options['custom_type'] != 'import_users') { wp_delete_object_term_relationships($id, get_object_taxonomies('' != $this->options['custom_type'] ? $this->options['custom_type'] : 'post')); } } if ($this->options['custom_type'] == 'import_users') { $sql = "delete a,b\n\t\t\t\t\tFROM " . $this->wpdb->users . " a\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->usermeta . " b ON ( a.ID = b.user_id )\t\t\t\t\t\n\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");"; } else { $sql = "delete a,b,c\n\t\t\t\t\tFROM " . $this->wpdb->posts . " a\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->term_relationships . " b ON ( a.ID = b.object_id )\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->postmeta . " c ON ( a.ID = c.post_id )\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->posts . " d ON ( a.ID = d.post_parent )\n\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");"; } $this->wpdb->query($this->wpdb->prepare($sql, '')); } } $this->wpdb->query($this->wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $this->id)); return $this; }
/** * Clear associations with posts * @param bool[optional] $keepPosts When set to false associated wordpress posts will be deleted as well * @return PMXI_Import_Record * @chainable */ public function deletePosts($keepPosts = TRUE, $is_deleted_images = 'auto', $is_delete_attachments = 'auto') { $post = new PMXI_Post_List(); if (!$keepPosts) { $ids = array(); foreach ($post->getBy('import_id', $this->id)->convertRecords() as $p) { $ids[] = $p->post_id; } if (!empty($ids)) { $this->deleteRecords($is_delete_attachments, $is_deleted_images, $ids); } } $this->wpdb->query($this->wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $this->id)); return $this; }
/** * Delete an import */ public function delete() { $id = $this->input->get('id'); $this->data['item'] = $item = new PMXI_Import_Record(); if (!$id or $item->getById($id)->isEmpty()) { wp_redirect($this->baseUrl); die; } if ($this->input->post('is_confirmed')) { check_admin_referer('delete-import', '_wpnonce_delete-import'); $is_deleted_images = $this->input->post('is_delete_images'); $is_delete_attachments = $this->input->post('is_delete_attachments'); $is_delete_import = $this->input->post('is_delete_import', false); $is_delete_posts = $this->input->post('is_delete_posts', false); if (!$is_delete_import and !$is_delete_posts) { wp_redirect(add_query_arg('pmxi_nt', urlencode(__('Nothing to delete.', 'wp_all_import_plugin')), $this->baseUrl)); die; } do_action('pmxi_before_import_delete', $item, $is_delete_posts); $item->delete(!$is_delete_posts, $is_deleted_images, $is_delete_attachments, $is_delete_import); $redirect_msg = ''; if ($is_delete_import and !$is_delete_posts) { $redirect_msg = __('Import deleted', 'wp_all_import_plugin'); } elseif (!$is_delete_import and $is_delete_posts) { $redirect_msg = __('All associated posts deleted.', 'wp_all_import_plugin'); } elseif ($is_delete_import and $is_delete_posts) { $redirect_msg = __('Import and all associated posts deleted.', 'wp_all_import_plugin'); } wp_redirect(add_query_arg('pmxi_nt', urlencode($redirect_msg), $this->baseUrl)); die; } $postList = new PMXI_Post_List(); $this->data['associated_posts'] = count($postList->getBy(array('import_id' => $item->id))); $this->render(); }