Ejemplo n.º 1
0
 /**
  * Refreshes the ref table with data from the data table
  *
  * Returns an array with counts: the number of scanned items, indexed items, and total items to scan
  *
  * @param BfoxRefDbTable $db_table
  * @param string $id_col
  * @param string $content_col
  * @param integer $limit
  * @param integer $offset
  * @return array
  */
 public static function simple_refresh(BfoxRefDbTable $db_table, $id_col, $content_col, $limit = 0, $offset = 0)
 {
     global $wpdb;
     $limit = (int) $limit;
     $offset = (int) $offset;
     if (0 == $limit) {
         $limit = 100;
     }
     $results = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS " . $db_table->refresh_select($id_col, $content_col, $limit, $offset));
     $total = $wpdb->get_var('SELECT FOUND_ROWS()');
     $scanned = count($results);
     $indexed = 0;
     foreach ($results as $data_row) {
         if ($db_table->save_data_row($data_row, $id_col, $content_col)) {
             $indexed++;
         }
     }
     return compact('scanned', 'indexed', 'total');
 }
 public function __construct()
 {
     global $wpdb;
     parent::__construct($wpdb->posts);
     $this->set_item_id_definition(array('item_id' => '%d', 'taxonomy' => '%s'));
 }
 /**
  * Scans a given number of blog posts for Bible references
  *
  * @param unknown_type $limit
  */
 private function scanPosts($limit)
 {
     $indexedPostTypes = $this->options->value('indexedPostTypes');
     if ($indexedPostTypes != $this->postTypes) {
         // If the configuration has changed, reset the indexes
         $this->options->setValue('indexStatus', array());
         $this->options->setValue('indexedPostTypes', $this->postTypes);
     }
     $status = $this->options->value('indexStatus');
     if (!isset($status['scanned'])) {
         $status = array('scanned' => 0, 'indexed' => 0, 'total' => 0);
     }
     if ($status['scanned'] < $status['total']) {
         extract(BfoxRefDbTable::simple_refresh($table, 'ID', '', $limit, $status['scanned']));
         $status['scanned'] += $scanned;
         $status['indexed'] += $indexed;
         $status['total'] = $total;
         $this->options->setValue('indexStatus', $status);
     }
 }
Ejemplo n.º 4
0
function bfox_bp_admin_activity_check_refresh($show_settings)
{
    if ($show_settings && $_GET['bfox_activity_refresh']) {
        $table = bfox_activity_ref_table();
        // If this is the first page of refreshing, delete all the activities
        $offset = (int) $_GET['offset'];
        if (0 == $offset) {
            $table->delete_all();
        }
        // Refresh this set of activities
        extract(BfoxRefDbTable::simple_refresh($table, 'id', 'content', $_GET['limit'], $offset));
        // Get old values from bfox_bp_admin_activity_refresh_status() and increment them with the new values from BfoxRefDbTable::simple_refresh())
        extract(bfox_bp_admin_activity_refresh_status());
        // If the previous status is finished, then we must be starting a new complete refresh
        if ($date_finished) {
            $blog_offset = $scan_total = $index_total = $blog_count = $date_finished = 0;
        }
        $scan_total += $scanned;
        $index_total += $indexed;
        $offset += $scanned;
        $is_running = $offset < $total;
        if ($is_running) {
            $date_finished = 0;
        } else {
            $date_finished = time();
        }
        bfox_bp_admin_activity_refresh_set_status(compact('scan_total', 'index_total', 'total', 'date_finished'));
        ?>
		<h3><?php 
        _e('Refreshing Bible Index...', 'bfox');
        ?>
</h3>
		<?php 
        bfox_bp_admin_activity_refresh_output_status();
        ?>

		<?php 
        $next_url = add_query_arg(compact('offset'), bfox_bp_admin_activity_refresh_url(true));
        if ($is_running) {
            ?>
		<p><?php 
            _e("If your browser doesn't start loading the next page automatically click this link:", 'bfox');
            ?>
 <a class="button" href="<?php 
            echo $next_url;
            ?>
"><?php 
            _e("Continue", 'bfox');
            ?>
</a></p>
		<script type='text/javascript'>
		<!--
		function nextpage() {
			location.href = "<?php 
            echo $next_url;
            ?>
";
		}
		setTimeout( "nextpage()", 250 );
		//-->
		</script>
		<?php 
        }
        $show_settings = false;
    }
    return $show_settings;
}