public function dispatch() { $this->header(); if (empty($_GET['step'])) { $step = 1; } else { $step = (int) $_GET['step']; } switch ($step) { case 1: $this->step1(); break; case 2: if (isset($_GET['import-id'])) { $inserted_posts = History::get_imported_post_ids($_GET['import-id']); } else { check_admin_referer('acsv-import-upload'); set_time_limit(0); $inserted_posts = $this->step2(); } if (is_wp_error($inserted_posts)) { echo '<p>' . $inserted_posts->get_error_message() . '</p>'; } else { self::delete_form($inserted_posts); } break; case 3: check_admin_referer('acsv-import-delete'); if (isset($_POST['acsv-import-id']) && count($_POST['acsv-import-id'])) { foreach ($_POST['acsv-import-id'] as $post_id) { if (intval($post_id)) { wp_delete_post($post_id, false); } } echo '<p>'; if (count($_POST['acsv-import-id']) === 1) { echo '1 post moved to the Trash.'; } else { echo count($_POST['acsv-import-id']) . ' posts moved to the Trash.'; } echo '</p>'; } else { echo '<p>Nothing to do.</p>'; } break; } $this->footer(); }
/** * 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')); } }
/** * 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)); }