You are here

function photos_update_index in Album Photos 7.3

Implements hook_update_index().

File

./photos.module, line 2856
Implementation of photos.module.

Code

function photos_update_index() {
  $limit = 'LIMIT ' . (int) variable_get('search_cron_limit', 100);
  $photos_search_max_id_ever = (int) variable_get('photos_search_max_id_ever', 0);
  $photos_search_max_id_reindex = (int) variable_get(' photos_search_max_id_reindex', 0);
  $wrap = (int) variable_get('photos_search_reindex_old_photos', 0);

  // Fetch new photos, added since last index run:
  $result = _photos_get_photos("WHERE pi.fid > {$photos_search_max_id_ever}", $limit, $wrap);
  if ($result
    ->rowCount() > 0) {
    foreach ($result as $image) {
      search_index($image->fid, 'photos', '<h1>' . $image->Title . '</h1> ' . $image->des);
      if ($photos_search_max_id_ever <= $image->fid) {

        /*
         We've just indexed a brand-new photo;
         Reset reindex counter to 0 so when reindexing we have to start
         at beginning.
        */
        $photos_search_max_id_ever = $image->fid;
        $photos_search_max_id_reindex = 0;
      }
      else {
        $photos_search_max_id_reindex = $image->fid;
      }
    }
    variable_set('photos_search_max_id_ever', (int) $photos_search_max_id_ever);
    variable_set('photos_search_max_id_reindex', (int) $photos_search_max_id_reindex);
  }
}