CS fixes and return values fixes

pull/267/merge
Aleksander Machniak 8 years ago
parent f1ec339893
commit d1cf69562f

@ -2250,7 +2250,7 @@ class rcube_imap_generic
} }
$result = $this->execute('UID STORE', array( $result = $this->execute('UID STORE', array(
$this->compressMessageSet($messages), $mod . 'FLAGS.SILENT', "($flag)"), $this->compressMessageSet($messages), $mod . 'FLAGS', "($flag)"),
self::COMMAND_NORESPONSE); self::COMMAND_NORESPONSE);
return $result == self::ERROR_OK; return $result == self::ERROR_OK;

@ -91,7 +91,8 @@ class rcube_user
/** /**
* Build a user name string (as e-mail address) * Build a user name string (as e-mail address)
* *
* @param string $part Username part (empty or 'local' or 'domain', 'mail') * @param string $part Username part (empty or 'local' or 'domain', 'mail')
*
* @return string Full user name or its part * @return string Full user name or its part
*/ */
function get_username($part = null) function get_username($part = null)
@ -117,13 +118,12 @@ class rcube_user
return $domain; return $domain;
} }
if (!empty($domain)) if (!empty($domain)) {
return $local . '@' . $domain; return $local . '@' . $domain;
else }
return $local;
}
return false; return $local;
}
} }
/** /**
@ -175,14 +175,18 @@ class rcube_user
*/ */
function save_prefs($a_user_prefs, $no_session = false) function save_prefs($a_user_prefs, $no_session = false)
{ {
if (!$this->ID) if (!$this->ID) {
return false; return false;
}
$plugin = $this->rc->plugins->exec_hook('preferences_update', array( $plugin = $this->rc->plugins->exec_hook('preferences_update', array(
'userid' => $this->ID, 'prefs' => $a_user_prefs, 'old' => (array)$this->get_prefs())); 'userid' => $this->ID,
'prefs' => $a_user_prefs,
'old' => (array)$this->get_prefs()
));
if (!empty($plugin['abort'])) { if (!empty($plugin['abort'])) {
return; return false;
} }
$a_user_prefs = $plugin['prefs']; $a_user_prefs = $plugin['prefs'];
@ -262,7 +266,7 @@ class rcube_user
/** /**
* Return a list of all user emails (from identities) * Return a list of all user emails (from identities)
* *
* @param bool Return only default identity * @param bool $default Return only default identity
* *
* @return array List of emails (identity_id, name, email) * @return array List of emails (identity_id, name, email)
*/ */
@ -289,7 +293,8 @@ class rcube_user
/** /**
* Get default identity of this user * Get default identity of this user
* *
* @param int $id Identity ID. If empty, the default identity is returned * @param int $id Identity ID. If empty, the default identity is returned
*
* @return array Hash array with all cols of the identity record * @return array Hash array with all cols of the identity record
*/ */
function get_identity($id = null) function get_identity($id = null)
@ -342,14 +347,16 @@ class rcube_user
/** /**
* Update a specific identity record * Update a specific identity record
* *
* @param int $iid Identity ID * @param int $iid Identity ID
* @param array $data Hash array with col->value pairs to save * @param array $data Hash array with col->value pairs to save
*
* @return boolean True if saved successfully, false if nothing changed * @return boolean True if saved successfully, false if nothing changed
*/ */
function update_identity($iid, $data) function update_identity($iid, $data)
{ {
if (!$this->ID) if (!$this->ID) {
return false; return false;
}
$query_cols = $query_params = array(); $query_cols = $query_params = array();
@ -373,19 +380,21 @@ class rcube_user
$this->identities = array(); $this->identities = array();
$this->emails = null; $this->emails = null;
return $this->db->affected_rows(); return $this->db->affected_rows() > 0;
} }
/** /**
* Create a new identity record linked with this user * Create a new identity record linked with this user
* *
* @param array $data Hash array with col->value pairs to save * @param array $data Hash array with col->value pairs to save
* @return int The inserted identity ID or false on error *
* @return int The inserted identity ID or false on error
*/ */
function insert_identity($data) function insert_identity($data)
{ {
if (!$this->ID) if (!$this->ID) {
return false; return false;
}
unset($data['user_id']); unset($data['user_id']);
@ -408,19 +417,21 @@ class rcube_user
$this->identities = array(); $this->identities = array();
$this->emails = null; $this->emails = null;
return $this->db->insert_id('identities'); return $this->db->insert_id('identities') ?: false;
} }
/** /**
* Mark the given identity as deleted * Mark the given identity as deleted
* *
* @param int $iid Identity ID * @param int $iid Identity ID
*
* @return boolean True if deleted successfully, false if nothing changed * @return boolean True if deleted successfully, false if nothing changed
*/ */
function delete_identity($iid) function delete_identity($iid)
{ {
if (!$this->ID) if (!$this->ID) {
return false; return false;
}
$sql_result = $this->db->query( $sql_result = $this->db->query(
"SELECT count(*) AS ident_count FROM ".$this->db->table_name('identities', true). "SELECT count(*) AS ident_count FROM ".$this->db->table_name('identities', true).
@ -430,8 +441,9 @@ class rcube_user
$sql_arr = $this->db->fetch_assoc($sql_result); $sql_arr = $this->db->fetch_assoc($sql_result);
// we'll not delete last identity // we'll not delete last identity
if ($sql_arr['ident_count'] <= 1) if ($sql_arr['ident_count'] <= 1) {
return -1; return false;
}
$this->db->query( $this->db->query(
"UPDATE ".$this->db->table_name('identities', true). "UPDATE ".$this->db->table_name('identities', true).
@ -445,7 +457,7 @@ class rcube_user
$this->identities = array(); $this->identities = array();
$this->emails = null; $this->emails = null;
return $this->db->affected_rows(); return $this->db->affected_rows() > 0;
} }
/** /**
@ -545,6 +557,7 @@ class rcube_user
* *
* @param string $user IMAP user name * @param string $user IMAP user name
* @param string $host IMAP host name * @param string $host IMAP host name
*
* @return rcube_user New user instance * @return rcube_user New user instance
*/ */
static function query($user, $host) static function query($user, $host)
@ -572,8 +585,6 @@ class rcube_user
if ($sql_arr) { if ($sql_arr) {
return new rcube_user($sql_arr['user_id'], $sql_arr); return new rcube_user($sql_arr['user_id'], $sql_arr);
} }
return false;
} }
/** /**
@ -581,6 +592,7 @@ class rcube_user
* *
* @param string $user IMAP user name * @param string $user IMAP user name
* @param string $host IMAP host * @param string $host IMAP host
*
* @return rcube_user New user instance * @return rcube_user New user instance
*/ */
static function create($user, $host) static function create($user, $host)
@ -606,7 +618,7 @@ class rcube_user
// plugin aborted this operation // plugin aborted this operation
if ($data['abort']) { if ($data['abort']) {
return false; return;
} }
$dbh->query( $dbh->query(
@ -686,20 +698,21 @@ class rcube_user
'message' => "Failed to create new user"), true, false); 'message' => "Failed to create new user"), true, false);
} }
return $user_id ? $user_instance : false; return $user_id ? $user_instance : null;
} }
/** /**
* Resolve username using a virtuser plugins * Resolve username using a virtuser plugins
* *
* @param string $email E-mail address to resolve * @param string $email E-mail address to resolve
*
* @return string Resolved IMAP username * @return string Resolved IMAP username
*/ */
static function email2user($email) static function email2user($email)
{ {
$rcube = rcube::get_instance(); $rcube = rcube::get_instance();
$plugin = $rcube->plugins->exec_hook('email2user', $plugin = $rcube->plugins->exec_hook('email2user',
array('email' => $email, 'user' => NULL)); array('email' => $email, 'user' => null));
return $plugin['user']; return $plugin['user'];
} }
@ -707,25 +720,26 @@ class rcube_user
/** /**
* Resolve e-mail address from virtuser plugins * Resolve e-mail address from virtuser plugins
* *
* @param string $user User name * @param string $user User name
* @param boolean $first If true returns first found entry * @param boolean $first If true returns first found entry
* @param boolean $extended If true returns email as array (email and name for identity) * @param boolean $extended If true returns email as array (email and name for identity)
*
* @return mixed Resolved e-mail address string or array of strings * @return mixed Resolved e-mail address string or array of strings
*/ */
static function user2email($user, $first=true, $extended=false) static function user2email($user, $first=true, $extended=false)
{ {
$rcube = rcube::get_instance(); $rcube = rcube::get_instance();
$plugin = $rcube->plugins->exec_hook('user2email', $plugin = $rcube->plugins->exec_hook('user2email',
array('email' => NULL, 'user' => $user, array('email' => null, 'user' => $user,
'first' => $first, 'extended' => $extended)); 'first' => $first, 'extended' => $extended));
return empty($plugin['email']) ? NULL : $plugin['email']; return empty($plugin['email']) ? null : $plugin['email'];
} }
/** /**
* Return a list of saved searches linked with this user * Return a list of saved searches linked with this user
* *
* @param int $type Search type * @param int $type Search type
* *
* @return array List of saved searches indexed by search ID * @return array List of saved searches indexed by search ID
*/ */
@ -757,7 +771,7 @@ class rcube_user
/** /**
* Return saved search data. * Return saved search data.
* *
* @param int $id Row identifier * @param int $id Row identifier
* *
* @return array Data * @return array Data
*/ */
@ -784,21 +798,20 @@ class rcube_user
'data' => unserialize($sql_arr['data']), 'data' => unserialize($sql_arr['data']),
); );
} }
return null;
} }
/** /**
* Deletes given saved search record * Deletes given saved search record
* *
* @param int $sid Search ID * @param int $sid Search ID
* *
* @return boolean True if deleted successfully, false if nothing changed * @return boolean True if deleted successfully, false if nothing changed
*/ */
function delete_search($sid) function delete_search($sid)
{ {
if (!$this->ID) if (!$this->ID) {
return false; return false;
}
$this->db->query( $this->db->query(
"DELETE FROM ".$this->db->table_name('searches', true) "DELETE FROM ".$this->db->table_name('searches', true)
@ -806,7 +819,7 @@ class rcube_user
." AND `search_id` = ?", ." AND `search_id` = ?",
(int) $this->ID, $sid); (int) $this->ID, $sid);
return $this->db->affected_rows(); return $this->db->affected_rows() > 0;
} }
/** /**
@ -814,12 +827,13 @@ class rcube_user
* *
* @param array $data Hash array with col->value pairs to save * @param array $data Hash array with col->value pairs to save
* *
* @return int The inserted search ID or false on error * @return int The inserted search ID or false on error
*/ */
function insert_search($data) function insert_search($data)
{ {
if (!$this->ID) if (!$this->ID) {
return false; return false;
}
$insert_cols[] = 'user_id'; $insert_cols[] = 'user_id';
$insert_values[] = (int) $this->ID; $insert_values[] = (int) $this->ID;
@ -837,6 +851,6 @@ class rcube_user
call_user_func_array(array($this->db, 'query'), call_user_func_array(array($this->db, 'query'),
array_merge(array($sql), $insert_values)); array_merge(array($sql), $insert_values));
return $this->db->insert_id('searches'); return $this->db->insert_id('searches') ?: false;
} }
} }

Loading…
Cancel
Save