Пример #1
0
 public function update($allFields = false, $remap = false)
 {
     if (!isset($this->stored[static::$primaryKey])) {
         $class = get_class($this);
         throw new MissingPrimaryKeyException($class . '->update() cannot be called until a primary key is set.');
     }
     $changedMap = array();
     $query = new Query('UPDATE', $this->dbengine);
     $query->table(static::$tableNoPrefix);
     $fieldSet = $allFields ? $this->stored : $this->changed;
     foreach ($fieldSet as $key => $changed) {
         if ($remap && $changed) {
             foreach (static::$beanMap as $name => $args) {
                 if ($args['foreignKey'] == $key) {
                     $changedMap[] = $name;
                 }
             }
         }
         if (!$allFields && $changed) {
             if ($this->sqlkeys[$key]) {
                 $query->set($key . ' = ' . $this->stored[$key]);
             } else {
                 $query->set($key . ' = ?', $this->stored[$key]);
             }
         }
     }
     $query->where(static::$primaryKey . ' = ?', $this->stored[static::$primaryKey]);
     $query->limit(1);
     $stmt = $query->prepare();
     if (!$stmt->execute()) {
         $info = $stmt->errorInfo();
         $e = new QueryFailedException($info[2]);
         $e->errorInfo = $info;
         throw $e;
     }
     $this->changed = array();
     if ($remap) {
         foreach ($changedMap as $map) {
             if ($this->mapped[$map]) {
                 $class = static::$beanMap[$map]['joinBean'];
                 $query = new Query('SELECT', $this->dbengine);
                 $fkey = static::$beanMap[$map]['foreignKey'];
                 $hasMapped = $this->mapped[$map]->hasMappedBeans();
                 if ($hasMapped) {
                     $query->where($class::$tableAlias . ".{$fkey} = ?", $this->stored[$fkey]);
                 } else {
                     $query->where($fkey . ' = ?', $this->stored[$fkey]);
                 }
                 $query->limit(1);
                 $result = $class::select($query, $hasMapped, false, $this->dbengine);
                 $this->mapped[$map] = $result ? $result[0] : false;
             }
         }
     }
     return true;
 }
Пример #2
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);
     }
 }
Пример #3
0
    $acracker = array();
    while ($row = $stmt->fetchAssoc()) {
        $acracker[$row['app_id']] = $row['cracker'];
    }
    echo "Got crackers.<br />\n";
    ob_flush();
    flush();
    // And finally, update the facades
    foreach ($aname as $key => $value) {
        $version = $aver[$key];
        $date = $adate[$key];
        $cracker = isset($acracker[$key]) && !is_null($acracker[$key]) && !empty($acracker[$key]) ? "'" . $acracker[$key] . "'" : NULL;
        echo "Updating {$key}: {$value} ({$version}) cracked by {$cracker} on {$date}... ";
        $query = new Query('UPDATE');
        $query->table('applications');
        $query->set('latest_version = ?', $version);
        $query->set('latest_version_added = ?', $date);
        if (is_null($cracker)) {
            $query->set('latest_version_first_cracker = NULL');
        } else {
            $query->set('latest_version_first_cracker = ?', $cracker);
        }
        $query->where('id = ?', $key);
        $stmt = $query->prepare();
        if ($stmt->execute()) {
            echo "Done.<br />\n";
        } else {
            echo "Failed.<br />\n";
        }
    }
} else {
Пример #4
0
	<input type="submit" name="submitfull" value="Yes, Kabosh" />
	<input type="submit" name="cancel" value="No, I f****d up :(" />
</form>
<?php 
} else {
    if (isset($_POST['submitfull']) && isset($_POST['uid'])) {
        $upm = UserProfileModel::getInstance();
        $user = $upm->getByUserID($_POST['uid']);
        if (!$user) {
            die('You screwed up. There\'s no user with that ID.</body></html>');
        }
        $banid = (int) $_POST['uid'];
        echo "Deleting the links...<br />\n";
        $query = new Query('UPDATE');
        $query->table('links');
        $query->set('active = ?', 0);
        $query->where('submitter_id = ?', $banid);
        $stmt = $query->prepare();
        $stmt->execute();
        echo "All of user {$user->username}'s links have been deleted.<br />\n";
        echo "Banning the dickhead...<br />\n";
        $ipstoban = array();
        if ($user->reg_ip != 0) {
            $ipstoban[] = $user->reg_ip;
        }
        if (!is_null($user->last_ip) && $user->last_ip) {
            $ipstoban[] = $user->last_ip;
        }
        // And now, let's get all known IPs
        $query = new Query('SELECT');
        $query->field('submitter_ip');