Update login statistics, like IP address and the current date

@param int $userId The user_id value
@param array $columns Extra columns, variable
@return int The number of rows updated.
768909
public function updateLoginStats($userId, $columns = array()) {
        if (isset($_SERVER['REMOTE_ADDR'])) {
            $columns['ip_address'] = $_SERVER['REMOTE_ADDR'];
        }
        $columns['last_login'] = new Zend_Db_Expr('NOW()');
        return $this->_model->update(
            $columns,
            $this->_model->getAdapter()->quoteInto('user_id = ?', $userId)
        );
    }
87943
public function find($id, $columns = ['*'])
    {
        if (Uuid::validate($id)) {
            return $this->findByUuid($id, $columns);
        } else {
            return parent::find($id, $columns);
        }
    }
934005
public function login(string $userID): bool
    {
        $data = Internal\Server::call('login', ['userID' => $userID], true);
        if (isset($data['result'])) {
            return $data['result'] === 'ok';
        }
        return false;
    }
1055854
public function update($userId, array $userInfo = [])
    {
        $params = array_merge($userInfo, ['userid' => $userId]);

        return $this->parseJSON('json', [self::API_UPDATE, $params]);
    }
137909
public static function get_by_user_id($user_id) {
	$mysql = bootstrap::get_library('mysql');
	
	$sql   = "SELECT * FROM `login_github` WHERE `user_id` = %d;";
	$login = $mysql::select('row', $sql, $user_id);
	if (empty($login)) {
		return false;
	}
	
	return new static($login['id']);
}
446255
protected function _updateSource(array $values, $userId)
    {
        if ($this->tracker->filterChangesOnly($this->_sourceData, $values)) {


            if (\Gems_Tracker::$verbose) {
                $echo = '';
                foreach ($values as $key => $val) {
                    $echo .= $key . ': ' . $this->_sourceData[$key] . ' => ' . $val . "\n";
                }
                \MUtil_Echo::r($echo, 'Updated values for ' . $this->getId());
            }

            if (! isset($values['gso_changed'])) {
                $values['gso_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
            }
            if (! isset($values['gso_changed_by'])) {
                $values['gso_changed_by'] = $userId;
            }

            // Update values in this object
            $this->_sourceData = $values + $this->_sourceData;

            // return 1;
            return $this->_gemsDb->update('gems__sources', $values, array('gso_id_source = ?' => $this->getId()));

        } else {
            return 0;
        }
    }
1142129
public function update($userId, array $data=null)
    {
        $payload = [];
        if( $data !== null ){
            $payload['data'] = $data;
        }
        $response = $this->doRequest('PUT', 'user/' . $userId . '/', $payload);
        $body = $response->getBody()->getContents();
        return json_decode($body, true);
    }
750461
public function isMe($userId) {
		$field = $this->getConfig('idColumn');
		return $userId && (string)$userId === (string)$this->user($field);
	}
883927
public function updateUserSecurityIdentity(UserSecurityIdentity $usid, $oldUsername)
    {
        $this->connection->executeQuery($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
    }
898959
public static function update($userId, $id, $params = null, $options = null)
    {
        return self::_userBasedUpdate($userId, $id, $params, $options);
    }
328363
public function SetUserBookmarkCount($UserID) {
		$Count = $this->UserBookmarkCount($UserID);
      Gdn::UserModel()->SetField($UserID, 'CountBookmarks', $Count);
		
		return $Count;
	}
988407
protected function toResponseDatabase($userId)
    {
        $responseDb = $this->project->getResponseDatabase();

        // WHY EXPLANATION!!
        //
        // For some reason mysql prepared parameters do nothing with a \Zend_Db_Expr
        // object and that causes an error when using CURRENT_TIMESTAMP
        $current = \MUtil_Date::now()->toString(\Gems_Tracker::DB_DATETIME_FORMAT);
        $rValues = array(
            'gdr_id_token'   => $this->_tokenId,
            'gdr_changed'    => $current,
            'gdr_changed_by' => $userId,
            'gdr_created'    => $current,
            'gdr_created_by' => $userId,
        );
        $responses = $this->getRawAnswers();
        unset($responses['token'], $responses['id'], $responses['lastpage'],
                $responses['startlanguage'], $responses['submitdate'], $responses['startdate'],
                $responses['datestamp']);

        // first read current responses to differentiate between insert and update
        $responseSelect = $responseDb->select()->from('gemsdata__responses', array('gdr_answer_id', 'gdr_response'))
                ->where('gdr_id_token = ?', $this->_tokenId);
        $currentResponses = $responseDb->fetchPairs($responseSelect);

        if (! $currentResponses) {
            $currentResponses = array();
        }
        // \MUtil_Echo::track($currentResponses, $responses);

        // Prepare sql
        $sql = "UPDATE gemsdata__responses
            SET `gdr_response` = ?, `gdr_changed` = ?, `gdr_changed_by` = ?
            WHERE gdr_id_token = ? AND gdr_answer_id = ? AND gdr_answer_row = 1";
        $statement = $responseDb->prepare($sql);

        $inserts = array();
        foreach ($responses as $fieldName => $response) {
            $rValues['gdr_answer_id']  = $fieldName;
            if (is_array($response)) {
                $response = join('|', $response);
            }
            $rValues['gdr_response']  = $response;

            if (array_key_exists($fieldName, $currentResponses)) {    // Already exists, do update
                // But only if value changed
                if ($currentResponses[$fieldName] != $response) {
                    try {
                        // \MUtil_Echo::track($sql, $rValues['gdr_id_token'], $fieldName, $response);
                        $statement->execute(array(
                            $response,
                            $rValues['gdr_changed'],
                            $rValues['gdr_changed_by'],
                            $rValues['gdr_id_token'],
                            $fieldName
                        ));
                    } catch (\Zend_Db_Statement_Exception $e) {
                        error_log($e->getMessage());
                        \Gems_Log::getLogger()->logError($e);
                    }
                }
            } else {
                // We add the inserts together in the next prepared statement to improve speed
                $inserts[$fieldName] = $rValues;
            }
        }

        if (count($inserts)>0) {
            // \MUtil_Echo::track($inserts);
            try {
                $fields = array_keys(reset($inserts));
                $fields = array_map(array($responseDb, 'quoteIdentifier'), $fields);
                $sql = 'INSERT INTO gemsdata__responses (' .
                        implode(', ', $fields) . ') VALUES (' .
                        implode(', ', array_fill(1, count($fields), '?')) . ')';

                // \MUtil_Echo::track($sql);
                $statement = $responseDb->prepare($sql);

                foreach($inserts as $insert) {
                    // \MUtil_Echo::track($insert);
                    $statement->execute($insert);
                }

            } catch (\Zend_Db_Statement_Exception $e) {
                error_log($e->getMessage());
                \Gems_Log::getLogger()->logError($e);
            }
        }
    }
868624
public static function findByID($userID, $columnName = '')
    {
        $userObj = User::where('userID', $userID)->first();

        // return custom column
        if ($columnName && isset($userObj->$columnName)) {
            return $userObj->$columnName;
        }

        return $userObj;
    }
437798
protected function _updateObject( $user_id, $fields ) {
		$fields['ID'] = $user_id;
		$updated = wp_update_user( $fields );
		if ( $updated && ! is_wp_error( $updated ) ) {
			$this->_debug( 'Updated user ' . $user_id );
		} elseif ( is_wp_error( $updated ) ) {
			$this->_debug(
				'Update failed for user %d with message [%s] %s',
				$user_id,
				$updated->get_error_code(),
				$updated->get_error_message()
			);
		} else {
			$this->_debug( 'Update failed for user ' . $user_id );
		}

		return $updated;
	}
1248768
public function GetCount($UserID) {
      return $this->SQL
         ->Select('DraftID', 'count', 'CountDrafts')
         ->From('Draft')
         ->Where('InsertUserID', $UserID)
         ->Get()
         ->FirstRow()
         ->CountDrafts;
   }
484667
public function deleteUserQuery($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->delete($this->getTableName());

        if (is_numeric($userId)) {
            $qb->where('id = :userId');
        } else {
            $qb->where('username = :userId')->orWhere('email = :userId');
        }
        $qb->setParameter('userId', $userId);

        return $qb;
    }
1111653
public function load($userId)
    {
        try {
            return $this->innerGateway->load($userId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }