本文整理汇总了PHP中PMXI_Import_Record::set方法的典型用法代码示例。如果您正苦于以下问题:PHP PMXI_Import_Record::set方法的具体用法?PHP PMXI_Import_Record::set怎么用?PHP PMXI_Import_Record::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMXI_Import_Record
的用法示例。
在下文中一共展示了PMXI_Import_Record::set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pmxi_wp_ajax_delete_import
function pmxi_wp_ajax_delete_import()
{
if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
exit(json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
if (!current_user_can('manage_options')) {
exit(json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
$input = new PMXI_Input();
$post = $input->post(array('data' => ''));
$get = $input->get(array('iteration' => 1));
$params = array();
parse_str($post['data'], $params);
$response = array('result' => false, 'msg' => '', 'redirect' => add_query_arg('pmxi_nt', urlencode(__('Import deleted', 'wp_all_import_plugin')), $params['base_url']));
if (!empty($params['import_ids'])) {
foreach ($params['import_ids'] as $key => $id) {
$import = new PMXI_Import_Record();
$import->getById($id);
if (!$import->isEmpty()) {
if ((int) $get['iteration'] === 1) {
$import->set(array('deleted' => 0))->update();
}
$is_all_records_deleted = $import->deletePostsAjax(!$params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments']);
$response['result'] = empty($params['import_ids'][$key + 1]) ? $is_all_records_deleted : false;
$response['msg'] = sprintf(__('Import #%d - %d records deleted', 'wp_all_import_plugin'), $import->id, $import->deleted);
if ($is_all_records_deleted === true) {
$import->delete(!$params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments']);
}
}
}
}
exit(json_encode($response));
}
示例2: pmxi_wp_loaded
function pmxi_wp_loaded()
{
@ini_set("max_input_time", PMXI_Plugin::getInstance()->getOption('max_input_time'));
@ini_set("max_execution_time", PMXI_Plugin::getInstance()->getOption('max_execution_time'));
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports';
global $wpdb;
$imports = $wpdb->get_results("SELECT `id`, `name`, `path` FROM {$table} WHERE `path` IS NULL", ARRAY_A);
if (!empty($imports)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($imports as $imp) {
$importRecord->getById($imp['id']);
if (!$importRecord->isEmpty()) {
$importRecord->delete(true);
}
$importRecord->clear();
}
}
/* Check if cron is manualy, then execute import */
$cron_job_key = PMXI_Plugin::getInstance()->getOption('cron_job_key');
if (!empty($cron_job_key) and !empty($_GET['import_id']) and !empty($_GET['import_key']) and $_GET['import_key'] == $cron_job_key and !empty($_GET['action']) and in_array($_GET['action'], array('processing', 'trigger', 'pipe'))) {
$logger = create_function('$m', 'echo "<p>$m</p>\\n";');
$import = new PMXI_Import_Record();
$ids = explode(',', $_GET['import_id']);
if (!empty($ids) and is_array($ids)) {
foreach ($ids as $id) {
if (empty($id)) {
continue;
}
$import->getById($id);
if (!$import->isEmpty()) {
if (!in_array($import->type, array('url', 'ftp', 'file'))) {
$logger and call_user_func($logger, sprintf(__('Scheduling update is not working with "upload" import type. Import #%s.', 'wp_all_import_plugin'), $id));
}
switch ($_GET['action']) {
case 'trigger':
if ((int) $import->executing) {
$logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif (!$import->processing and !$import->triggered) {
$import->set(array('triggered' => 1, 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'queue_chunk_number' => 0, 'last_activity' => date('Y-m-d H:i:s')))->update();
$history_log = new PMXI_History_Record();
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => 'trigger', 'summary' => __("triggered by cron", "wp_all_import_plugin")))->save();
$logger and call_user_func($logger, sprintf(__('#%s Cron job triggered.', 'wp_all_import_plugin'), $id));
} elseif ($import->processing and !$import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s currently in process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif (!$import->processing and $import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s already triggered. Request skipped.', 'wp_all_import_plugin'), $id));
}
break;
case 'processing':
if ($import->processing == 1 and time() - strtotime($import->registered_on) > (PMXI_Plugin::getInstance()->getOption('cron_processing_time_limit') ? PMXI_Plugin::getInstance()->getOption('cron_processing_time_limit') : 120)) {
// it means processor crashed, so it will reset processing to false, and terminate. Then next run it will work normally.
$import->set(array('processing' => 0))->update();
}
// start execution imports that is in the cron process
if (!(int) $import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s is not triggered. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif ((int) $import->executing) {
$logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif ((int) $import->triggered and !(int) $import->processing) {
$log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage');
// unlink previous logs
$by = array();
$by[] = array(array('import_id' => $id, 'type NOT LIKE' => 'trigger'), 'AND');
$historyLogs = new PMXI_History_List();
$historyLogs->setColumns('id', 'import_id', 'type', 'date')->getBy($by, 'id ASC');
if ($historyLogs->count() and $historyLogs->count() >= $log_storage) {
$logsToRemove = $historyLogs->count() - $log_storage;
foreach ($historyLogs as $i => $file) {
$historyRecord = new PMXI_History_Record();
$historyRecord->getBy('id', $file['id']);
if (!$historyRecord->isEmpty()) {
$historyRecord->delete();
}
// unlink history file only
if ($i == $logsToRemove) {
break;
}
}
}
$history_log = new PMXI_History_Record();
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => 'processing', 'summary' => __("cron processing", "wp_all_import_plugin")))->save();
if ($log_storage) {
$wp_uploads = wp_upload_dir();
$log_file = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $history_log->id) . DIRECTORY_SEPARATOR . $history_log->id . '.html';
if (@file_exists($log_file)) {
wp_all_import_remove_source($log_file, false);
}
}
ob_start();
$import->set(array('canceled' => 0, 'failed' => 0))->execute($logger, true, $history_log->id);
$log_data = ob_get_clean();
if ($log_storage) {
$log = @fopen($log_file, 'a+');
@fwrite($log, $log_data);
@fclose($log);
}
if (!(int) $import->queue_chunk_number) {
$logger and call_user_func($logger, sprintf(__('Import #%s complete', 'wp_all_import_plugin'), $import->id));
} else {
//.........这里部分代码省略.........
示例3: update
/**
* Re-run import
*/
public function update()
{
$id = $this->input->get('id');
PMXI_Plugin::$session->clean_session($id);
$action_type = false;
$this->data['import'] = $item = new PMXI_Import_Record();
if (!$id or $item->getById($id)->isEmpty()) {
wp_redirect($this->baseUrl);
die;
}
$this->data['isWizard'] = false;
$default = PMXI_Plugin::get_default_import_options();
$DefaultOptions = $item->options + $default;
foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
if (class_exists($class)) {
$DefaultOptions += call_user_func(array($class, "get_default_import_options"));
}
}
$this->data['post'] =& $DefaultOptions;
$this->data['source'] = array('path' => $item->path, 'root_element' => $item->root_element);
$this->data['xpath'] = $item->xpath;
$this->data['count'] = $item->count;
$history = new PMXI_File_List();
$history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $item->id), 'id DESC');
if ($history->count()) {
foreach ($history as $file) {
if (@file_exists($file['path'])) {
$this->data['locfilePath'] = $file['path'];
break;
}
}
}
$chunks = 0;
if ($this->input->post('is_confirmed') and check_admin_referer('confirm', '_wpnonce_confirm')) {
$continue = $this->input->post('is_continue', 'no');
// mark action type ad continue
if ($continue == 'yes') {
$action_type = 'continue';
}
$filePath = '';
// upload new file in case when import is not continue
if (empty(PMXI_Plugin::$session->chunk_number)) {
if ($item->type == 'upload') {
// retrieve already uploaded file
$uploader = new PMXI_Upload(trim($item->path), $this->errors, rtrim(str_replace(basename($item->path), '', $item->path), '/'));
$upload_result = $uploader->upload();
if ($upload_result instanceof WP_Error) {
$this->errors = $upload_result;
} else {
$filePath = $upload_result['filePath'];
}
}
if (empty($item->options['encoding'])) {
$currentOptions = $item->options;
$currentOptions['encoding'] = 'UTF-8';
$item->set(array('options' => $currentOptions))->update();
}
@set_time_limit(0);
$local_paths = !empty($local_paths) ? $local_paths : array($filePath);
foreach ($local_paths as $key => $path) {
if (!empty($action_type) and $action_type == 'continue') {
$chunks = $item->count;
} else {
$file = new PMXI_Chunk($path, array('element' => $item->root_element, 'encoding' => $item->options['encoding']));
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$xml = "<?xml version=\"1.0\" encoding=\"" . $item->options['encoding'] . "\"?>" . "\n" . $xml;
$dom = new DOMDocument('1.0', !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8');
$old = libxml_use_internal_errors(true);
$dom->loadXML($xml);
// FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = @$xpath->query($item->xpath) and !empty($elements) and !empty($elements->length)) {
$chunks += $elements->length;
}
unset($dom, $xpath, $elements);
}
}
unset($file);
}
!$key and $filePath = $path;
}
if (empty($chunks)) {
$this->errors->add('form-validation', __('No matching elements found for Root element and XPath expression specified', 'wp_all_import_plugin'));
}
}
if ($chunks) {
// xml is valid
if (!PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->chunk_number)) {
// compose data to look like result of wizard steps
$sesson_data = array('filePath' => $filePath, 'source' => array('name' => $item->name, 'type' => $item->type, 'path' => $item->path, 'root_element' => $item->root_element), 'feed_type' => $item->feed_type, 'update_previous' => $item->id, 'parent_import_id' => $item->parent_import_id, 'xpath' => $item->xpath, 'options' => $item->options, 'encoding' => !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8', 'is_csv' => !empty($item->options['delimiter']) ? $item->options['delimiter'] : PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'chunk_number' => 1, 'log' => '', 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'pointer' => 1, 'count' => isset($chunks) ? $chunks : 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'action' => (!empty($action_type) and $action_type == 'continue') ? 'continue' : 'update', 'nonce' => wp_create_nonce('import'));
foreach ($sesson_data as $key => $value) {
PMXI_Plugin::$session->set($key, $value);
}
PMXI_Plugin::$session->save_data();
//.........这里部分代码省略.........
示例4: process
/**
* Import processing step (status console)
*/
public function process($save_history = true)
{
$wp_uploads = wp_upload_dir();
$import = $this->data['update_previous'];
$history_log = new PMXI_History_Record();
$input = new PMXI_Input();
if (!empty(PMXI_Plugin::$session->history_id)) {
$history_log->getById(PMXI_Plugin::$session->history_id);
}
$log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage');
if (!PMXI_Plugin::is_ajax()) {
$import->set((empty(PMXI_Plugin::$session->source) ? array() : PMXI_Plugin::$session->source) + array('xpath' => PMXI_Plugin::$session->xpath, 'options' => PMXI_Plugin::$session->options, 'count' => PMXI_Plugin::$session->count, 'friendly_name' => PMXI_Plugin::$session->options['friendly_name'], 'feed_type' => PMXI_Plugin::$session->feed_type, 'parent_import_id' => $this->data['update_previous']->isEmpty() ? PMXI_Plugin::$session->parent_import_id : $this->data['update_previous']->parent_import_id, 'queue_chunk_number' => 0, 'triggered' => 0, 'processing' => 0, 'executing' => 1, 'iteration' => !empty($import->iteration) ? $import->iteration : 0))->save();
if (PMXI_Plugin::$session->action != 'continue') {
// store import info in database
$import->set(array('imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0))->update();
}
// add history log
$custom_type = get_post_type_object($import->options['custom_type']);
// unlink previous logs
$by = array();
$by[] = array(array('import_id' => $import->id, 'type NOT LIKE' => 'trigger'), 'AND');
$historyLogs = new PMXI_History_List();
$historyLogs->setColumns('id', 'import_id', 'type', 'date')->getBy($by, 'id ASC');
if ($historyLogs->count() and $historyLogs->count() >= $log_storage) {
$logsToRemove = $historyLogs->count() - $log_storage;
foreach ($historyLogs as $i => $file) {
$historyRecord = new PMXI_History_Record();
$historyRecord->getBy('id', $file['id']);
if (!$historyRecord->isEmpty()) {
$historyRecord->delete();
}
// unlink history file only
if ($i == $logsToRemove) {
break;
}
}
}
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => PMXI_Plugin::$session->action != 'continue' ? 'manual' : 'continue', 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->save();
PMXI_Plugin::$session->set('history_id', $history_log->id);
foreach (get_taxonomies() as $tax) {
delete_transient("pmxi_{$tax}_terms");
}
do_action('pmxi_before_xml_import', $import->id);
PMXI_Plugin::$session->set('update_previous', $import->id);
if (empty($import->options['encoding'])) {
$currentOptions = $import->options;
$currentOptions['encoding'] = 'UTF-8';
$import->set(array('options' => $currentOptions))->update();
}
// unlink previous files
$history = new PMXI_File_List();
$history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $import->id), 'id DESC');
if ($history->count()) {
foreach ($history as $file) {
$history_file_path = wp_all_import_get_absolute_path($file['path']);
if (@file_exists($history_file_path) and $history_file_path != PMXI_Plugin::$session->filePath) {
if (in_array($import->type, array('upload'))) {
wp_all_import_remove_source($history_file_path, false);
} else {
wp_all_import_remove_source($history_file_path);
}
}
$history_file = new PMXI_File_Record();
$history_file->getBy('id', $file['id']);
if (!$history_file->isEmpty()) {
$history_file->delete();
}
}
}
if ($save_history) {
$history_file = new PMXI_File_Record();
$history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => wp_all_import_get_relative_path(PMXI_Plugin::$session->filePath), 'registered_on' => date('Y-m-d H:i:s')))->save();
}
/*
Split file up into 1000 record chunks.
This option will decrease the amount of slowdown experienced at the end of large imports.
The slowdown is partially caused by the need for WP All Import to read deeper and deeper into the file on each successive iteration.
Splitting the file into pieces means that, for example, instead of having to read 19000 records into a 20000 record file when importing the last 1000 records,
WP All Import will just split it into 20 chunks, and then read the last chunk from the beginning.
*/
if ("ajax" == $import->options['import_processing'] and $import->count > PMXI_Plugin::getInstance()->getOption('large_feed_limit') and $import->options['chuncking']) {
$chunk_files = array();
if (!empty(PMXI_Plugin::$session->local_paths)) {
$records_count = 0;
$chunk_records_count = 0;
$feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
foreach (PMXI_Plugin::$session->local_paths as $key => $path) {
$file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding']));
// loop through the file until all lines are read
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
$dom = new DOMDocument('1.0', $import->options['encoding']);
$old = libxml_use_internal_errors(true);
$dom->loadXML($chunk);
// FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
//.........这里部分代码省略.........
示例5: process
/**
* Step #3: Export
*/
public function process()
{
@set_time_limit(0);
$export = $this->data['update_previous'];
if (!PMXE_Plugin::is_ajax()) {
if ("" == PMXE_Plugin::$session->friendly_name) {
$friendly_name = '';
$post_types = PMXE_Plugin::$session->get('cpt');
if (!empty($post_types)) {
if (!in_array('users', $post_types)) {
$post_type_details = get_post_type_object(array_shift($post_types));
$friendly_name = $post_type_details->labels->name . ' Export - ' . date("Y F d H:i");
} else {
$friendly_name = 'Users Export - ' . date("Y F d H:i");
}
} else {
$friendly_name = 'WP_Query Export - ' . date("Y F d H:i");
}
PMXE_Plugin::$session->set('friendly_name', $friendly_name);
}
PMXE_Plugin::$session->set('file', '');
PMXE_Plugin::$session->save_data();
$export->set(array('triggered' => 0, 'processing' => 0, 'exported' => 0, 'executing' => 1, 'canceled' => 0, 'options' => PMXE_Plugin::$session->get_clear_session_data(), 'friendly_name' => PMXE_Plugin::$session->friendly_name, 'scheduled' => PMXE_Plugin::$session->is_scheduled ? PMXE_Plugin::$session->scheduled_period : '', 'registered_on' => date('Y-m-d H:i:s'), 'last_activity' => date('Y-m-d H:i:s')))->save();
$options = $export->options;
if ($options['is_generate_import'] and wp_all_export_is_compatible()) {
$import = new PMXI_Import_Record();
if (!empty($options['import_id'])) {
$import->getById($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();
PMXE_Plugin::$session->set('import_id', $import->id);
$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();
PMXE_Plugin::$session->set('import_id', $newImport->id);
$options['import_id'] = $newImport->id;
$export->set(array('options' => $options))->save();
}
}
}
PMXE_Plugin::$session->set('update_previous', $export->id);
PMXE_Plugin::$session->save_data();
}
$this->render();
}
示例6: process
/**
* Import processing step (status console)
*/
public function process($save_history = true)
{
$wp_uploads = wp_upload_dir();
$import = $this->data['update_previous'];
$logger = create_function('$m', 'echo "<div class=\\"progress-msg\\">$m</div>\\n"; if ( "" != strip_tags(pmxi_strip_tags_content($m)) and !empty(PMXI_Plugin::$session[\'pmxi_import\'][\'log\'])) { PMXI_Plugin::$session[\'pmxi_import\'][\'log\'] .= "<p>".strip_tags(pmxi_strip_tags_content($m))."</p>"; flush(); }');
if (!PMXI_Plugin::is_ajax()) {
$import->set((empty(PMXI_Plugin::$session->data['pmxi_import']['source']) ? array() : PMXI_Plugin::$session->data['pmxi_import']['source']) + array('xpath' => PMXI_Plugin::$session->data['pmxi_import']['xpath'], 'template' => PMXI_Plugin::$session->data['pmxi_import']['template'], 'options' => PMXI_Plugin::$session->data['pmxi_import']['options'], 'count' => PMXI_Plugin::$session->data['pmxi_import']['count'], 'friendly_name' => PMXI_Plugin::$session->data['pmxi_import']['options']['friendly_name'], 'feed_type' => PMXI_Plugin::$session->data['pmxi_import']['feed_type'], 'parent_import_id' => $this->data['update_previous']->isEmpty() ? PMXI_Plugin::$session->data['pmxi_import']['parent_import_id'] : $this->data['update_previous']->parent_import_id, 'queue_chunk_number' => 0, 'triggered' => 0, 'processing' => 0, 'iteration' => !empty($import->iteration) ? $import->iteration : 0))->save();
if (PMXI_Plugin::$session->data['pmxi_import']['action'] != 'continue') {
// store import info in database
$import->set(array('imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0))->update();
}
foreach (get_taxonomies() as $tax) {
delete_transient("pmxi_{$tax}_terms");
}
do_action('pmxi_before_xml_import', $import->id);
PMXI_Plugin::$session['pmxi_import']['update_previous'] = $import->id;
// unlick previous files
$history = new PMXI_File_List();
$history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $import->id), 'id DESC');
if ($history->count()) {
foreach ($history as $file) {
if (@file_exists($file['path']) and $file['path'] != PMXI_Plugin::$session->data['pmxi_import']['filePath']) {
@unlink($file['path']);
}
$history_file = new PMXI_File_Record();
$history_file->getBy('id', $file['id']);
if (!$history_file->isEmpty()) {
$history_file->delete();
}
}
}
if ($save_history) {
$history_file = new PMXI_File_Record();
$history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => PMXI_Plugin::$session->data['pmxi_import']['filePath'], 'contents' => $this->get_xml(), 'registered_on' => date('Y-m-d H:i:s')))->save();
}
/*
Split file up into 1000 record chunks.
This option will decrease the amount of slowdown experienced at the end of large imports.
The slowdown is partially caused by the need for WP All Import to read deeper and deeper into the file on each successive iteration.
Splitting the file into pieces means that, for example, instead of having to read 19000 records into a 20000 record file when importing the last 1000 records,
WP All Import will just split it into 20 chunks, and then read the last chunk from the beginning.
*/
if ("ajax" == $import->options['import_processing'] and $import->count > PMXI_Plugin::getInstance()->getOption('large_feed_limit') and $import->options['chuncking']) {
$chunk_files = array();
if (!empty(PMXI_Plugin::$session->data['pmxi_import']['local_paths'])) {
$records_count = 0;
$chunk_records_count = 0;
$feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
foreach (PMXI_Plugin::$session->data['pmxi_import']['local_paths'] as $key => $path) {
$file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding']));
// loop through the file until all lines are read
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
$dom = new DOMDocument('1.0', $import->options['encoding']);
$old = libxml_use_internal_errors(true);
$dom->loadXML($chunk);
// FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = @$xpath->query($import->xpath) and $elements->length) {
$records_count += $elements->length;
$chunk_records_count += $elements->length;
$feed .= $xml;
}
}
if ($chunk_records_count == PMXI_Plugin::getInstance()->getOption('large_feed_limit') or $records_count == $import->count) {
$feed .= "</pmxi_records>";
$chunk_file_path = $wp_uploads['path'] . "/pmxi_chunk_" . count($chunk_files) . "_" . basename($path);
file_put_contents($chunk_file_path, $feed);
$chunk_files[] = $chunk_file_path;
$chunk_records_count = 0;
$feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
}
}
}
PMXI_Plugin::$session['pmxi_import']['local_paths'] = $chunk_files;
}
}
pmxi_session_commit();
$this->render();
wp_ob_end_flush_all();
flush();
@set_time_limit(0);
if ("ajax" == $import->options['import_processing']) {
die;
}
} elseif (empty($import->id)) {
$import = new PMXI_Import_Record();
$import->getById(PMXI_Plugin::$session->data['pmxi_import']['update_previous']);
}
$ajax_processing = "ajax" == $import->options['import_processing'] ? true : false;
PMXI_Plugin::$session['pmxi_import']['start_time'] = empty(PMXI_Plugin::$session->data['pmxi_import']['start_time']) ? time() : PMXI_Plugin::$session->data['pmxi_import']['start_time'];
wp_cache_flush();
if (PMXI_Plugin::is_ajax() or !$ajax_processing) {
if ("ajax" == $import->options['import_processing']) {
//.........这里部分代码省略.........
示例7: link_template_to_import
public static function link_template_to_import(&$export, $file_path, $foundPosts)
{
$exportOptions = $export->options;
// associate exported posts with new import
if (wp_all_export_is_compatible()) {
$options = self::$templateOptions + PMXI_Plugin::get_default_import_options();
$import = new PMXI_Import_Record();
$import->getById($exportOptions['import_id']);
if (!$import->isEmpty() and $import->parent_import_id == 99999) {
$xmlPath = $file_path;
$root_element = '';
$historyPath = $file_path;
if ('csv' == $exportOptions['export_to']) {
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
$options['delimiter'] = $exportOptions['delimiter'];
include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
$path_info = pathinfo($xmlPath);
$path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
$security_folder = array_pop($path_parts);
$wp_uploads = wp_upload_dir();
$target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
$csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target));
if (!in_array($xmlPath, $exportOptions['attachment_list'])) {
$exportOptions['attachment_list'][] = $csv->xml_path;
}
$historyPath = $csv->xml_path;
$root_element = 'node';
} else {
$root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id);
}
$import->set(array('xpath' => '/' . $root_element, 'type' => 'upload', 'options' => $options, 'root_element' => $root_element, 'path' => $xmlPath, 'name' => basename($xmlPath), 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1, 'count' => $foundPosts))->save();
$history_file = new PMXI_File_Record();
$history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $historyPath, 'registered_on' => date('Y-m-d H:i:s')))->save();
$exportOptions['import_id'] = $import->id;
$export->set(array('options' => $exportOptions))->save();
}
}
}
示例8: execute
/**
* Import all files matched by path
* @param callback[optional] $logger Method where progress messages are submmitted
* @return PMXI_Import_Record
* @chainable
*/
public function execute($logger = NULL, $cron = false)
{
$this->set('registered_on', date('Y-m-d H:i:s'))->save();
// update registered_on to indicated that job has been exectured even if no files are going to be imported by the rest of the method
$wp_uploads = wp_upload_dir();
$this->set(array('processing' => 1))->update();
// lock cron requests
wp_reset_postdata();
XmlExportEngine::$exportOptions = $this->options;
XmlExportEngine::$is_user_export = $this->options['is_user_export'];
if ('advanced' == $this->options['export_type']) {
if (XmlExportEngine::$is_user_export) {
$exportQuery = eval('return new WP_User_Query(array(' . $this->options['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $this->exported . ', \'number\' => ' . $this->options['records_per_iteration'] . '));');
} else {
$exportQuery = eval('return new WP_Query(array(' . $this->options['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $this->exported . ', \'posts_per_page\' => ' . $this->options['records_per_iteration'] . '));');
}
} else {
XmlExportEngine::$post_types = $this->options['cpt'];
if (!in_array('users', $this->options['cpt'])) {
add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
$exportQuery = new WP_Query(array('post_type' => $this->options['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $this->exported, 'posts_per_page' => $this->options['records_per_iteration']));
remove_filter('posts_join', 'wp_all_export_posts_join');
remove_filter('posts_where', 'wp_all_export_posts_where');
} else {
add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
$exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => $this->options['records_per_iteration'], 'offset' => $this->exported));
remove_action('pre_user_query', 'wp_all_export_pre_user_query');
}
}
XmlExportEngine::$exportQuery = $exportQuery;
$file_path = false;
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if ($this->exported == 0) {
$import = new PMXI_Import_Record();
$import->getById($this->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();
$exportOptions = $this->options;
$exportOptions['import_id'] = $import->id;
$this->set(array('options' => $exportOptions))->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();
$exportOptions = $this->options;
$exportOptions['import_id'] = $newImport->id;
$this->set(array('options' => $exportOptions))->save();
}
}
if (!empty($this->attch_id)) {
wp_delete_attachment($this->attch_id, true);
}
$target = $is_secure_import ? wp_all_export_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY) : $wp_uploads['path'];
$file_path = $target . DIRECTORY_SEPARATOR . time() . '.' . $this->options['export_to'];
if (!$is_secure_import) {
$wp_filetype = wp_check_filetype(basename($file_path), null);
$attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path($file_path), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file_path)), 'post_content' => '', 'post_status' => 'inherit');
$attach_id = wp_insert_attachment($attachment_data, $file_path);
$this->set(array('attch_id' => $attach_id))->save();
} else {
wp_all_export_remove_source(wp_all_export_get_absolute_path($this->options['filepath']));
$exportOptions = $this->options;
$exportOptions['filepath'] = $file_path;
$this->set(array('options' => $exportOptions))->save();
}
} else {
if (!$is_secure_import) {
$file_path = str_replace($wp_uploads['baseurl'], $wp_uploads['basedir'], wp_get_attachment_url($this->attch_id));
} else {
$file_path = wp_all_export_get_absolute_path($this->options['filepath']);
}
}
$foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total();
$postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results());
// if posts still exists then export them
if ($postCount) {
switch ($this->options['export_to']) {
case 'xml':
if (!XmlExportEngine::$is_user_export) {
$exported_to_file = pmxe_export_xml($exportQuery, $this->options, false, $cron, $file_path);
} else {
$exported_to_file = pmxe_export_users_xml($exportQuery, $this->options, false, $cron, $file_path);
}
break;
case 'csv':
if (!XmlExportEngine::$is_user_export) {
$exported_to_file = pmxe_export_csv($exportQuery, $this->options, false, $cron, $file_path, $this->exported);
} else {
$exported_to_file = pmxe_export_users_csv($exportQuery, $this->options, false, $cron, $file_path, $this->exported);
}
break;
default:
# code...
//.........这里部分代码省略.........
示例9: pmxe_wp_ajax_wpallexport
/**
* AJAX action export processing
*/
function pmxe_wp_ajax_wpallexport()
{
if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
exit(__('Security check', 'wp_all_export_plugin'));
}
if (!current_user_can('manage_options')) {
exit(__('Security check', 'wp_all_export_plugin'));
}
$input = new PMXE_Input();
$export_id = $input->get('id', 0);
if (empty($export_id)) {
$export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0;
}
$wp_uploads = wp_upload_dir();
$export = new PMXE_Export_Record();
$export->getById($export_id);
if ($export->isEmpty()) {
exit(__('Export is not defined.', 'wp_all_export_plugin'));
}
$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
wp_reset_postdata();
XmlExportEngine::$exportOptions = $exportOptions;
XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
XmlExportEngine::$exportID = $export_id;
$posts_per_page = $exportOptions['records_per_iteration'];
if ('advanced' == $exportOptions['export_type']) {
if (XmlExportEngine::$is_user_export) {
exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))));
} else {
$exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
}
} else {
XmlExportEngine::$post_types = $exportOptions['cpt'];
if (!in_array('users', $exportOptions['cpt'])) {
$exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page));
} else {
exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))));
}
}
XmlExportEngine::$exportQuery = $exportQuery;
$foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total();
$postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results());
if (!$export->exported) {
$attachment_list = $export->options['attachment_list'];
if (!empty($attachment_list)) {
foreach ($attachment_list as $attachment) {
if (!is_numeric($attachment)) {
@unlink($attachment);
}
}
}
$exportOptions['attachment_list'] = array();
$export->set(array('options' => $exportOptions))->save();
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if ($is_secure_import and !empty($exportOptions['filepath'])) {
// if 'Create a new file each time export is run' disabled remove all previously generated source files
// if ( ! $exportOptions['creata_a_new_export_file'] or ! $export->iteration ){
// wp_all_export_remove_source(wp_all_export_get_absolute_path($exportOptions['filepath']));
// }
$exportOptions['filepath'] = '';
}
PMXE_Plugin::$session->set('count', $foundPosts);
PMXE_Plugin::$session->save_data();
}
// if posts still exists then export them
if ($postCount) {
switch ($exportOptions['export_to']) {
case 'xml':
pmxe_export_xml($exportQuery, $exportOptions);
break;
case 'csv':
pmxe_export_csv($exportQuery, $exportOptions);
break;
default:
# code...
break;
}
wp_reset_postdata();
}
if ($postCount) {
$export->set(array('exported' => $export->exported + $postCount))->save();
}
if ($posts_per_page != -1 and $postCount) {
wp_send_json(array('exported' => $export->exported, 'percentage' => ceil($export->exported / $foundPosts * 100), 'done' => false, 'records_per_request' => $exportOptions['records_per_iteration']));
} else {
wp_reset_postdata();
if (file_exists(PMXE_Plugin::$session->file)) {
if ($exportOptions['export_to'] == 'xml') {
file_put_contents(PMXE_Plugin::$session->file, '</' . $exportOptions['main_xml_tag'] . '>', FILE_APPEND);
}
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if (!$is_secure_import) {
if (!$export->isEmpty()) {
$wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null);
$attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path(PMXE_Plugin::$session->file), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)), 'post_content' => '', 'post_status' => 'inherit');
if (empty($export->attch_id)) {
$attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
//.........这里部分代码省略.........