function tryInsertUser(DatabaseBase $db, GWTUser $u) { $res = $db->select("webmaster_user_accounts", array('user_id'), array("user_name" => $u->getEmail()), __METHOD__); $obj = null; if ($obj = $res->fetchObject()) { return $obj->user_id; } //echo "insert: " . $u->getEmail() . "\n"; $user_id = generateUserId($db); if ($db->insert("webmaster_user_accounts", array("user_id" => $user_id, "user_name" => $u->getEmail(), "user_password" => $u->getPassword()))) { throw new Exception("can't insert user id = " . $user_id . " name = " . $u->getEmail()); } return $user_id; }
/** * @param GWTUser $gwtUserObject * @throws GWTException */ public function update($gwtUserObject) { $res = $this->databaseConnection->update("webmaster_user_accounts", array("user_id" => $gwtUserObject->getId(), "user_name" => $gwtUserObject->getEmail(), "user_password" => $gwtUserObject->getPassword(), "wikis_number" => $gwtUserObject->getCount()), array("user_id" => $gwtUserObject->getId())); if (!$res) { throw new GWTException("Failed to update " . $gwtUserObject->getId()); } }