Exemple #1
0
    function view_history()
    {
        // Get list of past imports
        $ids = TI_Import::get_list();
        if (!empty($ids)) {
            krsort($ids);
        }
        $this->postbox_start(__('Import History'), 'history');
        ?>
			<?php 
        foreach ((array) $ids as $id) {
            $import = TI_Import::get($id);
            // Skip import if it's invalid...this has sometimes happened with invalid unserialize() calls - see notes for ti_delete
            if (!$import || is_wp_error($import)) {
                continue;
            }
            $date_link = "<a href='" . esc_attr(add_query_arg(array('noheader' => null, 'page' => 'ti_display', 'id' => $import->_id))) . "'>" . date("M d, Y G:i:s", $import->timestamp) . "</a>";
            $delete_link = "<a class='ti_delete_link' href='" . esc_attr(add_query_arg(array('noheader' => 'true', 'cmd' => 'delete', 'id' => $import->_id))) . "'>" . __('Delete') . "</a>";
            if ($import->status == 'COMPLETE' || $import->status == 'ERROR') {
                $undo_link = " | <a class='ti_undo_link' href='" . esc_attr(add_query_arg(array('noheader' => 'true', 'cmd' => 'undo', 'id' => $import->_id))) . "'>" . __('Undo') . "</a>";
            } else {
                $undo_link = "";
            }
            $rows[] = array('class' => null, 'data' => array($import->get_status(false, true), $import->filename, $date_link, $import->lines_total, $delete_link . $undo_link));
        }
        if (!isset($rows)) {
            $rows[] = array('class' => null, 'data' => array(__('No imports', 'turbocsv'), '', '', '', ''));
        }
        $html = "<div class='ti-large-scroll'>" . $this->option_table(array(__('Status'), __('File Name'), __('Date'), __('Lines'), __('Action')), $rows) . "</div>";
        echo $html;
        ?>
		<?php 
        $this->postbox_end();
    }
Exemple #2
0
 /**
  * Undo an entire import.  All newly-created posts and associated comments are deleted.
  * Any categories and tags that were created during the import are also
  * deleted, but only if they have no reference count once the posts/comments are gone.
  *
  * For posts that were updated (rather than created), the last revision is restored.
  * If no revisions are available then the post is deleted.
  *
  * The import profile is retained and is not deleted, but the status is set to 'UNDO'.
  *
  * The instance will update itself back to the options database.
  */
 function undo($id)
 {
     global $current_user, $blog_id;
     $original_blog_id = $blog_id;
     $import = TI_Import::get($id);
     if ($import === false) {
         return new WP_Error('ERROR', sprintf(__('Unable to read import id %s for undo'), $id));
     }
     get_currentuserinfo();
     $import->log(__("Undo started by: {$current_user->user_login}"), 'INFO');
     $import->import_start();
     foreach ((array) $import->get_imported_posts() as $post) {
         // Switch blogs if needed
         if (is_multisite() && isset($post['blog_id']) && $post['blog_id'] != $blog_id) {
             switch_to_blog($post['blog_id']);
         }
         // If post was updated during import, and revisions is on, then try to roll back to previous version
         if (defined('WP_POST_REVISIONS') && WP_POST_REVISIONS && isset($post['updated']) && $post['updated'] && isset($post['revision_id'])) {
             $result = wp_restore_post_revision($post['revision_id']);
             if (is_wp_error($result)) {
                 $import->log(sprintf(__("Unable to restore original version of post %s (%s): %s"), $post['post_title'], $post['post_id'], $result->get_error_message()));
             }
             if (!$result) {
                 $import->log(sprintf(__("Unable to restore original version of post %s (%s)"), $post['post_title'], $post['post_id']));
             }
         } else {
             // If no revisions, or post was created during import, then delete it
             $result = wp_delete_post($post['post_id']);
             if (is_wp_error($result)) {
                 $import->log(sprintf(__("Error deleting post %s (%s): %s"), $post['post_title'], $post['post_id'], $result->get_error_message()));
             }
         }
     }
     // NOTE: counts seem to be incorrect for custom taxonomies - they include deleted posts - see wordpress trac #14084, #14073, #14392
     // Delete tags, categories and custom taxonomies
     foreach ((array) $import->imported_terms as $taxonomy => $terms) {
         foreach ($terms as $term) {
             // Switch blogs if needed
             if (is_multisite() && isset($term->blog_id) && $term->blog_id != $blog_id) {
                 switch_to_blog($term->blog_id);
             }
             // Get current name in case it's changed
             $wp_term = get_term($term->term_id, $taxonomy);
             if (!is_wp_error($wp_term) && $wp_term) {
                 // get_term() returns either wp_error or null
                 $term->name = $wp_term->name;
             }
             // Term doesn't exist
             if (!$wp_term || is_wp_error($wp_term)) {
                 $import->log(sprintf(__('Could not delete term "%s" in taxonomy "%s" because it no longer exists'), $term->name, $taxonomy), 'WARNING');
                 continue;
             }
             // Term still in use
             if ($wp_term->count > 0) {
                 $import->log(sprintf(__('Term "%s" in taxonomy "%s" was not deleted because it is still in use'), $term->name, $taxonomy), 'WARNING');
                 continue;
             }
             // Delete term
             $result = wp_delete_term($term->term_id, $taxonomy);
             if (!$result) {
                 $import->log(sprintf(__('Uknown error deleting term "%s" in taxonomy "%s"'), $term->name, $taxonomy), 'ERROR');
             }
             if (is_wp_error($result)) {
                 $import->log(sprintf(__('Error deleting term "%s" in taxonomy "%s" : "%s"'), $term->name, $taxonomy, $result->get_error_message()), 'ERROR');
             }
         }
     }
     // Switch back to original blog before writing out the import logs to the database
     if ($original_blog_id != $blog_id) {
         switch_to_blog($original_blog_id);
     }
     // Update terms cache
     $import->clean_term_cache();
     // Set status and save back to db
     $import->log(__('Undo finished.'), 'INFO');
     $import->status = 'UNDO';
     $import->save();
     return true;
 }