コード例 #1
0
ファイル: queue.php プロジェクト: 0hyeah/yurivn
 /**
 * vb_Search_Indexcontroller_Queue::indexQueue()
 *
 * Index an item based on a map of fieldname/value pairs
 *
 * @param string $package : the package which we are indexing
 * @param string $contenttype : text string with the type of content
 * @param string $operation: the index action, which will vary depending on the action.
 *    usually it will just be "index"
 * @param data : If we have fourth parameter we take it as an associative array of field values
 * @return : boolean success indicator
 */
 public static function indexQueue($package, $contenttype, $operation)
 {
     $data = array_slice(func_get_args(), 3);
     global $vbulletin;
     $db = vB_Search_Core::get_db();
     //For now we need to compose an sql query. Parameters are not available.
     //First make sure we've got good data. If we don't have the three parameters
     if (isset($package)) {
         $dbfields['package'] = "'" . $db->escape_string($package) . "'";
     } else {
         return false;
     }
     if (isset($contenttype)) {
         $dbfields['contenttype'] = "'" . $db->escape_string($contenttype) . "'";
     } else {
         return false;
     }
     if (isset($operation)) {
         $dbfields['operation'] = "'" . $db->escape_string($operation) . "'";
     }
     if (!$vbulletin->options['searchqueueupdates']) {
         // we just call indexNow. It checks for valid data.
         return vB_Search_Indexcontroller_QueueProcessor::indexNow($package, $contenttype, $operation, $data);
     }
     $dbfields['data'] = "'" . $db->escape_string(serialize($data)) . "'";
     $sql = "INSERT INTO " . TABLE_PREFIX . "indexqueue (" . implode(', ', array_keys($dbfields)) . ")\n\t\t\tVALUES ( " . implode(', ', $dbfields) . " )";
     $db->query_write($sql);
     return true;
 }
コード例 #2
0
ファイル: queueprocessor.php プロジェクト: 0hyeah/yurivn
    /**
     * vB_Search_Indexcontroller_QueueProcessor::index()
     * This is the default method. We get called by the cron job, and we have
     * no idea how many records are waiting, etc.
     *
     * @return : boolean success indicator
     */
    public static function index()
    {
        //first, do a check to see if we are unique. If we are already running,
        // we just quit.
        global $vbulletin;
        $lock_name = TABLE_PREFIX . 'vb_queue_lock';
        if (!($row = $vbulletin->db->query_first("SELECT IS_FREE_LOCK('{$lock_name}')"))) {
            error_log('in vB_Search_Indexcontroller_QueueProcessor::index,
				unable to query lock to do queue indexing');
            return false;
        }
        reset($row);
        if (!current($row)) {
            return false;
        }
        if (!($row = $vbulletin->db->query_first("SELECT GET_LOCK('{$lock_name}', 2)"))) {
            return false;
        }
        if (!current($row)) {
            return false;
        }
        //if we got here, we were able to get the lock.
        $vb = vB_Search_Core::get_instance();
        $db = vB_Search_Core::get_db();
        $rst = $db->query_read("SELECT indexqueue.* FROM " . TABLE_PREFIX . "indexqueue AS indexqueue ORDER BY queueid");
        $ids = array();
        $currtime = gettimeofday(true);
        $timeout = ini_get('max_execution_time');
        if ($timeout < 15 or $timeout > 300) {
            $timeout = 60;
            @set_time_limit($timeout);
        }
        $endtime = $currtime + intval($timeout * 0.75);
        while ($row = $db->fetch_array($rst)) {
            //make sure we have good data
            if ($row['contenttype'] == null || $row['package'] == null) {
                continue;
            }
            //let's try to get the correct controller
            if (($indexcontroller = $vb->get_index_controller($row['package'], $row['contenttype'])) == null) {
                continue;
            }
            if (gettimeofday(true) > $endtime) {
                break;
            }
            //The data is serialized, so let's extract it.
            $row['data'] = unserialize($row['data']);
            if (!self::indexOne($indexcontroller, $row['contenttype'], $row['operation'], $row['data'])) {
                error_log('Unable to index ' . ': ' . $row['operation'] . ': ' . isset($row['data'][0]) ? $row['data'][0] : '');
            }
            $ids[] = $row['queueid'];
        }
        if (count($ids)) {
            $db->query_write("DELETE from " . TABLE_PREFIX . "indexqueue WHERE queueid in(" . implode(', ', $ids) . ")");
        }
        $vbulletin->db->query_first("SELECT RELEASE_LOCK('{$lock_name}')");
        return true;
    }