Esempio n. 1
0
function prep_bib(&$bib)
{
    // Item Status Fields
    $bib['ages'] = '';
    $bib['branches'] = '';
    // Availability Attributes
    $lc = new locum_client();
    $bib_status = $lc->get_item_status($bib['bnum'], FALSE, TRUE);
    $formats = $lc->locum_config['formats'];
    // magnatune field names
    if ($bib['magnatune_id']) {
        $bib['author'] = $bib['artist'];
        $bib['series'] = 'magnatune';
        $bib['callnum'] = 'magnatune';
        $bib['mat_code'] = 'z';
        $bib['loc_code'] = 'online';
        $bib['bib_lastupdate'] = $bib['bib_created'];
        $bib['active'] = '1';
    }
    if (count($bib_status['ages'])) {
        $ages = array();
        foreach ($bib_status['ages'] as $age => $details) {
            $ages[] = $lc->string_poly($age);
        }
        $bib['ages'] = implode(',', $ages);
        unset($ages);
    }
    if (count($bib_status['branches'])) {
        $branches = array();
        foreach ($bib_status['branches'] as $branch => $details) {
            if ($details['avail']) {
                $branches[] = $lc->string_poly($branch);
            }
        }
        if (count($branches)) {
            $branches[] = $lc->string_poly('any');
        }
        $bib['branches'] = implode(',', $branches);
        unset($branches);
    }
    $callnum = $bib['callnum'];
    if (count($bib_status['items'])) {
        foreach ($bib_status['items'] as $item) {
            if (!strpos($bib['callnum'], $item['callnum'])) {
                $bib['callnum'] = $bib['callnum'] . " " . trim($item['callnum']);
            }
            if (strpos($item['location'], 'StaffPicks')) {
                $bib['callnum'] = $bib['callnum'] . " StaffPick";
            }
            if (strpos($item['location'], 'Stuff Shelf') && !strpos($bib['callnum'], 'Stuff Shelf')) {
                $bib['callnum'] = $bib['callnum'] . " Stuff Shelf";
            }
        }
    }
    unset($bib_status);
    // Series
    if (is_array($bib['series']) && count($bib['series'])) {
        $series_arr = $bib['series'];
        foreach ($series_arr as &$series) {
            // Convert to 32 bit hash and store lookup
            $series_string = $series;
            $series = $lc->string_poly($series);
            $lc->redis->set('poly_string:' . $series, $series_string);
        }
        $bib['series_attr'] = implode(',', $series_arr);
    }
    // Copy fields
    $bib['publisher'] = $bib['pub_info'];
    $bib['pubyear'] = $bib['pub_year'];
    $bib['langcode'] = $bib['lang'];
    $bib['mat_name'] = $formats[$bib['mat_code']];
    $bib['pub_decade'] = floor($bib['pub_year'] / 10) * 10;
    if ($bib['reading_level']->lexile) {
        $bib['lexile'] = floor($bib['reading_level']->lexile / 100) * 100;
    }
    // CRC32s
    $bib['pub_info'] = $lc->string_poly($bib['pub_info']);
    $bib['lang'] = $lc->string_poly($bib['lang']);
    $bib['loc_code'] = $lc->string_poly($bib['loc_code']);
    $bib['mat_code'] = $lc->string_poly($bib['mat_code']);
    $bib['title_attr'] = $lc->string_poly(strtolower($bib['title']));
    $bib['cover_code'] = $lc->string_poly($bib['cover_img']);
    // Timestamps
    $bib['bib_created'] = strtotime($bib['bib_created']);
    $bib['bib_last_update'] = strtotime($bib['bib_last_update']);
    // Ordinals
    $bib['title_ord'] = strtolower($bib['title']);
    $bib['author_ord'] = strtolower($bib['author']);
    // Null check
    $bib['author_null'] = empty($bib['author']) ? 1 : 0;
    // Non numeric ID check
    if ($bib['sphinxid']) {
        $bib['bnum'] = $bib['sphinxid'];
    }
    unset($lc);
}
Esempio n. 2
0
<pre>
<?php 
$time_start = microtime(true);
////////////////////////////////////////////////////////////////////////////////
require_once '/usr/local/lib/locum/locum-client.php';
$l = new locum_client();
print_r($l->search('keyword', 'dogs', 10, 0));
////////////////////////////////////////////////////////////////////////////////
$time = microtime(true) - $time_start;
echo "<p>Execution time: {$time} seconds</p>";
?>
</pre>
Esempio n. 3
0
 /**
  * Scans existing imported bibs for changes to the availability cache.
  *
  * @param boolean $quiet Run this function silently.  Default: TRUE
  */
 public function verify_status($quiet = TRUE)
 {
     if (is_callable(array(__CLASS__ . '_hook', __FUNCTION__))) {
         eval('$hook = new ' . __CLASS__ . '_hook;');
         return $hook->{__FUNCTION__}($quiet);
     }
     require_once 'locum-client.php';
     $limit = 1000;
     $offset = 0;
     $this->putlog("Collecting current data keys ..");
     $db = MDB2::connect($this->dsn);
     $sql = "SELECT bnum, bib_lastupdate FROM locum_bib_items WHERE active = '1' ORDER BY bnum LIMIT {$limit}";
     $init_result = $db->query($sql);
     $init_bib_arr = $init_result->fetchAll(MDB2_FETCHMODE_ASSOC);
     $locumclient = new locum_client();
     while (!empty($init_bib_arr)) {
         $num_children = $this->locum_config['harvest_config']['max_children'];
         $num_to_process = count($init_bib_arr);
         $bib_arr = array();
         foreach ($init_bib_arr as $init_bib_arr_vals) {
             $bib_arr[$init_bib_arr_vals['bnum']] = $init_bib_arr_vals['bib_lastupdate'];
         }
         $db->disconnect();
         $this->putlog("Finished collecting data keys.");
         if (extension_loaded('pcntl') && $this->locum_config['harvest_config']['harvest_with_children'] && $num_to_process >= 2 * $num_children) {
             $increment = ceil($num_to_process / $num_children);
             $split_offset = 0;
             for ($i = 0; $i < $num_children; ++$i) {
                 $end = $start + ($increment - 1);
                 $new_start = $end + 1;
                 $pid = pcntl_fork();
                 if ($pid != -1) {
                     if ($pid) {
                         $this->putlog("Spawning child harvester to verify records. PID is {$pid} ..");
                     } else {
                         sleep(1);
                         ++$i;
                         if ($i == $num_children) {
                             $end++;
                         }
                         $bib_arr_sliced = array_slice($bib_arr, $split_offset, $increment, TRUE);
                         $num_bibs = count($bib_arr_sliced);
                         foreach ($bib_arr_sliced as $bnum => $init_bib_date) {
                             $locumclient->get_item_status($bnum, TRUE);
                             $this->putlog("Caching status for {$bnum}");
                         }
                         $this->putlog("Child process complete.  Checked {$num_bibs} records", 2);
                         exit($i);
                     }
                 } else {
                     $this->putlog("Unable to spawn harvester: ({$i})", 5);
                 }
                 $start = $new_start;
                 $split_offset = $split_offset + $increment;
             }
             if ($pid) {
                 while ($i > 0) {
                     pcntl_waitpid(-1, &$status);
                     $val = pcntl_wexitstatus($status);
                     --$i;
                 }
                 $this->putlog("Verification complete!", 3);
             }
         } else {
             // TODO - Bib verification for those poor saps w/o pcntl
         }
         $offset = $offset + $limit;
         $this->putlog("Collecting current data keys starting at {$offset}");
         $db = MDB2::connect($this->dsn);
         $sql = "SELECT bnum, bib_lastupdate FROM locum_bib_items WHERE active = '1' ORDER BY bnum LIMIT {$limit} OFFSET {$offset}";
         $init_result = $db->query($sql);
         $init_bib_arr = $init_result->fetchAll(MDB2_FETCHMODE_ASSOC);
     }
 }
Esempio n. 4
0
<?php

date_default_timezone_set('America/Detroit');
$locum_lib_dir = '/usr/local/lib/locum';
// Include Locum libraries
require_once $locum_lib_dir . '/locum-client.php';
$locum = new locum_client();
// Rebuild timestamp queue if needed
if ($argv[1] == 'rebuild') {
    echo "Rebuilding timestamps queue...\n";
    $count = $locum->rebuild_status_timestamps();
    echo "Added {$count} records to the timestamp queue\n";
} else {
    if ($argv[1] == 'todays_bibs') {
        // Work from the todays_bibs queue
        echo "Starting availcache worker for today's bibs\n";
        while (1) {
            if ($bnum = $locum->redis->spop('todays_bibs')) {
                $now_date = date('m-d-Y G:i:s');
                echo "[{$now_date}] UPDATING {$bnum}\n";
                $locum->get_item_status($bnum, TRUE);
            } else {
                // No bibs to be updated, sleep and look again
                sleep(10);
            }
        }
    } else {
        // Identify queue offset to work from
        $q_offset = (int) ($argv[1] ? $argv[1] * 10 : 0);
        echo "Starting availcache worker with queue offset {$q_offset}\n";
        while (1) {