From dedabf1fac4e57622853045c5c530aef6d730a36 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 12 Jun 2016 10:45:32 +0800 Subject: [PATCH] fix empty realname column of Authme --- libraries/Database/AdaptedDatabase.class.php | 14 +++++++++++--- libraries/Database/Database.class.php | 13 ++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/libraries/Database/AdaptedDatabase.class.php b/libraries/Database/AdaptedDatabase.class.php index 7066483f..4690f5f9 100644 --- a/libraries/Database/AdaptedDatabase.class.php +++ b/libraries/Database/AdaptedDatabase.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-03-18 16:53:55 * @Last Modified by: printempw - * @Last Modified time: 2016-04-03 15:36:35 + * @Last Modified time: 2016-06-12 10:44:56 */ namespace Database; @@ -35,11 +35,19 @@ class AdaptedDatabase extends Database implements PasswordInterface, SyncInterfa if ($exist_in_bs_table && !$exist_in_data_table) { $result = $this->select('username', $username); - $this->insert(array( + $user_data = array( $this->column_uname => $username, $this->column_passwd => $result['password'], $this->column_ip => $result['ip'] - ), $this->data_table); + ); + + // quick fix for Authme realname + if (Option::get('data_adapter') == "Authme") { + if ($this->checkColumnExist('realname', $this->data_table)) + $user_data['realname'] = $username; + } + + $this->insert($user_data, $this->data_table); // recursion return $this->sync($username); diff --git a/libraries/Database/Database.class.php b/libraries/Database/Database.class.php index 5248c867..ce01ac92 100644 --- a/libraries/Database/Database.class.php +++ b/libraries/Database/Database.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-02-02 21:59:06 * @Last Modified by: printempw - * @Last Modified time: 2016-04-11 17:09:09 + * @Last Modified time: 2016-06-12 10:43:47 */ namespace Database; @@ -111,6 +111,17 @@ class Database implements PasswordInterface, SyncInterface return $this->query("DELETE FROM $table".$this->where($condition)); } + public function checkTableExist($table_name) { + $sql = "SELECT table_name FROM `INFORMATION_SCHEMA`.`TABLES` WHERE (table_name ='$table_name') AND TABLE_SCHEMA='".DB_NAME."'"; + return ($this->query($sql)->num_rows == 0) ? false : true; + } + + public function checkColumnExist($column_name, $table = null) { + $table = is_null($table) ? $this->table_name : $table; + $sql = "SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE TABLE_SCHEMA = '".DB_NAME."' AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column_name'"; + return ($this->query($sql)->num_rows == 0) ? false : true; + } + public function getNumRows($key, $value, $table = null) { $table = is_null($table) ? $this->table_name : $table; $sql = "SELECT * FROM $table WHERE $key='$value'";