Exemplo n.º 1
0
 static function update_index($task)
 {
     try {
         $completed = $task->get("completed", 0);
         $start = microtime(true);
         foreach (ORM::factory("item")->join("search_records", "items.id", "search_records.item_id", "left")->where("search_records.item_id", "IS", null)->or_where("search_records.dirty", "=", 1)->find_all(100) as $item) {
             // The query above can take a long time, so start the timer after its done
             // to give ourselves a little time to actually process rows.
             if (!isset($start)) {
                 $start = microtime(true);
             }
             search::update($item);
             $completed++;
             if (microtime(true) - $start > 0.75) {
                 break;
             }
         }
         list($remaining, $total, $percent) = search::stats();
         $task->set("completed", $completed);
         if ($remaining == 0 || !($remaining + $completed)) {
             $task->done = true;
             $task->state = "success";
             site_status::clear("search_index_out_of_date");
             $task->percent_complete = 100;
         } else {
             $task->percent_complete = round(100 * $completed / ($remaining + $completed));
         }
         $task->status = t2("one record updated, index is %percent% up-to-date", "%count records updated, index is %percent% up-to-date", $completed, array("percent" => $percent));
     } catch (Exception $e) {
         $task->done = true;
         $task->state = "error";
         $task->status = $e->getMessage();
     }
 }
Exemplo n.º 2
0
 /**
  * @return string An error message suitable for inclusion in the task log
  */
 static function check_index()
 {
     list($remaining) = search::stats();
     if ($remaining) {
         site_status::warning(t('Your search index needs to be updated.  <a href="%url" class="g-dialog-link">Fix this now</a>', array("url" => html::mark_clean(url::site("admin/maintenance/start/search_task::update_index?csrf=__CSRF__")))), "search_index_out_of_date");
     }
 }
Exemplo n.º 3
0
 static function update_index($task)
 {
     try {
         $completed = $task->get("completed", 0);
         $start = microtime(true);
         foreach (ORM::factory("item")->join("search_records", "items.id", "search_records.item_id", "left")->where("search_records.item_id", null)->orwhere("search_records.dirty", 1)->find_all() as $item) {
             if (microtime(true) - $start > 1.5) {
                 break;
             }
             search::update($item);
             $completed++;
         }
         list($remaining, $total, $percent) = search::stats();
         $task->set("completed", $completed);
         if ($remaining == 0 || !($remaining + $completed)) {
             $task->done = true;
             $task->state = "success";
             site_status::clear("search_index_out_of_date");
             $task->percent_complete = 100;
         } else {
             $task->percent_complete = round(100 * $completed / ($remaining + $completed));
         }
         $task->status = t2("one record updated, index is %percent% up-to-date", "%count records updated, index is %percent% up-to-date", $completed, array("percent" => $percent));
     } catch (Exception $e) {
         $task->done = true;
         $task->state = "error";
         $task->status = $e->getMessage();
     }
 }