Plugin Directory

Changeset 1098191


Ignore:
Timestamp:
02/24/2015 03:08:26 PM (11 years ago)
Author:
naveenann
Message:

Working on synchronizing data with CRON

Location:
opensearchserver-search/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • opensearchserver-search/trunk/index.php

    r1091184 r1098191  
    239239add_action('admin_menu', 'opensearchserver_admin_actions');
    240240add_action('template_redirect', 'opensearchserver_search');
    241 add_filter( 'query_vars', 'add_query_vars_filter' )
     241add_action('synchronize_with_cron','opensearchserver_synchronize_with_cron' );
     242add_filter( 'query_vars', 'add_query_vars_filter' );
    242243?>
  • opensearchserver-search/trunk/opensearchserver_admin.php

    r1085512 r1098191  
    191191 * @param number $limit
    192192 */
    193 function opensearchserver_checkindex(OSSIndexDocument $index, $limit = 1, $idx = 0, $total = 0) {
     193function opensearchserver_checkindex(OSSIndexDocument $index, $limit = 1, $idx = 0, $total = 0 ,$is_not_cron = TRUE) {
    194194  global $wpdb;
    195195  if ($index->count() < $limit) {
     
    198198  opensearchserver_start_indexing($index);
    199199  $index = null;
    200   wp_cache_flush();
    201   $wpdb->flush();
    202   if (function_exists('gc_enabled')) {
    203     if (gc_enabled()) {
    204       gc_collect_cycles();
    205     }
    206   }
    207 
    208   if ($idx != 0 && $total != 0) {
    209     $percent = (floatval($idx) / floatval($total)) * 100;
    210     $mem = floatval(memory_get_usage()) / 1024 / 1024;
    211     opensearchserver_display_messages(sprintf('Completed: %.2f %% (%d/%d)- Memory usage: %2f', $percent, $idx, $total, $mem));
     200  if(is_not_cron) {
     201    wp_cache_flush();
     202    $wpdb->flush();
     203    if (function_exists('gc_enabled')) {
     204      if (gc_enabled()) {
     205        gc_collect_cycles();
     206      }
     207    }
     208
     209    if ($idx != 0 && $total != 0) {
     210      $percent = (floatval($idx) / floatval($total)) * 100;
     211      $mem = floatval(memory_get_usage()) / 1024 / 1024;
     212      opensearchserver_display_messages(sprintf('Completed: %.2f %% (%d/%d)- Memory usage: %2f', $percent, $idx, $total, $mem));
     213    }
    212214  }
    213215  return new OSSIndexDocument();
     
    227229    return $docs_count;
    228230}
    229 
    230231/*
    231  * Function to reindex the website.
     232 * Function to reindex the website with cron.
    232233*/
    233 function opensearchserver_reindex_site($id,$type, $from = 0, $to = 0) {
     234function opensearchserver_reindex_site_with_cron() {
     235  global $wpdb;
     236  opensearchserver_reindex_init();
     237  opensearchserver_delete_document('*:*');
     238   $contentTypesToKeep = array();
     239    foreach (get_post_types() as $post_type) {
     240        if (get_option('oss_index_types_'.$post_type) == 1) {
     241            $contentTypesToKeep[] = $post_type;
     242        }
     243    }
     244    $sql_query = 'SELECT ID FROM '.$wpdb->posts.' WHERE post_status = \'publish\' AND post_type IN ("'.implode('","', $contentTypesToKeep).'") ORDER BY ID'.$limitSuffix;
     245    $posts = $wpdb->get_results($sql_query);
     246    $total_count = count($posts);
     247    $index = new OSSIndexDocument();
     248    for ($i = 0; $i < $total_count; $i++) {
     249      $post = get_post($posts[$i]->ID);
     250      opensearchserver_add_documents_to_index($index, $lang, $post);
     251      $index = opensearchserver_checkindex($index, 200, $i, $total_count, FALSE);
     252    }
     253    opensearchserver_checkindex($index, 1, $i, $total_count,FALSE);
     254  opensearchserver_optimize();
     255  opensearchserver_autocompletionBuild();
     256  return 1;
     257}
     258/*
     259 * Function to initialize the variable for reindex.
     260*/
     261function opensearchserver_reindex_init() {
    234262  global $wpdb;
    235263  $oss_server_url = get_option('oss_serverurl');
     
    244272  $ossEngineConnectTimeOut = config_request_value('ossEngineConnectTimeOut', 5, 'engineConnectTimeOut');
    245273  $ossEngineIndex = config_request_value('ossEngineIndex', $oss_indexname, 'engineIndex');
     274}
     275/*
     276 * Function to reindex the website.
     277*/
     278function opensearchserver_reindex_site($id,$type, $from = 0, $to = 0) {
     279  global $wpdb;
     280  opensearchserver_reindex_init();
    246281  if($id) {
    247282    $delete='id:'.$type.'_'.$id;
     
    858893
    859894function opensearchserver_admin_set_reindex() {
    860   $oss_index_from = isset($_POST['oss_index_from']) ? $_POST['oss_index_from'] : NULL;
    861   $oss_index_to = isset($_POST['oss_index_to']) ? $_POST['oss_index_to'] : NULL;
    862   update_option('oss_index_from', $oss_index_from);
    863   update_option('oss_index_to', $oss_index_to);
    864   $index_success = opensearchserver_reindex_site(NULL,NULL, $oss_index_from, $oss_index_to);
    865   $suffix = ($oss_index_from !== null && $oss_index_from != '' && $oss_index_to !== null && $oss_index_to != '') ? '(indexed documents from #'.$oss_index_from.' to #'.$oss_index_to.')' : '';
    866   opensearchserver_display_messages('Re indexing has been finished successfully '. $suffix .'.');
    867 }
     895  $post_oss_submit = $_POST['opensearchserver_submit'];
     896  if($post_oss_submit == 'Synchronize with CRON') {
     897    wp_schedule_single_event(time(), 'synchronize_with_cron');
     898    opensearchserver_display_messages('Re indexing has been successfully scheduled with cron will be executed in next 15 minutes.');
     899  }else {
     900    $oss_index_from = isset($_POST['oss_index_from']) ? $_POST['oss_index_from'] : NULL;
     901    $oss_index_to = isset($_POST['oss_index_to']) ? $_POST['oss_index_to'] : NULL;
     902    update_option('oss_index_from', $oss_index_from);
     903    update_option('oss_index_to', $oss_index_to);
     904    $index_success = opensearchserver_reindex_site(NULL,NULL, $oss_index_from, $oss_index_to);
     905    $suffix = ($oss_index_from !== null && $oss_index_from != '' && $oss_index_to !== null && $oss_index_to != '') ? '(indexed documents from #'.$oss_index_from.' to #'.$oss_index_to.')' : '';
     906    opensearchserver_display_messages('Re indexing has been finished successfully '. $suffix .'.');
     907  }
     908}
     909/*
     910 * Re-index using cron
     911*/
     912function opensearchserver_synchronize_with_cron() {
     913   opensearchserver_reindex_site_with_cron();
     914}
     915
     916
    868917/*
    869918 * The admin page settings actions
     
    911960  } elseif ($action == 'opensearchserver_reindex') {
    912961    opensearchserver_admin_set_reindex();
    913   } elseif ($action == 'opensearchserver_advanced_settings') {
     962  }elseif ($action == 'opensearchserver_advanced_settings') {
    914963    opensearchserver_admin_set_advanced_settings();
    915964  }
     
    15371586                                    name="opensearchserver_submit" value="Synchronize / Re-Index"
    15381587                                    class="button-primary" />
     1588                  <input type="submit"
     1589                  name="opensearchserver_submit" value="Synchronize with CRON"
     1590                  class="button-primary" />
    15391591                            </p>
    15401592                        </form>
Note: See TracChangeset for help on using the changeset viewer.