/** * Display importing log. * * ## OPTIONS * * [<id>] * : The ID of the log. * * [--format=<format>] * : Accepted values: table, csv, json, count, ids. Default: table */ function log($args, $assoc_args) { if (isset($assoc_args['format'])) { $format = $assoc_args['format']; } else { $format = 'table'; } if (isset($args[0]) && $args[0]) { $ids = History::get_imported_post_ids($args[0]); if ($ids) { if ('ids' === $format) { echo implode(' ', $ids); } else { $this->get_imported_data($ids, $format); } } else { WP_CLI::warning('Not found.'); } } else { $history = History::get_history(true); WP_CLI\Utils\format_items('table', $history, array('ID', 'Title', 'Date', 'Success', 'Failure')); } }
/** * The form of the first step. * * @param none * @return none */ private function step1() { $bytes = apply_filters('acsv_import_upload_size_limit', wp_max_upload_size()); $size = size_format($bytes); $upload_dir = wp_upload_dir(); echo '<div class="narrow">'; if (!empty($upload_dir['error'])) { ?> <div class="error"> <p><?php _e('Before you can upload your import file, you will need to fix the following error:', 'advanced-csv-importer'); ?> </p> <p><strong><?php echo $upload_dir['error']; ?> </strong></p> </div> <?php return; } ?> <form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url(add_query_arg(array('step' => 2), $this->get_action())); ?> "> <p> <label for="upload"><?php _e('Choose a .csv file from your computer.', 'advanced-csv-importer'); ?> </label><br />(<?php printf(__('Maximum size: %s'), $size); ?> ) </p> <p> <input type="file" id="upload" name="import" size="25" /> <input type="hidden" name="action" value="save" /> <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?> " /> <?php wp_nonce_field('acsv-import-upload'); ?> </p> <?php submit_button(__('Upload file and import'), 'advanced-csv-importer'); ?> </form> <h3>History</h3> <?php $history = History::get_history(); ?> <table class="wp-list-table widefat fixed posts"> <thead><tr style="color: #dedede;"> <th scope="col" style="width: 15%;">ID</th> <th scope="col" style="">Title</th> <th scope="col" style="">Date</th> <th scope="col" style="width: 15%;">Success</th> <th scope="col" style="width: 15%;">Failure</th> </tr></thead> <?php foreach ($history as $log) { ?> <tr style="color: #dedede;"> <td><a href="<?php echo add_query_arg(array('step' => 2, 'import-id' => $log['ID']), admin_url('admin.php?import=advanced-csv-importer')); ?> "><?php echo esc_html($log['ID']); ?> </a></td> <td><?php echo esc_html($log['Title']); ?> </td> <td><?php echo esc_html($log['Date']); ?> </td> <td><?php echo esc_html($log['Success']); ?> </td> <td><?php echo esc_html($log['Failure']); ?> </td> </tr> <?php } ?> </table> <?php echo '</div>'; }
/** * Importing author and title. * * @test */ public function insert_posts_author() { $posts = array(array('post_author' => 'admin', 'post_title' => 'original post'), array('post_author' => 'foo', 'post_title' => 'original post'), array('post_author' => 'bar', 'post_title' => 'original post')); $inserted_posts = \ACSV\Main::insert_posts($posts); for ($i = 0; $i < count($inserted_posts); $i++) { $post = get_post($inserted_posts[$i]); $this->assertSame("1", $post->post_author, $posts[$i]['post_author'] . ' should be 1.'); } $logs = \ACSV\History::get_history(); $this->assertEquals(1, count($logs)); $log_name = \ACSV\History::get_log_name($inserted_posts); $log = \ACSV\History::get_imported_post_ids($log_name); $this->assertEquals(3, count($log)); }