/**
  * Parses the XML file and prepares us for the task of processing parsed data
  *
  * @param string $file Path to the WXR file for importing
  */
 function import_start($file)
 {
     if (!is_file($file)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo __('The file does not exist, please try again.', 'anno') . '</p>';
         $this->footer();
         die;
     }
     $import_data = $this->parse($file);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         $this->footer();
         die;
     }
     $this->version = $import_data['version'];
     $this->get_authors_from_import($import_data);
     $this->posts = $import_data['posts'];
     $this->terms = $import_data['terms'];
     $this->categories = $import_data['categories'];
     $this->tags = $import_data['tags'];
     $this->base_url = esc_url($import_data['base_url']);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     do_action('import_start');
 }
 function import_start($file)
 {
     if (!is_file($file)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br/>';
         echo __('The file does not exist, please try again.', 'wordpress-importer') . '</p>';
         $this->footer();
         die;
     }
     $import_data = $this->parse($file);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br/>';
         echo esc_html($import_data->get_error_message()) . '</p>';
         $this->footer();
         die;
     }
     $this->version = $import_data['version'];
     $this->get_authors_from_import($import_data);
     $this->posts = $import_data['posts'];
     $this->terms = $import_data['terms'];
     $this->categories = $import_data['categories'];
     $this->tags = $import_data['tags'];
     $this->base_url = esc_url($import_data['base_url']);
     // fix for: 'http://localhost/justmarriedmarried' = str_replace('http://localhost/just', 'http://localhost/justmarried', 'http://localhost/justmarried')
     $this->wrong_replace = network_home_url() !== ($wrong_replace = str_replace($this->base_url, network_home_url(), network_home_url())) ? $wrong_replace : false;
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     do_action('import_start');
     // deprecated
     do_action('tf_ext_import_start');
 }
Example #3
0
 function import_end()
 {
     // Switch off importing flag and flush rewrite cache
     wp_defer_term_counting(false);
     wp_defer_comment_counting(true);
     global $wp_rewrite;
     $wp_rewrite->flush_rules();
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     do_action('import_end');
 }
 public function import_end()
 {
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a>' . '</p>';
     echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>';
     do_action('import_end');
 }
Example #6
0
 /**
  * Parses the XML file and prepares us for the task of processing parsed data
  *
  * @param string $file Path to the WXR file for importing
  */
 function import_start($file)
 {
     if (!is_file($file)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo __('The file does not exist, please try again.', 'anno') . '</p>';
         $this->footer();
         die;
     }
     $import_data = $this->parse($file);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         $this->footer();
         die;
     }
     // Validation error likely
     if (isset($import_data['status']) && $import_data['status'] == 'error') {
         echo '<h3>' . __('There were the following errors while trying to validate your XML. Please correct them and try again.', 'anno') . '</h3>';
         foreach ($import_data['errors'] as $error) {
             $error_lines[] = $error['line'];
             echo '<div class="error">' . $error['fullMessage'] . '.</div>';
         }
         $this->output_XML($import_data['content'], $error_lines);
         $this->footer();
         die;
     }
     $this->version = $import_data['version'];
     $this->get_authors_from_import($import_data);
     $this->posts = $import_data['posts'];
     $this->terms = $import_data['terms'];
     $this->categories = $import_data['categories'];
     $this->tags = $import_data['tags'];
     $this->base_url = esc_url($import_data['base_url']);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     do_action('import_start');
 }
function cherry_plugin_import_end()
{
    wp_cache_flush();
    foreach (get_taxonomies() as $tax) {
        delete_option("{$tax}_children");
        _get_term_hierarchy($tax);
    }
    wp_defer_term_counting(false);
    wp_defer_comment_counting(false);
    update_option('cherry_sample_data', 1);
    cherry_plugin_set_to_draft('hello-world');
    cherry_plugin_set_to_draft('sample-page');
    settings();
    do_action('cherry_plugin_import_end');
    session_name("import_xml");
    session_destroy();
    exit('import_json');
}
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a></p>';
     echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>';
     do_action('import_end');
     // deprecated
     do_action('tf_ext_import_end', array('version' => @$this->version, 'authors' => @$this->authors, 'posts' => @$this->posts, 'terms' => @$this->terms, 'categories' => @$this->categories, 'tags' => @$this->tags, 'base_url' => @$this->base_url, 'processed_authors' => @$this->processed_authors, 'author_mapping' => @$this->author_mapping, 'processed_terms' => @$this->processed_terms, 'processed_posts' => @$this->processed_posts, 'post_orphans' => @$this->post_orphans, 'processed_menu_items' => @$this->processed_menu_items, 'menu_item_orphans' => @$this->menu_item_orphans, 'missing_menu_items' => @$this->missing_menu_items, 'fetch_attachments' => @$this->fetch_attachments, 'url_remap' => @$this->url_remap, 'featured_images' => @$this->featured_images, 'old_site_url' => @$this->old_site_url, 'new_site_url' => @$this->new_site_url, 'upload_url_old' => @$this->upload_url_old, 'install_url' => @$this->install_url, 'tfuse_options' => @$this->tfuse_options));
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 public function import_end()
 {
     wp_cache_flush();
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     do_action('import_end');
 }
Example #10
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('Import complete.', 'wc_customer_relationship_manager') . '</p>';
     echo '<p>' . sprintf(_n('%d Customer has been successfully added.', '%d Customers has been successfully added.', $this->row, 'wc_customer_relationship_manager'), $this->row) . '</p>';
     if (!empty($this->groups_added)) {
         echo '<p>' . sprintf(_n('%d Group has been successfully added.', '%d Groups has been successfully added.', count($this->groups_added), 'wc_customer_relationship_manager'), count($this->groups_added)) . ' (' . implode(', ', $this->groups_added) . ')</p>';
     }
     if (!empty($this->statuses_added)) {
         echo '<p>' . sprintf(_n('%d Customer status has been successfully added.', '%d Customer statuses has been successfully added.', count($this->statuses_added), 'wc_customer_relationship_manager'), count($this->statuses_added)) . ' (' . implode(', ', $this->statuses_added) . ')</p>';
     }
     if (!empty($this->not_import)) {
         echo '<p>' . sprintf(_n('%d Customer  was not added.', '%d Customers  was not added.', count($this->not_import), 'wc_customer_relationship_manager'), count($this->not_import)) . '</p>';
         echo '<code>';
         foreach ($this->not_import as $key => $value) {
             echo $value[0] . '<br>';
         }
         echo '</code>';
     }
     do_action('wcrm_import_end');
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     wp_cache_flush();
     $taxonomies = get_taxonomies();
     foreach ($taxonomies as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
         $args = array('hide_empty' => 0, 'fields' => 'ids');
         $terms = get_terms($tax, $args);
         if (is_array($terms) && !empty($terms)) {
             wp_update_term_count_now($terms, $tax);
         }
     }
     do_action('import_end');
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'wordpress-importer') . '</p>';
     do_action('import_end');
 }
 public function enable_comment_counting()
 {
     wp_defer_comment_counting(false);
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 public function import_end()
 {
     //wp_cache_flush(); Stops output in some hosting environments
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     do_action('import_end');
 }
 function status_changes_convert_questions($n = 50, $offset = 0)
 {
     global $wpdb;
     wp_defer_comment_counting(true);
     $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->users} ");
     if (0 == $user_count_result) {
         return true;
     }
     // Calculate if this is the last page
     if (0 == $offset) {
         $current_page = 1;
     } else {
         $current_page = intval($offset / $n);
     }
     $total_pages = ceil($user_count_result / $n);
     $users_sql = "SELECT ID FROM {$wpdb->users} ORDER BY ID ASC LIMIT %d OFFSET %d";
     $answers_sql = "SELECT * FROM {$wpdb->comments} WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID ";
     $grades_sql = "SELECT comment_post_ID, comment_content FROM {$wpdb->comments} WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID ";
     $notes_sql = "SELECT comment_post_ID, comment_content FROM {$wpdb->comments} WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID ";
     $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
     foreach ($user_ids as $user_id) {
         $answer_grades = $answer_notes = array();
         // Pre-process the answer grades
         $_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A);
         foreach ($_answer_grades as $answer_grade) {
             // This will overwrite existing entries with the newer ones
             $answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content'];
         }
         unset($_answer_grades);
         // Pre-process the answer notes
         $_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A);
         foreach ($_answer_notes as $answer_note) {
             // This will overwrite existing entries with the newer ones
             $answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content'];
         }
         unset($_answer_notes);
         // Grab all the questions for the user
         $sql = $wpdb->prepare($answers_sql, $user_id);
         $answers = $wpdb->get_results($sql, ARRAY_A);
         foreach ($answers as $answer) {
             // Excape data
             $answer = wp_slash($answer);
             $comment_ID = $answer['comment_ID'];
             $meta_data = array();
             // Check if the question has been graded, add as meta
             if (!empty($answer_grades[$answer['comment_post_ID']])) {
                 $meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']];
             }
             // Check if there is an answer note, add as meta
             if (!empty($answer_notes[$answer['comment_post_ID']])) {
                 $meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']];
             }
             // Wipe the unnessary data from the main comment
             $data = array('comment_author' => '', 'comment_author_email' => '', 'comment_author_url' => '', 'comment_author_IP' => '', 'comment_agent' => '');
             $data = array_merge($answer, $data);
             $rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID'));
             if ($rval) {
                 if (!empty($meta_data)) {
                     foreach ($meta_data as $key => $value) {
                         // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
                         if ($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE comment_id = %d AND meta_key = %s ", $comment_ID, $key))) {
                             continue;
                             // Found the meta data already
                         }
                         $result = $wpdb->insert($wpdb->commentmeta, array('comment_id' => $comment_ID, 'meta_key' => $key, 'meta_value' => $value));
                     }
                 }
             }
         }
     }
     $wpdb->flush();
     if ($current_page == $total_pages) {
         return true;
     } else {
         return false;
     }
 }
Example #16
0
 /**
  * Parses the XML response, deletes existing CPTs, and imports CCB data
  *
  * @param     mixed    $full_response
  * @since     0.9.0
  * @access    protected
  * @return    void
  */
 protected function import_cpts($full_response)
 {
     global $wpdb;
     // temporarily disable counting for performance
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     // temporarily disable autocommit
     $wpdb->query('SET autocommit = 0;');
     // GROUP PROFILES
     if ($this->enabled_apis['group_profiles'] == true && isset($full_response['group_profiles']->response->groups->group) && !empty($full_response['group_profiles']->response->groups->group)) {
         $groups_taxonomy_map = CCB_Core_CPTs::get_groups_taxonomy_map();
         $groups_custom_fields_map = CCB_Core_CPTs::get_groups_custom_fields_map();
         // delete the existing taxonomy terms
         foreach ($groups_taxonomy_map as $taxonomy_name => $taxonomy) {
             $terms = get_terms($taxonomy_name, array('fields' => 'ids', 'hide_empty' => false));
             if (!empty($terms)) {
                 foreach ($terms as $term_value) {
                     wp_delete_term($term_value, $taxonomy_name);
                 }
             }
         }
         // delete existing custom posts
         $custom_posts = get_posts(array('post_type' => $this->plugin_name . '-groups', 'posts_per_page' => -1));
         foreach ($custom_posts as $custom_post) {
             wp_delete_post($custom_post->ID, true);
         }
         // commit the deletes now
         $wpdb->query('COMMIT;');
         foreach ($full_response['group_profiles']->response->groups->group as $group) {
             // only allow publicly listed and active groups to be imported
             if ($group->inactive == 'false' && $group->public_search_listed == 'true') {
                 $group_id = 0;
                 foreach ($group->attributes() as $key => $value) {
                     if ($key == 'id') {
                         $group_id = (int) $value;
                         break;
                     }
                 }
                 // insert group post
                 $group_post_atts = array('post_title' => $group->name, 'post_name' => $group->name, 'post_content' => $group->description, 'post_status' => 'publish', 'post_type' => $this->plugin_name . '-groups');
                 $post_id = wp_insert_post($group_post_atts);
                 // insert hierarchial taxonomy values (categories) and non-hierarchial taxonomy values (tags)
                 $taxonomy_atts = $this->get_taxonomy_atts($group, $groups_taxonomy_map);
                 if (!empty($taxonomy_atts)) {
                     foreach ($taxonomy_atts as $taxonomy_attribute) {
                         wp_set_post_terms($post_id, $taxonomy_attribute['terms'], $taxonomy_attribute['taxonomy'], true);
                     }
                 }
                 // insert custom fields
                 $custom_fields_atts = $this->get_custom_fields_atts($group, $groups_custom_fields_map);
                 if (!empty($custom_fields_atts)) {
                     foreach ($custom_fields_atts as $custom_fields_attribute) {
                         add_post_meta($post_id, $custom_fields_attribute['field_name'], $custom_fields_attribute['field_value']);
                     }
                 }
             }
         }
         // commit the inserts now
         $wpdb->query('COMMIT;');
     }
     // PUBLIC CALENDAR LISTING
     if ($this->enabled_apis['public_calendar_listing'] == true && isset($full_response['public_calendar_listing']->response->items->item) && !empty($full_response['public_calendar_listing']->response->items->item)) {
         $calendar_taxonomy_map = CCB_Core_CPTs::get_calendar_taxonomy_map();
         $calendar_custom_fields_map = CCB_Core_CPTs::get_calendar_custom_fields_map();
         // delete the existing taxonomy terms
         foreach ($calendar_taxonomy_map as $taxonomy_name => $taxonomy) {
             $terms = get_terms($taxonomy_name, array('fields' => 'ids', 'hide_empty' => false));
             if (!empty($terms)) {
                 foreach ($terms as $term_value) {
                     wp_delete_term($term_value, $taxonomy_name);
                 }
             }
         }
         // delete existing custom posts
         $custom_posts = get_posts(array('post_type' => $this->plugin_name . '-calendar', 'posts_per_page' => -1));
         foreach ($custom_posts as $custom_post) {
             wp_delete_post($custom_post->ID, true);
         }
         // commit the deletes now
         $wpdb->query('COMMIT;');
         foreach ($full_response['public_calendar_listing']->response->items->item as $event) {
             // insert event post
             $event_post_atts = array('post_title' => $event->event_name, 'post_name' => $event->event_name, 'post_content' => $event->event_description, 'post_status' => 'publish', 'post_type' => $this->plugin_name . '-calendar');
             $post_id = wp_insert_post($event_post_atts);
             // insert hierarchial taxonomy values (categories) and non-hierarchial taxonomy values (tags)
             $taxonomy_atts = $this->get_taxonomy_atts($event, $calendar_taxonomy_map);
             if (!empty($taxonomy_atts)) {
                 foreach ($taxonomy_atts as $taxonomy_attribute) {
                     wp_set_post_terms($post_id, $taxonomy_attribute['terms'], $taxonomy_attribute['taxonomy'], true);
                 }
             }
             // insert custom fields
             $custom_fields_atts = $this->get_custom_fields_atts($event, $calendar_custom_fields_map);
             if (!empty($custom_fields_atts)) {
                 foreach ($custom_fields_atts as $custom_fields_attribute) {
                     add_post_meta($post_id, $custom_fields_attribute['field_name'], $custom_fields_attribute['field_value']);
                 }
             }
         }
         // commit the inserts now
         $wpdb->query('COMMIT;');
     }
     // re-enable autocommit
     $wpdb->query('SET autocommit = 1;');
     // re-enable counting
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
 }
Example #17
0
        /**
         * Performs post-import cleanup of files and the cache
         */
        function import_end()
        {
            wp_import_cleanup($this->id);
            wp_cache_flush();
            foreach (get_taxonomies() as $tax) {
                delete_option("{$tax}_children");
                _get_term_hierarchy($tax);
            }
            wp_defer_term_counting(false);
            wp_defer_comment_counting(false);
            echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a>' . '</p>';
            echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>';
            if ($this->one_click) {
                $main_menu = get_term_by('slug', 'main-menu', 'nav_menu');
                $top_menu = get_term_by('slug', 'top-menu', 'nav_menu');
                $footer_menu = get_term_by('slug', 'menu-footer', 'nav_menu');
                $menu_locations = get_theme_mod('nav_menu_locations');
                if ($main_menu) {
                    $menu_locations['menu-header'] = $main_menu->term_id;
                }
                if ($top_menu) {
                    $menu_locations['menu-top'] = $top_menu->term_id;
                }
                if ($footer_menu) {
                    $menu_locations['menu-footer'] = $footer_menu->term_id;
                }
                set_theme_mod('nav_menu_locations', $menu_locations);
                if ($this->front_page) {
                    update_option('page_on_front', $this->processed_posts[intval($this->front_page)]);
                    update_option('show_on_front', 'page');
                }
                $quick_setup = admin_url('admin.php?page=wpv_import');
                echo <<<REDIRECT
\t\t\t<script>
\t\t\t\t/*<![CDATA[*/
\t\t\t\tsetTimeout(function() {
\t\t\t\t\twindow.location = '{$quick_setup}';
\t\t\t\t}, 3000);
\t\t\t\t/*]]>*/
\t\t\t</script>
REDIRECT;
            }
            do_action('import_end');
        }
Example #18
0
 /**
  * Import the PHPDoc $data into WordPress posts and taxonomies
  *
  * @param array $data
  * @param bool  $skip_sleep               Optional; defaults to false. If true, the sleep() calls are skipped.
  * @param bool  $import_ignored_functions Optional; defaults to false. If true, functions marked `@ignore` will be imported.
  */
 public function import(array $data, $skip_sleep = false, $import_ignored_functions = false)
 {
     global $wpdb;
     $time_start = microtime(true);
     $num_queries = $wpdb->num_queries;
     $this->logger->info('Starting import. This will take some time…');
     $file_number = 1;
     $num_of_files = count($data);
     do_action('wp_parser_starting_import');
     // Defer term counting for performance
     wp_suspend_cache_invalidation(true);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     // Remove actions for performance
     remove_action('transition_post_status', '_update_blog_date_on_post_publish', 10);
     remove_action('transition_post_status', '__clear_multi_author_cache', 10);
     delete_option('wp_parser_imported_wp_version');
     delete_option('wp_parser_root_import_dir');
     // Sanity check -- do the required post types exist?
     if (!post_type_exists($this->post_type_class) || !post_type_exists($this->post_type_function) || !post_type_exists($this->post_type_hook)) {
         $this->logger->error(sprintf('Missing post type; check that "%1$s", "%2$s", and "%3$s" are registered.', $this->post_type_class, $this->post_type_function, $this->post_type_hook));
         exit;
     }
     // Sanity check -- do the required taxonomies exist?
     if (!taxonomy_exists($this->taxonomy_file) || !taxonomy_exists($this->taxonomy_since_version) || !taxonomy_exists($this->taxonomy_package)) {
         $this->logger->error(sprintf('Missing taxonomy; check that "%1$s" is registered.', $this->taxonomy_file));
         exit;
     }
     $root = '';
     foreach ($data as $file) {
         $this->logger->info(sprintf('Processing file %1$s of %2$s "%3$s".', number_format_i18n($file_number), number_format_i18n($num_of_files), $file['path']));
         $file_number++;
         $this->import_file($file, $skip_sleep, $import_ignored_functions);
         if (empty($root) && (isset($file['root']) && $file['root'])) {
             $root = $file['root'];
         }
     }
     if (!empty($root)) {
         update_option('wp_parser_root_import_dir', $root);
         $this->logger->info('Updated option wp_parser_root_import_dir: ' . $root);
     }
     $last_import = time();
     $import_date = date_i18n(get_option('date_format'), $last_import);
     $import_time = date_i18n(get_option('time_format'), $last_import);
     update_option('wp_parser_last_import', $last_import);
     $this->logger->info(sprintf('Updated option wp_parser_last_import: %1$s at %2$s.', $import_date, $import_time));
     $wp_version = get_option('wp_parser_imported_wp_version');
     if ($wp_version) {
         $this->logger->info('Updated option wp_parser_imported_wp_version: ' . $wp_version);
     }
     /**
      * Workaround for a WP core bug where hierarchical taxonomy caches are not being cleared
      *
      * https://core.trac.wordpress.org/ticket/14485
      * http://wordpress.stackexchange.com/questions/8357/inserting-terms-in-an-hierarchical-taxonomy
      */
     delete_option("{$this->taxonomy_package}_children");
     delete_option("{$this->taxonomy_since_version}_children");
     /**
      * Action at the end of a complete import
      */
     do_action('wp_parser_ending_import');
     // Start counting again
     wp_defer_term_counting(false);
     wp_suspend_cache_invalidation(false);
     wp_cache_flush();
     wp_defer_comment_counting(false);
     $time_end = microtime(true);
     $time = $time_end - $time_start;
     $this->logger->info('Time: ' . $time);
     $this->logger->info('Queries: ' . ($wpdb->num_queries - $num_queries));
     if (empty($this->errors)) {
         $this->logger->notice('Import complete!');
     } else {
         $this->logger->info('Import complete, but some errors were found:');
         foreach ($this->errors as $error) {
             $this->logger->error($error);
         }
     }
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 protected function import_end()
 {
     // Re-enable stuff in core
     wp_suspend_cache_invalidation(false);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     /**
      * Complete the import.
      *
      * Fires after the import process has finished. If you need to update
      * your cache or re-enable processing, do so here.
      */
     do_action('import_end');
 }
 function import_end()
 {
     do_action('import_end');
     // clear the caches after backfilling
     foreach ($this->post_ids_processed as $post_id) {
         clean_post_cache($post_id);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
 }
Example #21
0
 function defer_counting($bool)
 {
     wp_defer_term_counting($bool);
     wp_defer_comment_counting($bool);
 }
 /**
  * Delete table
  *
  * @return bool
  */
 public function delete_table($data)
 {
     if (empty($data)) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Please select a table!', 'go_pricing_textdomain'));
         return;
     }
     $cnt = 0;
     global $wpdb;
     $data = GW_GoPricing_Helper::clean_input($data);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     $wpdb->query('SET autocommit = 0;');
     $table_ids = explode(',', $data);
     foreach ((array) $table_ids as $table_id) {
         $result = GW_GoPricing_Data::delete_table((int) $table_id);
         $cnt++;
         if ($result === false) {
             GW_GoPricing_AdminNotices::add('main', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
             break;
         }
     }
     $notices = GW_GoPricing_AdminNotices::get('main', 'error');
     if (empty($notices)) {
         GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('%1$s pricing table(s) has been successfully deleted.', 'go_pricing_textdomain'), $cnt));
     }
     $wpdb->query('COMMIT;');
     $wpdb->query('SET autocommit = 1;');
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
 }
Example #23
0
    /**
     * Import processing step (status console)
     */
    public function process($save_history = true)
    {
        $wp_uploads = wp_upload_dir();
        $import = $this->data['update_previous'];
        $history_log = new PMXI_History_Record();
        $input = new PMXI_Input();
        if (!empty(PMXI_Plugin::$session->history_id)) {
            $history_log->getById(PMXI_Plugin::$session->history_id);
        }
        $log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage');
        if (!PMXI_Plugin::is_ajax()) {
            $import->set((empty(PMXI_Plugin::$session->source) ? array() : PMXI_Plugin::$session->source) + array('xpath' => PMXI_Plugin::$session->xpath, 'options' => PMXI_Plugin::$session->options, 'count' => PMXI_Plugin::$session->count, 'friendly_name' => wp_all_import_clear_xss(PMXI_Plugin::$session->options['friendly_name']), 'feed_type' => PMXI_Plugin::$session->feed_type, 'parent_import_id' => $this->data['update_previous']->isEmpty() ? PMXI_Plugin::$session->parent_import_id : $this->data['update_previous']->parent_import_id, 'queue_chunk_number' => 0, 'triggered' => 0, 'processing' => 0, 'executing' => 1, 'iteration' => !empty($import->iteration) ? $import->iteration : 0))->save();
            if (PMXI_Plugin::$session->action != 'continue') {
                // store import info in database
                $import->set(array('imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0))->update();
            }
            // add history log
            $custom_type = get_post_type_object($import->options['custom_type']);
            // unlink previous logs
            $by = array();
            $by[] = array(array('import_id' => $import->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->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => PMXI_Plugin::$session->action != 'continue' ? 'manual' : 'continue', 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->save();
            PMXI_Plugin::$session->set('history_id', $history_log->id);
            foreach (get_taxonomies() as $tax) {
                delete_transient("pmxi_{$tax}_terms");
            }
            $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
            if (@file_exists($functions)) {
                require_once $functions;
            }
            do_action('pmxi_before_xml_import', $import->id);
            PMXI_Plugin::$session->set('update_previous', $import->id);
            if (empty($import->options['encoding'])) {
                $currentOptions = $import->options;
                $currentOptions['encoding'] = 'UTF-8';
                $import->set(array('options' => $currentOptions))->update();
            }
            // unlink previous files
            $history = new PMXI_File_List();
            $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $import->id), 'id DESC');
            if ($history->count()) {
                foreach ($history as $file) {
                    $history_file_path = wp_all_import_get_absolute_path($file['path']);
                    if (@file_exists($history_file_path) and $history_file_path != PMXI_Plugin::$session->filePath) {
                        if (in_array($import->type, array('upload'))) {
                            wp_all_import_remove_source($history_file_path, false);
                        } else {
                            wp_all_import_remove_source($history_file_path);
                        }
                    }
                    $history_file = new PMXI_File_Record();
                    $history_file->getBy('id', $file['id']);
                    if (!$history_file->isEmpty()) {
                        $history_file->delete($history_file_path != PMXI_Plugin::$session->filePath);
                    }
                }
            }
            if ($save_history) {
                $history_file = new PMXI_File_Record();
                $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => wp_all_import_get_relative_path(PMXI_Plugin::$session->filePath), 'registered_on' => date('Y-m-d H:i:s')))->save();
            }
            /*
            	Split file up into 1000 record chunks.			
            	This option will decrease the amount of slowdown experienced at the end of large imports. 
            	The slowdown is partially caused by the need for WP All Import to read deeper and deeper into the file on each successive iteration. 
            	Splitting the file into pieces means that, for example, instead of having to read 19000 records into a 20000 record file when importing the last 1000 records, 
            	WP All Import will just split it into 20 chunks, and then read the last chunk from the beginning.
            */
            if ("ajax" == $import->options['import_processing'] and $import->count > PMXI_Plugin::getInstance()->getOption('large_feed_limit') and $import->options['chuncking']) {
                $chunk_files = array();
                if (!empty(PMXI_Plugin::$session->local_paths)) {
                    $records_count = 0;
                    $chunk_records_count = 0;
                    $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                    foreach (PMXI_Plugin::$session->local_paths as $key => $path) {
                        $file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding']));
                        // loop through the file until all lines are read
                        while ($xml = $file->read()) {
                            if (!empty($xml)) {
                                //PMXI_Import_Record::preprocessXml($xml);
                                $chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
                                $dom = new DOMDocument('1.0', $import->options['encoding']);
                                $old = libxml_use_internal_errors(true);
                                $dom->loadXML($chunk);
                                // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
                                libxml_use_internal_errors($old);
                                $xpath = new DOMXPath($dom);
                                if ($elements = @$xpath->query($import->xpath) and $elements->length) {
                                    $records_count += $elements->length;
                                    $chunk_records_count += $elements->length;
                                    $feed .= $xml;
                                }
                            }
                            if ($chunk_records_count == PMXI_Plugin::getInstance()->getOption('large_feed_limit') or $records_count == $import->count) {
                                $feed .= "</pmxi_records>";
                                $chunk_file_path = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY) . DIRECTORY_SEPARATOR . "pmxi_chunk_" . count($chunk_files) . "_" . basename($path);
                                file_put_contents($chunk_file_path, $feed);
                                $chunk_files[] = $chunk_file_path;
                                $chunk_records_count = 0;
                                $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                            }
                        }
                    }
                    PMXI_Plugin::$session->set('local_paths', $chunk_files);
                }
            }
            PMXI_Plugin::$session->save_data();
            if ($log_storage) {
                $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 (PMXI_Plugin::$session->action != 'continue') {
                    if (file_exists($log_file)) {
                        wp_all_import_remove_source($log_file, false);
                    }
                    //@file_put_contents($log_file, sprintf(__('<p>Source path `%s`</p>', 'wp_all_import_plugin'), $import->path));
                }
            }
            $this->data['ajax_processing'] = "ajax" == $import->options['import_processing'] ? true : false;
            $this->render();
            wp_ob_end_flush_all();
            flush();
            @set_time_limit(0);
            $import_id = $input->get('id', 0);
            if ("ajax" == $import->options['import_processing'] and !$import_id) {
                PMXI_Plugin::$session->convertData($import->id);
                //die();
            }
        } elseif (empty($import->id)) {
            $import = new PMXI_Import_Record();
            $import_id = $input->get('id', PMXI_Plugin::$session->update_previous);
            $import->getById($import_id);
        }
        $ajax_processing = "ajax" == $import->options['import_processing'] ? true : false;
        if (PMXI_Plugin::is_ajax() and $ajax_processing and !check_ajax_referer('wp_all_import_secure', 'security', false)) {
            exit(__('Security check', 'wp_all_import_plugin'));
        }
        if ($ajax_processing) {
            $logger = create_function('$m', 'echo "<div class=\\"progress-msg\\">$m</div>\\n"; flush();');
        } else {
            $logger = create_function('$m', 'echo "<div class=\\"progress-msg\\">$m</div>\\n"; if ( "" != strip_tags(wp_all_import_strip_tags_content($m))) { PMXI_Plugin::$session->log .= "<p>".strip_tags(wp_all_import_strip_tags_content($m))."</p>"; flush(); }');
        }
        PMXI_Plugin::$session->set('start_time', empty(PMXI_Plugin::$session->start_time) ? time() : PMXI_Plugin::$session->start_time);
        wp_cache_flush();
        wp_defer_term_counting(true);
        wp_defer_comment_counting(true);
        if (PMXI_Plugin::is_ajax() or !$ajax_processing) {
            $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
            if (@file_exists($functions)) {
                require_once $functions;
            }
            $iteration_start_time = time();
            if ($log_storage) {
                $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 ($ajax_processing) {
                // HTTP headers for no cache etc
                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                header("Cache-Control: no-store, no-cache, must-revalidate");
                header("Cache-Control: post-check=0, pre-check=0", false);
                header("Pragma: no-cache");
            }
            $loop = 0;
            $pointer = 0;
            $records = array();
            if ($import->options['is_import_specified']) {
                foreach (preg_split('% *, *%', $import->options['import_specified'], -1, PREG_SPLIT_NO_EMPTY) as $chank) {
                    if (preg_match('%^(\\d+)-(\\d+)$%', $chank, $mtch)) {
                        $records = array_merge($records, range(intval($mtch[1]), intval($mtch[2])));
                    } else {
                        $records = array_merge($records, array(intval($chank)));
                    }
                }
            }
            $records_to_import = empty($records) ? $import->count : $records[count($records) - 1];
            $failures = $input->get('failures', 0);
            // auto decrease records per iteration option
            if ($failures) {
                $options = $import->options;
                $options['records_per_request'] = ceil($options['records_per_request'] / 2) ? ceil($options['records_per_request'] / 2) : 1;
                $import->set(array('options' => $options))->update();
            }
            $records_per_request = (!$ajax_processing and $import->options['records_per_request'] < 50) ? 50 : $import->options['records_per_request'];
            if (!empty(PMXI_Plugin::$session->local_paths)) {
                $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                foreach (PMXI_Plugin::$session->local_paths as $key => $path) {
                    $import_done = $import->imported + $import->skipped == $records_to_import ? true : false;
                    if ($import_done) {
                        if (strpos($path, "pmxi_chunk_") !== false and @file_exists($path)) {
                            wp_all_import_remove_source($path, false);
                        }
                        PMXI_Plugin::$session->set('local_paths', array());
                        PMXI_Plugin::$session->save_data();
                        break;
                    }
                    $file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding'], 'pointer' => PMXI_Plugin::$session->pointer, 'filter' => true));
                    // loop through the file until all lines are read
                    while ($xml = $file->read() and empty($import->canceled)) {
                        if (!empty($xml)) {
                            // if ( ! $import->options['chuncking'] )
                            // 	PMXI_Import_Record::preprocessXml($xml);
                            $chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
                            $dom = new DOMDocument('1.0', $import->options['encoding']);
                            $old = libxml_use_internal_errors(true);
                            $dom->loadXML($chunk);
                            // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
                            libxml_use_internal_errors($old);
                            $xpath = new DOMXPath($dom);
                            $pointer++;
                            if ($this->data['elements'] = $elements = @$xpath->query($import->xpath) and $elements->length) {
                                /* Merge nested XML/CSV files */
                                /*$nested_files = json_decode($import->options['nested_files'], true);
                                		if ( ! empty($nested_files) and is_array($nested_files)){										
                                			$merger = new PMXI_Nested($dom, $nested_files, $xml, $import->xpath, $elements);
                                			$merger->merge();
                                			$xml = $merger->get_xml();
                                			unset($merger);
                                		}	*/
                                // continue action
                                if ($import->imported + $import->skipped >= PMXI_Plugin::$session->chunk_number + $elements->length - 1) {
                                    PMXI_Plugin::$session->set('chunk_number', PMXI_Plugin::$session->chunk_number + $elements->length);
                                    PMXI_Plugin::$session->save_data();
                                    continue;
                                }
                                if (!$loop and $ajax_processing) {
                                    ob_start();
                                }
                                $feed .= $xml;
                                $loop += $elements->length;
                                $processed_records = $import->imported + $import->skipped;
                                if ($loop == $records_per_request or $processed_records + $loop == $records_to_import or $processed_records == $records_to_import) {
                                    $feed .= "</pmxi_records>";
                                    $import->process($feed, $logger, PMXI_Plugin::$session->chunk_number, false, '/pmxi_records', $loop);
                                    unset($dom, $xpath);
                                    if (!$ajax_processing) {
                                        $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                                        $loop = 0;
                                    } else {
                                        if (!$history_log->isEmpty()) {
                                            $custom_type = get_post_type_object($import->options['custom_type']);
                                            $history_log->set(array('time_run' => time() - strtotime($history_log->date), 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->update();
                                        }
                                        unset($file);
                                        PMXI_Plugin::$session->set('pointer', PMXI_Plugin::$session->pointer + $pointer);
                                        PMXI_Plugin::$session->save_data();
                                        $log_data = ob_get_clean();
                                        if ($log_storage) {
                                            $log = @fopen($log_file, 'a+');
                                            @fwrite($log, $log_data);
                                            @fclose($log);
                                        }
                                        $iteration_execution_time = time() - $iteration_start_time;
                                        wp_send_json(array('imported' => $import->imported, 'created' => $import->created, 'updated' => $import->updated, 'skipped' => $import->skipped, 'percentage' => ceil($processed_records / $import->count * 100), 'warnings' => PMXI_Plugin::$session->warnings, 'errors' => PMXI_Plugin::$session->errors, 'log' => $log_data, 'done' => false, 'records_per_request' => $import->options['records_per_request'], 'iteration_execution_time' => $iteration_execution_time));
                                    }
                                }
                            }
                        }
                    }
                    // Move to the next file, set pointer to first element
                    if ($ajax_processing) {
                        if (strpos($path, "pmxi_chunk_") !== false and @file_exists($path)) {
                            @unlink($path);
                        }
                        PMXI_Plugin::$session->set('pointer', 1);
                        $pointer = 0;
                        $lp = PMXI_Plugin::$session->local_paths;
                        array_shift($lp);
                        PMXI_Plugin::$session->set('local_paths', $lp);
                        PMXI_Plugin::$session->save_data();
                    } else {
                        break;
                    }
                }
            }
        }
        // delete missing records
        if (PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->local_paths) or !$ajax_processing) {
            ob_start();
            $is_all_records_deleted = $import->delete_missing_records($logger, $import->iteration);
            $log_data = ob_get_clean();
            if ($log_storage) {
                $log = @fopen($log_file, 'a+');
                @fwrite($log, $log_data);
                @fclose($log);
            }
            $iteration_execution_time = time() - $iteration_start_time;
            if ($ajax_processing and !$is_all_records_deleted) {
                wp_send_json(array('imported' => $import->imported, 'created' => $import->created, 'updated' => $import->updated, 'skipped' => $import->skipped, 'deleted' => $import->deleted, 'percentage' => 99, 'warnings' => PMXI_Plugin::$session->warnings, 'errors' => PMXI_Plugin::$session->errors, 'log' => $log_data, 'done' => false, 'records_per_request' => $import->options['records_per_request'], 'iteration_execution_time' => $iteration_execution_time));
            }
        }
        if (PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->local_paths) or !$ajax_processing or !empty($import->canceled)) {
            $import->set(array('processing' => 0, 'triggered' => 0, 'queue_chunk_number' => 0, 'registered_on' => date('Y-m-d H:i:s'), 'iteration' => ++$import->iteration))->update();
            if ("ajax" != $import->options['import_processing'] and $log_storage) {
                $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 (PMXI_Plugin::$session->action != 'continue') {
                    @file_put_contents($log_file, PMXI_Plugin::$session->log);
                } else {
                    $log = @fopen($log_file, 'a+');
                    @fwrite($log, PMXI_Plugin::$session->log);
                    @fclose($log);
                }
            }
            wp_cache_flush();
            foreach (get_taxonomies() as $tax) {
                delete_option("{$tax}_children");
                _get_term_hierarchy($tax);
            }
            $import->set(array('registered_on' => date('Y-m-d H:i:s'), 'executing' => 0))->update();
            wp_defer_term_counting(false);
            wp_defer_comment_counting(false);
            // add history log
            $custom_type = get_post_type_object($import->options['custom_type']);
            $history_log->set(array('time_run' => time() - strtotime($history_log->date), 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->update();
            // clear import session
            PMXI_Plugin::$session->clean_session($import->id);
            // clear session data (prevent from reimporting the same data on page refresh)
            // [indicate in header process is complete]
            $msg = !empty($import->canceled) ? addcslashes(__('Canceled', 'wp_all_import_plugin'), "\n\r") : addcslashes(__('Complete', 'wp_all_import_plugin'), "\n\r");
            if ($ajax_processing) {
                ob_start();
            }
            do_action('pmxi_after_xml_import', $import->id);
            $import->delete_source($logger);
            $import->options['is_import_specified'] and $logger and call_user_func($logger, 'Done');
            echo <<<COMPLETE
<script type="text/javascript">
//<![CDATA[
(function(\$){\t
\t\$('#status').html('{$msg}');\t
\twindow.onbeforeunload = false;
})(jQuery);
//]]>
</script>
COMPLETE;
            // [/indicate in header process is complete]
            if ($ajax_processing) {
                wp_send_json(array('imported' => $import->imported, 'created' => $import->created, 'updated' => $import->updated, 'skipped' => $import->skipped, 'percentage' => 100, 'warnings' => PMXI_Plugin::$session->warnings, 'errors' => PMXI_Plugin::$session->errors, 'log' => ob_get_clean(), 'done' => true, 'records_per_request' => $import->options['records_per_request']));
            }
        }
    }
Example #24
0
 function import_end()
 {
     unset($this->posts);
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     //echo '<p>' . __( 'All done.', 'rosa_txtd' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'rosa_txtd' ) . '</a>' . '</p>';
     //echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'rosa_txtd' ) . '</p>';
     do_action('import_end');
 }
Example #25
0
             break;
         case 'trash':
             wp_trash_comment($comment_id);
             $trashed++;
             break;
         case 'untrash':
             wp_untrash_comment($comment_id);
             $untrashed++;
             break;
         case 'delete':
             wp_delete_comment($comment_id);
             $deleted++;
             break;
     }
 }
 wp_defer_comment_counting(false);
 if ($approved) {
     $redirect_to = add_query_arg('approved', $approved, $redirect_to);
 }
 if ($unapproved) {
     $redirect_to = add_query_arg('unapproved', $unapproved, $redirect_to);
 }
 if ($spammed) {
     $redirect_to = add_query_arg('spammed', $spammed, $redirect_to);
 }
 if ($unspammed) {
     $redirect_to = add_query_arg('unspammed', $unspammed, $redirect_to);
 }
 if ($trashed) {
     $redirect_to = add_query_arg('trashed', $trashed, $redirect_to);
 }
Example #26
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     //wp_import_cleanup( $this->id );
     global $wp_filesystem;
     $wp_filesystem->delete($this->working_dir, true);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'cws_demo_imp') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'cws_demo_imp') . '</a>' . '</p>';
     do_action('import_end');
 }
Example #27
0
/**
 * Updates the comment count for post(s).
 *
 * When $do_deferred is false (is by default) and the comments have been set to
 * be deferred, the post_id will be added to a queue, which will be updated at a
 * later date and only updated once per post ID.
 *
 * If the comments have not be set up to be deferred, then the post will be
 * updated. When $do_deferred is set to true, then all previous deferred post
 * IDs will be updated along with the current $post_id.
 *
 * @since 2.1.0
 * @see wp_update_comment_count_now() For what could cause a false return value
 *
 * @staticvar array $_deferred
 *
 * @param int $post_id Post ID
 * @param bool $do_deferred Whether to process previously deferred post comment counts
 * @return bool|void True on success, false on failure
 */
function wp_update_comment_count($post_id, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        $_deferred = array_unique($_deferred);
        foreach ($_deferred as $i => $_post_id) {
            wp_update_comment_count_now($_post_id);
            unset($_deferred[$i]);
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }
    if (wp_defer_comment_counting()) {
        $_deferred[] = $post_id;
        return true;
    } elseif ($post_id) {
        return wp_update_comment_count_now($post_id);
    }
}
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'nav-menu-roles') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'nav-menu-roles') . '</a>' . '</p>';
     do_action('import_end');
 }
Example #29
0
/**
 * Trash or delete an attachment.
 *
 * When an attachment is permanently deleted, the file will also be removed.
 * Deletion removes all post meta fields, taxonomy, comments, etc. associated
 * with the attachment (except the main post).
 *
 * The attachment is moved to the trash instead of permanently deleted unless trash
 * for media is disabled, item is already in the trash, or $force_delete is true.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int  $post_id      Attachment ID.
 * @param bool $force_delete Optional. Whether to bypass trash and force deletion.
 *                           Default false.
 * @return mixed False on failure. Post data on success.
 */
function wp_delete_attachment($post_id, $force_delete = false)
{
    global $wpdb;
    if (!($post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $post_id)))) {
        return $post;
    }
    if ('attachment' != $post->post_type) {
        return false;
    }
    if (!$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status) {
        return wp_trash_post($post_id);
    }
    delete_post_meta($post_id, '_wp_trash_meta_status');
    delete_post_meta($post_id, '_wp_trash_meta_time');
    $meta = wp_get_attachment_metadata($post_id);
    $backup_sizes = get_post_meta($post->ID, '_wp_attachment_backup_sizes', true);
    $file = get_attached_file($post_id);
    if (is_multisite()) {
        delete_transient('dirsize_cache');
    }
    /**
     * Fires before an attachment is deleted, at the start of wp_delete_attachment().
     *
     * @since 2.0.0
     *
     * @param int $post_id Attachment ID.
     */
    do_action('delete_attachment', $post_id);
    wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
    wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
    // Delete all for any posts.
    delete_metadata('post', null, '_thumbnail_id', $post_id, true);
    wp_defer_comment_counting(true);
    $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $post_id));
    foreach ($comment_ids as $comment_id) {
        wp_delete_comment($comment_id, true);
    }
    wp_defer_comment_counting(false);
    $post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $post_id));
    foreach ($post_meta_ids as $mid) {
        delete_metadata_by_mid('post', $mid);
    }
    /** This action is documented in wp-includes/post.php */
    do_action('delete_post', $post_id);
    $result = $wpdb->delete($wpdb->posts, array('ID' => $post_id));
    if (!$result) {
        return false;
    }
    /** This action is documented in wp-includes/post.php */
    do_action('deleted_post', $post_id);
    $uploadpath = wp_upload_dir();
    if (!empty($meta['thumb'])) {
        // Don't delete the thumb if another attachment uses it.
        if (!$wpdb->get_row($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like($meta['thumb']) . '%', $post_id))) {
            $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
            /** This filter is documented in wp-includes/functions.php */
            $thumbfile = apply_filters('wp_delete_file', $thumbfile);
            @unlink(path_join($uploadpath['basedir'], $thumbfile));
        }
    }
    // Remove intermediate and backup images if there are any.
    if (isset($meta['sizes']) && is_array($meta['sizes'])) {
        foreach ($meta['sizes'] as $size => $sizeinfo) {
            $intermediate_file = str_replace(basename($file), $sizeinfo['file'], $file);
            /** This filter is documented in wp-includes/functions.php */
            $intermediate_file = apply_filters('wp_delete_file', $intermediate_file);
            @unlink(path_join($uploadpath['basedir'], $intermediate_file));
        }
    }
    if (is_array($backup_sizes)) {
        foreach ($backup_sizes as $size) {
            $del_file = path_join(dirname($meta['file']), $size['file']);
            /** This filter is documented in wp-includes/functions.php */
            $del_file = apply_filters('wp_delete_file', $del_file);
            @unlink(path_join($uploadpath['basedir'], $del_file));
        }
    }
    wp_delete_file($file);
    clean_post_cache($post);
    return $post;
}
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     update_option('cherry_sample_data', 1);
     do_action('import_end');
     $this->log(date('Y-m-d H:i:s'));
     $this->log(PHP_EOL . 'Import end' . PHP_EOL);
 }