admin_head.php
11 years ago
admin_init.php
11 years ago
admin_menu.php
11 years ago
admin_notices.php
11 years ago
delete_post.php
11 years ago
plugins_loaded.php
11 years ago
wp.php
11 years ago
wp_ajax_auto_detect_cf.php
11 years ago
wp_ajax_auto_detect_sf.php
11 years ago
wp_ajax_import_failed.php
11 years ago
wp_ajax_nested_merge.php
11 years ago
wp_ajax_nested_xpath.php
11 years ago
wp_ajax_parse_nested_file.php
11 years ago
wp_ajax_test_images.php
11 years ago
wp_ajax_unmerge_file.php
11 years ago
wp_loaded.php
11 years ago
wp_loaded.php
179 lines
| 1 | <?php |
| 2 | |
| 3 | function pmxi_wp_loaded() { |
| 4 | |
| 5 | @ini_set("max_input_time", PMXI_Plugin::getInstance()->getOption('max_input_time')); |
| 6 | @ini_set("max_execution_time", PMXI_Plugin::getInstance()->getOption('max_execution_time')); |
| 7 | |
| 8 | $table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports'; |
| 9 | global $wpdb; |
| 10 | $imports = $wpdb->get_results("SELECT `id`, `name`, `path` FROM $table WHERE `path` IS NULL", ARRAY_A); |
| 11 | |
| 12 | if ( ! empty($imports) ){ |
| 13 | |
| 14 | $importRecord = new PMXI_Import_Record(); |
| 15 | $importRecord->clear(); |
| 16 | foreach ($imports as $imp) { |
| 17 | $importRecord->getById($imp['id']); |
| 18 | if ( ! $importRecord->isEmpty()){ |
| 19 | $importRecord->delete( true ); |
| 20 | } |
| 21 | $importRecord->clear(); |
| 22 | } |
| 23 | |
| 24 | } |
| 25 | |
| 26 | /* Check if cron is manualy, then execute import */ |
| 27 | $cron_job_key = PMXI_Plugin::getInstance()->getOption('cron_job_key'); |
| 28 | |
| 29 | 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'))) { |
| 30 | |
| 31 | $logger = create_function('$m', 'echo "<p>$m</p>\\n";'); |
| 32 | |
| 33 | $import = new PMXI_Import_Record(); |
| 34 | |
| 35 | $ids = explode(',', $_GET['import_id']); |
| 36 | |
| 37 | if (!empty($ids) and is_array($ids)){ |
| 38 | |
| 39 | foreach ($ids as $id) { if (empty($id)) continue; |
| 40 | |
| 41 | $import->getById($id); |
| 42 | |
| 43 | if ( ! $import->isEmpty() ){ |
| 44 | |
| 45 | if ( ! in_array($import->type, array('url', 'ftp', 'file')) ) { |
| 46 | $logger and call_user_func($logger, sprintf(__('Scheduling update is not working with "upload" import type. Import #%s.', 'pmxi_plugin'), $id)); |
| 47 | } |
| 48 | |
| 49 | switch ($_GET['action']) { |
| 50 | |
| 51 | case 'trigger': |
| 52 | |
| 53 | if ( (int) $import->executing ){ |
| 54 | $logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'pmxi_plugin'), $id)); |
| 55 | } |
| 56 | elseif ( ! $import->processing and ! $import->triggered ){ |
| 57 | |
| 58 | $import->set(array( |
| 59 | 'triggered' => 1, |
| 60 | 'imported' => 0, |
| 61 | 'created' => 0, |
| 62 | 'updated' => 0, |
| 63 | 'skipped' => 0, |
| 64 | 'deleted' => 0, |
| 65 | 'queue_chunk_number' => 0, |
| 66 | 'last_activity' => date('Y-m-d H:i:s') |
| 67 | ))->update(); |
| 68 | |
| 69 | $history_log = new PMXI_History_Record(); |
| 70 | $history_log->set(array( |
| 71 | 'import_id' => $import->id, |
| 72 | 'date' => date('Y-m-d H:i:s'), |
| 73 | 'type' => 'trigger', |
| 74 | 'summary' => __("triggered by cron", "pmxi_plugin") |
| 75 | ))->save(); |
| 76 | |
| 77 | $logger and call_user_func($logger, sprintf(__('#%s Cron job triggered.', 'pmxi_plugin'), $id)); |
| 78 | |
| 79 | } |
| 80 | elseif( $import->processing and ! $import->triggered) { |
| 81 | $logger and call_user_func($logger, sprintf(__('Import #%s currently in process. Request skipped.', 'pmxi_plugin'), $id)); |
| 82 | } |
| 83 | elseif( ! $import->processing and $import->triggered){ |
| 84 | $logger and call_user_func($logger, sprintf(__('Import #%s already triggered. Request skipped.', 'pmxi_plugin'), $id)); |
| 85 | } |
| 86 | |
| 87 | break; |
| 88 | |
| 89 | case 'processing': |
| 90 | |
| 91 | 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. |
| 92 | $import->set(array( |
| 93 | 'processing' => 0 |
| 94 | ))->update(); |
| 95 | } |
| 96 | |
| 97 | // start execution imports that is in the cron process |
| 98 | if ( ! (int) $import->triggered ){ |
| 99 | $logger and call_user_func($logger, sprintf(__('Import #%s is not triggered. Request skipped.', 'pmxi_plugin'), $id)); |
| 100 | } |
| 101 | elseif ( (int) $import->executing ){ |
| 102 | $logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'pmxi_plugin'), $id)); |
| 103 | } |
| 104 | elseif ( (int) $import->triggered and ! (int) $import->processing ){ |
| 105 | |
| 106 | $log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage'); |
| 107 | |
| 108 | // unlink previous logs |
| 109 | $by = array(); |
| 110 | $by[] = array(array('import_id' => $id, 'type NOT LIKE' => 'trigger'), 'AND'); |
| 111 | $historyLogs = new PMXI_History_List(); |
| 112 | $historyLogs->setColumns('id', 'import_id', 'type', 'date')->getBy($by, 'id ASC'); |
| 113 | if ($historyLogs->count() and $historyLogs->count() >= $log_storage ){ |
| 114 | $logsToRemove = $historyLogs->count() - $log_storage; |
| 115 | foreach ($historyLogs as $i => $file){ |
| 116 | $historyRecord = new PMXI_History_Record(); |
| 117 | $historyRecord->getBy('id', $file['id']); |
| 118 | if ( ! $historyRecord->isEmpty()) $historyRecord->delete( false ); // unlink history file only |
| 119 | if ($i == $logsToRemove) |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | $history_log = new PMXI_History_Record(); |
| 125 | $history_log->set(array( |
| 126 | 'import_id' => $import->id, |
| 127 | 'date' => date('Y-m-d H:i:s'), |
| 128 | 'type' => 'processing', |
| 129 | 'summary' => __("cron processing", "pmxi_plugin") |
| 130 | ))->save(); |
| 131 | |
| 132 | if ($log_storage){ |
| 133 | $wp_uploads = wp_upload_dir(); |
| 134 | $log_file = pmxi_secure_file( $wp_uploads['basedir'] . "/wpallimport/logs", 'logs', $history_log->id ) . '/' . $history_log->id . '.html'; |
| 135 | if ( @file_exists($log_file) ) pmxi_remove_source($log_file, false); |
| 136 | } |
| 137 | |
| 138 | ob_start(); |
| 139 | |
| 140 | $import->set(array('canceled' => 0, 'failed' => 0))->execute($logger, true, $history_log->id); |
| 141 | |
| 142 | $log_data = ob_get_clean(); |
| 143 | |
| 144 | if ($log_storage){ |
| 145 | $log = @fopen($log_file, 'a+'); |
| 146 | @fwrite($log, $log_data); |
| 147 | @fclose($log); |
| 148 | } |
| 149 | |
| 150 | if ( ! (int) $import->queue_chunk_number ){ |
| 151 | |
| 152 | $logger and call_user_func($logger, sprintf(__('Import #%s complete', 'pmxi_plugin'), $import->id)); |
| 153 | |
| 154 | } |
| 155 | else{ |
| 156 | |
| 157 | $logger and call_user_func($logger, sprintf(__('Records Count %s', 'pmxi_plugin'), (int) $import->count)); |
| 158 | $logger and call_user_func($logger, sprintf(__('Records Processed %s', 'pmxi_plugin'), (int) $import->queue_chunk_number)); |
| 159 | |
| 160 | } |
| 161 | |
| 162 | } |
| 163 | else { |
| 164 | $logger and call_user_func($logger, sprintf(__('Import #%s already processing. Request skipped.', 'pmxi_plugin'), $id)); |
| 165 | } |
| 166 | |
| 167 | break; |
| 168 | case 'pipe': |
| 169 | |
| 170 | $import->execute($logger); |
| 171 | |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | } |