Force all user ids equal

This commit is contained in:
kaetemi 2014-09-03 06:38:38 +02:00
parent 2b2ffb8052
commit f920da3873
2 changed files with 59 additions and 60 deletions

View file

@ -7,13 +7,13 @@
* @author Daan Janssens, mentored by Matthew Lagoe * @author Daan Janssens, mentored by Matthew Lagoe
*/ */
class Ticket_User{ class Ticket_User{
private $tUserId; /**< The id of the user inside the ticket system*/ private $tUserId; /**< The id of the user inside the ticket system*/
private $permission; /**< The permission of the user */ private $permission; /**< The permission of the user */
private $externId; /**< The id of the user account in the www (could be drupal,...) that is linked to the ticket_user */ private $externId; /**< The id of the user account in the www (could be drupal,...) that is linked to the ticket_user */
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
/** /**
* create a new ticket user. * create a new ticket user.
* @param $extern_id the id of the user account in the www version (drupal,...) * @param $extern_id the id of the user account in the www version (drupal,...)
@ -21,10 +21,10 @@ class Ticket_User{
*/ */
public static function createTicketUser( $extern_id, $permission) { public static function createTicketUser( $extern_id, $permission) {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$dbl->insert("ticket_user",array('Permission' => $permission, 'ExternId' => $extern_id)); $dbl->insert("ticket_user",array('TUserId' => $extern_id, 'Permission' => $permission, 'ExternId' => $extern_id));
} }
/** /**
* check if a ticket_user object is a mod or not. * check if a ticket_user object is a mod or not.
* @param $user the ticket_user object itself * @param $user the ticket_user object itself
@ -36,8 +36,8 @@ class Ticket_User{
} }
return false; return false;
} }
/** /**
* check if a ticket_user object is an admin or not. * check if a ticket_user object is an admin or not.
* @param $user the ticket_user object itself * @param $user the ticket_user object itself
@ -49,8 +49,8 @@ class Ticket_User{
} }
return false; return false;
} }
/** /**
* return constructed ticket_user object based on TUserId. * return constructed ticket_user object based on TUserId.
* @param $id the TUserId of the entry. * @param $id the TUserId of the entry.
@ -60,10 +60,10 @@ class Ticket_User{
$instance = new self(); $instance = new self();
$instance->setTUserId($id); $instance->setTUserId($id);
return $instance; return $instance;
} }
/** /**
* return a list of all mods/admins. * return a list of all mods/admins.
* @return an array consisting of ticket_user objects that are mods & admins. * @return an array consisting of ticket_user objects that are mods & admins.
@ -78,10 +78,10 @@ class Ticket_User{
$instanceUser->set($user); $instanceUser->set($user);
$result[] = $instanceUser; $result[] = $instanceUser;
} }
return $result; return $result;
} }
/** /**
* return constructed ticket_user object based on ExternId. * return constructed ticket_user object based on ExternId.
* @param $id the ExternId of the entry. * @param $id the ExternId of the entry.
@ -97,8 +97,8 @@ class Ticket_User{
$instance->externId = $row['ExternId']; $instance->externId = $row['ExternId'];
return $instance; return $instance;
} }
/** /**
* change the permission of a ticket_user. * change the permission of a ticket_user.
* @param $user_id the TUserId of the entry. * @param $user_id the TUserId of the entry.
@ -110,8 +110,8 @@ class Ticket_User{
$user->setPermission($perm); $user->setPermission($perm);
$user->update(); $user->update();
} }
/** /**
* return the email address of a ticket_user. * return the email address of a ticket_user.
* @param $id the TUserId of the entry. * @param $id the TUserId of the entry.
@ -121,10 +121,10 @@ class Ticket_User{
$user = new Ticket_User(); $user = new Ticket_User();
$user->load_With_TUserId($id); $user->load_With_TUserId($id);
$webUser = new WebUsers($user->getExternId()); $webUser = new WebUsers($user->getExternId());
return $webUser->getEmail(); return $webUser->getEmail();
} }
/** /**
* return the username of a ticket_user. * return the username of a ticket_user.
* @param $id the TUserId of the entry. * @param $id the TUserId of the entry.
@ -134,10 +134,10 @@ class Ticket_User{
$user = new Ticket_User(); $user = new Ticket_User();
$user->load_With_TUserId($id); $user->load_With_TUserId($id);
$webUser = new WebUsers($user->getExternId()); $webUser = new WebUsers($user->getExternId());
return $webUser->getUsername(); return $webUser->getUsername();
} }
/** /**
* return the TUserId of a ticket_user by giving a username. * return the TUserId of a ticket_user by giving a username.
* @param $username the username of a user. * @param $username the username of a user.
@ -146,9 +146,9 @@ class Ticket_User{
public static function get_id_from_username($username){ public static function get_id_from_username($username){
$externId = WebUsers::getId($username); $externId = WebUsers::getId($username);
$user = Ticket_User::constr_ExternId($externId); $user = Ticket_User::constr_ExternId($externId);
return $user->getTUserId(); return $user->getTUserId();
} }
/** /**
* return the ticket_user id from an email address. * return the ticket_user id from an email address.
* @param $email the emailaddress of a user. * @param $email the emailaddress of a user.
@ -163,18 +163,18 @@ class Ticket_User{
return "FALSE"; return "FALSE";
} }
} }
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
/** /**
* A constructor. * A constructor.
* Empty constructor * Empty constructor
*/ */
public function __construct() { public function __construct() {
} }
/** /**
* sets the object's attributes. * sets the object's attributes.
* @param $values should be an array of the form array('TUserId' => id, 'Permission' => perm, 'ExternId' => ext_id). * @param $values should be an array of the form array('TUserId' => id, 'Permission' => perm, 'ExternId' => ext_id).
@ -184,8 +184,8 @@ class Ticket_User{
$this->setPermission($values['Permission']); $this->setPermission($values['Permission']);
$this->setExternId($values['ExternId']); $this->setExternId($values['ExternId']);
} }
/** /**
* loads the object's attributes. * loads the object's attributes.
* loads the object's attributes by giving a TUserId. * loads the object's attributes by giving a TUserId.
@ -198,9 +198,9 @@ class Ticket_User{
$this->tUserId = $row['TUserId']; $this->tUserId = $row['TUserId'];
$this->permission = $row['Permission']; $this->permission = $row['Permission'];
$this->externId = $row['ExternId']; $this->externId = $row['ExternId'];
} }
/** /**
* update the object's attributes to the db. * update the object's attributes to the db.
*/ */
@ -208,33 +208,33 @@ class Ticket_User{
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$dbl->update("ticket_user" ,array('Permission' => $this->permission, 'ExternId' => $this->externId) ,"TUserId=$this->tUserId"); $dbl->update("ticket_user" ,array('Permission' => $this->permission, 'ExternId' => $this->externId) ,"TUserId=$this->tUserId");
} }
////////////////////////////////////////////Getters//////////////////////////////////////////////////// ////////////////////////////////////////////Getters////////////////////////////////////////////////////
/** /**
* get permission attribute of the object. * get permission attribute of the object.
*/ */
public function getPermission(){ public function getPermission(){
return $this->permission; return $this->permission;
} }
/** /**
* get externId attribute of the object. * get externId attribute of the object.
*/ */
public function getExternId(){ public function getExternId(){
return $this->externId; return $this->externId;
} }
/** /**
* get tUserId attribute of the object. * get tUserId attribute of the object.
*/ */
public function getTUserId(){ public function getTUserId(){
return $this->tUserId; return $this->tUserId;
} }
////////////////////////////////////////////Setters//////////////////////////////////////////////////// ////////////////////////////////////////////Setters////////////////////////////////////////////////////
/** /**
* set permission attribute of the object. * set permission attribute of the object.
* @param $perm integer that indicates the permission level. (1= user, 2= mod, 3= admin) * @param $perm integer that indicates the permission level. (1= user, 2= mod, 3= admin)
@ -242,16 +242,16 @@ class Ticket_User{
public function setPermission($perm){ public function setPermission($perm){
$this->permission = $perm; $this->permission = $perm;
} }
/** /**
* set externId attribute of the object. * set externId attribute of the object.
* @param $id the external id. * @param $id the external id.
*/ */
public function setExternId($id){ public function setExternId($id){
$this->externId = $id; $this->externId = $id;
} }
/** /**
* set tUserId attribute of the object. * set tUserId attribute of the object.
* @param $id the ticket_user id * @param $id the ticket_user id
@ -259,6 +259,6 @@ class Ticket_User{
public function setTUserId($id){ public function setTUserId($id){
$this->tUserId= $id; $this->tUserId= $id;
} }
} }

View file

@ -286,9 +286,11 @@ class Users{
* @param $user_id the extern id of the user (the id given by the www/CMS) * @param $user_id the extern id of the user (the id given by the www/CMS)
* @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline. * @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline.
*/ */
public static function createUser($values, $user_id){ public static function createUser($values, $user_id) {
ticket_user::createTicketUser($user_id, 1);
try { try {
//make connection with and put into shard db //make connection with and put into shard db
$values["UId"] = $user_id;
$dbs = new DBLayer("shard"); $dbs = new DBLayer("shard");
$dbs->insert("user", $values); $dbs->insert("user", $values);
/* /*
@ -298,7 +300,6 @@ class Users{
$valuesRing['user_type'] = 'ut_pioneer'; $valuesRing['user_type'] = 'ut_pioneer';
$dbr->insert("ring_users", $valuesRing); $dbr->insert("ring_users", $valuesRing);
*/ */
ticket_user::createTicketUser( $user_id, 1);
return "ok"; return "ok";
} }
catch (PDOException $e) { catch (PDOException $e) {
@ -306,15 +307,13 @@ class Users{
try { try {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$dbl->insert("ams_querycache", array("type" => "createUser", $dbl->insert("ams_querycache", array("type" => "createUser",
"query" => json_encode(array($values["Login"],$values["Password"],$values["Email"])), "db" => "shard")); "query" => json_encode(array($values["Login"], $values["Password"], $values["Email"])), "db" => "shard"));
ticket_user::createTicketUser( $user_id , 1 );
return "shardoffline"; return "shardoffline";
}catch (PDOException $e) { } catch (PDOException $e) {
print_r($e); print_r($e);
return "liboffline"; return "liboffline";
} }
} }
} }
/** /**