本文整理汇总了PHP中PMXI_Import_Record::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP PMXI_Import_Record::clear方法的具体用法?PHP PMXI_Import_Record::clear怎么用?PHP PMXI_Import_Record::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMXI_Import_Record
的用法示例。
在下文中一共展示了PMXI_Import_Record::clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
//.........这里部分代码省略.........
}
} elseif ('file' == $this->input->post('type')) {
$uploader = new PMXI_Upload($post['file'], $this->errors);
$upload_result = $uploader->file();
if ($upload_result instanceof WP_Error) {
$this->errors = $upload_result;
} else {
$source = $upload_result['source'];
$filePath = $upload_result['filePath'];
$post['template'] = $upload_result['template'];
PMXI_Plugin::$is_csv = $upload_result['is_csv'];
if (!empty($upload_result['root_element'])) {
$post['root_element'] = $upload_result['root_element'];
}
}
}
if ($this->input->post('is_submitted') and '' == $this->input->post('custom_type')) {
$this->errors->add('form-validation', __('Select an item type to import the data', 'wp_all_import_plugin'));
}
if ($post['is_update_previous'] and empty($post['update_previous'])) {
$this->errors->add('form-validation', __('Previous import for update must be selected to proceed with a new one', 'wp_all_import_plugin'));
}
$this->data['detection_feed_extension'] = false;
$elements_cloud = array();
@set_time_limit(0);
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports';
$deligate = $this->input->get('deligate', false);
$redirect_to_template = false;
$importRecord = new PMXI_Import_Record();
switch ($deligate) {
case 'wpallexport':
global $wpdb;
$import_id = $this->input->get('id', 0);
$importRecord->clear();
$importRecord->getById($import_id);
if (!$importRecord->isEmpty() and !empty($importRecord->options['unique_key'])) {
$importRecord->set(array('path' => wp_all_import_get_relative_path($filePath), 'parent_import_id' => 0))->save();
$post['is_update_previous'] = 1;
$post['update_previous'] = $importRecord->id;
//$chunks = $importRecord->count;
$redirect_to_template = true;
}
if ($importRecord->isEmpty()) {
$this->errors->add('form-validation', __('File is no longer in the correct format', 'wp_all_import_plugin'));
} elseif (empty($importRecord->options['unique_key'])) {
$this->errors->add('form-validation', __('Certain columns are required to be present in your file to enable it to be re-imported with WP All Import. These columns are missing. Re-export your file using WP All Export, and don\'t delete any of the columns when editing it. Then, re-import will work correctly.', 'wp_all_import_plugin'));
} elseif ($importRecord->options['custom_type'] == 'import_users' && !class_exists('PMUI_Plugin')) {
$this->errors->add('form-validation', __('The import template you are using requires User Import Add-On.<br/><a href="http://www.wpallimport.com/add-ons/user-import/?utm_source=wordpress.org&utm_medium=wpai-import-template&utm_campaign=free+wp+all+export+plugin" target="_blank">Purchase the User Import Add-On</a>', 'wp_all_import_plugin'));
}
break;
default:
# code...
break;
}
$local_paths = !empty($local_paths) ? $local_paths : array($filePath);
foreach ($local_paths as $key => $path) {
if (@file_exists($path)) {
$file = new PMXI_Chunk($path, array('element' => $post['root_element'], 'get_cloud' => true));
if (!empty($file->options['element'])) {
$xpath = "/" . $file->options['element'];
$elements_cloud = $file->cloud;
if (!empty($elements_cloud) and class_exists('PMXE_Plugin') and !$importRecord->isEmpty()) {
$is_file_valid = apply_filters('wp_all_import_is_exported_file_valid', true, $importRecord->options['export_id'], $elements_cloud);
if (!$is_file_valid) {
$this->errors->add('form-validation', __('Certain columns are required to be present in your file to enable it to be re-imported with WP All Import. These columns are missing. Re-export your file using WP All Export, and don\'t delete any of the columns when editing it. Then, re-import will work correctly.', 'wp_all_import_plugin'));
}
示例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: cleanup
public function cleanup()
{
$removedFiles = 0;
$wp_uploads = wp_upload_dir();
$dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY;
$cacheDir = PMXI_Plugin::ROOT_DIR . '/libraries/cache';
$files = array_diff(@scandir($dir), array('.', '..'));
$cacheFiles = @array_diff(@scandir($cacheDir), array('.', '..'));
$msg = __('Files not found', 'wp_all_import_plugin');
if (count($files) or count($cacheFiles)) {
wp_all_import_clear_directory($dir);
wp_all_import_clear_directory($cacheDir);
$msg = __('Clean Up has been successfully completed.', 'wp_all_import_plugin');
}
// clean logs files
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'history';
global $wpdb;
$histories = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A);
if (!empty($histories)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($histories as $history) {
$importRecord->getById($history['import_id']);
if ($importRecord->isEmpty()) {
$historyRecord = new PMXI_History_Record();
$historyRecord->getById($history['id']);
if (!$historyRecord->isEmpty()) {
$historyRecord->delete();
}
}
$importRecord->clear();
}
}
// clean uploads folder
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'files';
$files = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A);
$required_dirs = array();
if (!empty($files)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($files as $file) {
$importRecord->getById($file['import_id']);
if ($importRecord->isEmpty()) {
$fileRecord = new PMXI_File_Record();
$fileRecord->getById($file['id']);
if (!$fileRecord->isEmpty()) {
$fileRecord->delete();
}
} else {
$path_parts = pathinfo(wp_all_import_get_absolute_path($file['path']));
if (!empty($path_parts['dirname'])) {
$path_all_parts = explode('/', $path_parts['dirname']);
$dirname = array_pop($path_all_parts);
if (wp_all_import_isValidMd5($dirname)) {
$required_dirs[] = $path_parts['dirname'];
}
}
}
$importRecord->clear();
}
}
$uploads_dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY;
if (($dir = @opendir($uploads_dir . DIRECTORY_SEPARATOR)) !== false or ($dir = @opendir($uploads_dir)) !== false) {
while (($file = @readdir($dir)) !== false) {
$filePath = $uploads_dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($filePath) and !in_array($filePath, $required_dirs) and !in_array($file, array('.', '..'))) {
wp_all_import_rmdir($filePath);
}
}
}
wp_redirect(add_query_arg('pmxi_nt', urlencode($msg), $this->baseUrl));
die;
}