Permalink
Browse files

Fixed a few user model and driver bugs

  • Loading branch information...
1 parent 7807f1b commit 84179b5a509f9d4c885780351d5df8a1b144a45e @lillem4n committed Feb 16, 2012
Showing with 8 additions and 9 deletions.
  1. +4 −8 classes/driver/user/mysql.php
  2. +4 −1 classes/model/user.php
@@ -229,10 +229,10 @@ public function get_users($q = FALSE, $start = 0, $limit = 100, $order_by = FALS
public function new_field($field_name)
{
- if (User::field_name_available($field_name) && $field_name != 'id')
+ if ($field_name != 'id')
{
- $this->pdo->exec('INSERT INTO user_data_fields (name) VALUES('.$this->pdo->quote($field_name).')');
- return $this->pdo->lastInsertId();
+ $this->pdo->exec('INSERT INTO user_data_fields (name) VALUES('.$this->pdo->quote($field_name).') ON DUPLICATE KEY UPDATE id = id');
+ return $this->get_data_field_id($field_name);
}
else return FALSE;
}
@@ -323,11 +323,7 @@ public function set_data($user_id, $user_data, $clear_previous_data = TRUE)
$sql .= '
(
'.$this->pdo->quote($user_id).',
- (
- SELECT user_data_fields.id
- FROM user_data_fields
- WHERE user_data_fields.name = '.$this->pdo->quote($field).'
- ),
+ '.User::get_data_field_id($field).',
'.$this->pdo->quote($content_piece).'
),';
}
View
@@ -124,7 +124,10 @@ public static function field_name_available($field_name)
*/
public static function get_data_field_id($field_name)
{
- return self::driver()->get_data_field_id($field_name);
+ if ($field_id = self::driver()->get_data_field_id($field_name))
+ return $field_id;
+ else
+ return self::driver()->new_field($field_name);
}
/**

0 comments on commit 84179b5

Please sign in to comment.