Example #1
0
 public function banIPs($desc, $ips, $permissionSet = 10)
 {
     $query = new Query('INSERT');
     $query->intoTable('bans_ip');
     $query->intoField('ban_desc');
     $query->intoField('ip_low');
     $query->intoField('ip_high');
     $query->intoField('permissionset_id');
     $query->intoField('date_banned');
     foreach ($ips as $ip) {
         $intip = $this->toIntIP($ip);
         $query->values('(?, ?, ?, ?, NOW())', array($desc, $intip, $intip, $permissionSet));
     }
     $stmt = $query->prepare();
     return $stmt->execute();
 }
Example #2
0
 public function insert($ignore = false)
 {
     $query = new Query('INSERT', $this->dbengine);
     if ($ignore) {
         $query->ignore();
     }
     $query->intoTable(static::$tableNoPrefix);
     $vals = array();
     $template = '(';
     foreach ($this->stored as $key => $val) {
         $valid = true;
         if ($key == static::$primaryKey && static::$primaryKeyIsAutoIncrement) {
             $valid = false;
         }
         if ($valid) {
             $query->intoField($key);
             if ($this->sqlkeys[$key]) {
                 $template .= $val . ', ';
             } else {
                 $template .= '?, ';
                 $vals[] = $val;
             }
         }
     }
     if ($template == '(') {
         throw new NoStoredValuesException('INSERT cannot be completed: No values to be inserted.');
     }
     $template = substr($template, 0, -2) . ')';
     $query->values($template, $vals);
     $stmt = $query->prepare();
     if (!$stmt->execute()) {
         $info = $stmt->errorInfo();
         $e = new QueryFailedException($info[2]);
         $e->errorInfo = $info;
         throw $e;
     }
     return true;
 }
Example #3
0
        $name = $row['name'];
        $app_id = $row['id'];
        // Pull out the words we'll need to index
        $iwords = $am->getIndexable($name);
        // Add 'em
        if (count($iwords) > 0) {
            echo "Indexing: " . implode(', ', $iwords) . "<br />\n";
            foreach ($iwords as $iword) {
                $sindex[$iword][] = $app_id;
            }
        } else {
            echo "No words to be indexed.<br />\n";
        }
    }
}
echo "<br />Saving and caching:<br />\n";
foreach ($sindex as $term => $idarray) {
    echo "<strong>{$term}</strong> ";
    echo str_replace("\n", "<br />\n", print_r($idarray, true));
    $cm->set("search_name_index:{$term}", $idarray, 0);
    $query = new Query('INSERT');
    $query->intoTable('search_name_index');
    $query->intoField('term');
    $query->intoField('app_id_array');
    $query->values("(?, ?)", array($term, serialize($idarray)));
    $stmt = $query->prepare();
    if (!$stmt->execute()) {
        echo "Error while adding term '{$term}'.<br />\n";
    }
}
echo "<br />Done!";
Example #4
0
 protected function indexName($name, $id)
 {
     $iwords = $this->getIndexable($name);
     if (count($iwords) > 0) {
         $sem = SemaphoreEngineFactory::getEngine();
         $sindex = array();
         $create = array();
         $docreate = false;
         $query = new Query('SELECT');
         $query->field('term');
         $query->field('app_id_array');
         $query->from('search_name_index');
         foreach ($iwords as $iword) {
             $sindex[$iword] = array();
             $create[$iword] = true;
             $docreate = true;
             $query->where('term = ?', $iword, 'OR');
         }
         $stmt = $query->prepare();
         $semkey = Config::getVal('recache', 'unique_name') . ":LOCK:sindex";
         $sem->acquire($semkey);
         $stmt->execute();
         while ($row = $stmt->fetchObj()) {
             $create[$row->term] = false;
             $sindex[$row->term] = unserialize($row->app_id_array);
         }
         unset($query);
         unset($stmt);
         $iquery = new Query('INSERT');
         $iquery->ignore();
         $iquery->intoTable('search_name_index');
         $iquery->intoField('term');
         $iquery->intoField('app_id_array');
         $uqueries = array();
         foreach ($iwords as $iword) {
             if (!in_array($id, $sindex[$iword])) {
                 $sindex[$iword][] = $id;
                 $this->cm->set("search_name_index:{$iword}", $sindex[$iword], 0);
             }
             if ($create[$iword]) {
                 $iquery->VALUES('(?, ?)', array($iword, serialize($sindex[$iword])));
             } else {
                 $query = new Query('UPDATE');
                 $query->table('search_name_index');
                 $query->set('app_id_array = ?', serialize($sindex[$iword]));
                 $query->where('term = ?', $iword);
                 $uqueries[] = $query;
             }
         }
         if ($docreate) {
             $stmt = $iquery->prepare();
             unset($iquery);
             $stmt->execute();
         }
         foreach ($uqueries as $uquery) {
             $stmt = $uquery->prepare();
             $stmt->execute();
         }
         $sem->release($semkey);
     }
 }