diff options
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Notice_tag.php | 2 | ||||
-rw-r--r-- | classes/Oauth_application_user.php | 39 | ||||
-rw-r--r-- | classes/Oauth_token_association.php | 42 | ||||
-rw-r--r-- | classes/Profile.php | 71 | ||||
-rw-r--r-- | classes/Reply.php | 2 | ||||
-rw-r--r-- | classes/Status_network_tag.php | 3 | ||||
-rw-r--r-- | classes/User.php | 31 | ||||
-rw-r--r-- | classes/statusnet.ini | 12 |
8 files changed, 163 insertions, 39 deletions
diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index 9ade36c34..ea38bb350 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -60,7 +60,7 @@ class Notice_tag extends Memcached_DataObject } if ($max_id != 0) { - $nt->whereAdd('notice_id < ' . $max_id); + $nt->whereAdd('notice_id <= ' . $max_id); } $nt->orderBy('notice_id DESC'); diff --git a/classes/Oauth_application_user.php b/classes/Oauth_application_user.php index 3d4238d64..e1b4b8c04 100644 --- a/classes/Oauth_application_user.php +++ b/classes/Oauth_application_user.php @@ -24,20 +24,51 @@ class Oauth_application_user extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - static function getByKeys($user, $app) + static function getByUserAndToken($user, $token) { - if (empty($user) || empty($app)) { + if (empty($user) || empty($token)) { return null; } $oau = new Oauth_application_user(); - $oau->profile_id = $user->id; - $oau->application_id = $app->id; + $oau->profile_id = $user->id; + $oau->token = $token; $oau->limit(1); $result = $oau->find(true); return empty($result) ? null : $oau; } + + function updateKeys(&$orig) + { + $this->_connect(); + $parts = array(); + foreach (array('profile_id', 'application_id', 'token', 'access_type') as $k) { + if (strcmp($this->$k, $orig->$k) != 0) { + $parts[] = $k . ' = ' . $this->_quote($this->$k); + } + } + if (count($parts) == 0) { + # No changes + return true; + } + $toupdate = implode(', ', $parts); + + $table = $this->tableName(); + if(common_config('db','quote_identifiers')) { + $table = '"' . $table . '"'; + } + $qry = 'UPDATE ' . $table . ' SET ' . $toupdate . + ' WHERE profile_id = ' . $orig->profile_id + . ' AND application_id = ' . $orig->application_id + . " AND token = '$orig->token'"; + $orig->decache(); + $result = $this->query($qry); + if ($result) { + $this->encache(); + } + return $result; + } } diff --git a/classes/Oauth_token_association.php b/classes/Oauth_token_association.php new file mode 100644 index 000000000..66be22b5d --- /dev/null +++ b/classes/Oauth_token_association.php @@ -0,0 +1,42 @@ +<?php +/** + * Table Definition for oauth_association + */ +require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; + +class Oauth_token_association extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'oauth_token_association'; // table name + public $profile_id; // int(4) primary_key not_null + public $application_id; // int(4) primary_key not_null + public $token; // varchar(255) primary key not null + public $created; // datetime not_null + public $modified; // timestamp not_null default_CURRENT_TIMESTAMP + + /* Static get */ + function staticGet($k, $v = NULL) { + return Memcached_DataObject::staticGet('oauth_token_association', $k, $v); + } + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + static function getByUserAndToken($user, $token) + { + if (empty($user) || empty($token)) { + return null; + } + + $oau = new oauth_request_token(); + + $oau->profile_id = $user->id; + $oau->token = $token; + $oau->limit(1); + + $result = $oau->find(true); + + return empty($result) ? null : $oau; + } +} diff --git a/classes/Profile.php b/classes/Profile.php index 8b05bcbf9..e05b8bf27 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -199,7 +199,7 @@ class Profile extends Memcached_DataObject } if ($max_id != 0) { - $query .= " and id < $max_id"; + $query .= " and id <= $max_id"; } $query .= ' order by id DESC'; @@ -240,7 +240,7 @@ class Profile extends Memcached_DataObject } if ($max_id != 0) { - $query .= " and id < $max_id"; + $query .= " and id <= $max_id"; } $query .= ' order by id DESC'; @@ -401,10 +401,10 @@ class Profile extends Memcached_DataObject return $profile; } - function getApplications($offset = 0, $limit = null) + function getConnectedApps($offset = 0, $limit = null) { $qry = - 'SELECT a.* ' . + 'SELECT u.* ' . 'FROM oauth_application_user u, oauth_application a ' . 'WHERE u.profile_id = %d ' . 'AND a.id = u.application_id ' . @@ -419,11 +419,11 @@ class Profile extends Memcached_DataObject } } - $application = new Oauth_application(); + $apps = new Oauth_application_user(); - $cnt = $application->query(sprintf($qry, $this->id)); + $cnt = $apps->query(sprintf($qry, $this->id)); - return $application; + return $apps; } function subscriptionCount() @@ -758,43 +758,52 @@ class Profile extends Memcached_DataObject function grantRole($name) { - $role = new Profile_role(); + if (Event::handle('StartGrantRole', array($this, $name))) { - $role->profile_id = $this->id; - $role->role = $name; - $role->created = common_sql_now(); + $role = new Profile_role(); - $result = $role->insert(); + $role->profile_id = $this->id; + $role->role = $name; + $role->created = common_sql_now(); - if (!$result) { - common_log_db_error($role, 'INSERT', __FILE__); - return false; + $result = $role->insert(); + + if (!$result) { + throw new Exception("Can't save role '$name' for profile '{$this->id}'"); + } + + Event::handle('EndGrantRole', array($this, $name)); } - return true; + return $result; } function revokeRole($name) { - $role = Profile_role::pkeyGet(array('profile_id' => $this->id, - 'role' => $name)); + if (Event::handle('StartRevokeRole', array($this, $name))) { - if (empty($role)) { - // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. - // TRANS: %1$s is the role name, %2$s is the user ID (number). - throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id)); - } + $role = Profile_role::pkeyGet(array('profile_id' => $this->id, + 'role' => $name)); - $result = $role->delete(); + if (empty($role)) { + // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. + // TRANS: %1$s is the role name, %2$s is the user ID (number). + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id)); + } - if (!$result) { - common_log_db_error($role, 'DELETE', __FILE__); - // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. - // TRANS: %1$s is the role name, %2$s is the user ID (number). - throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id)); - } + $result = $role->delete(); - return true; + if (!$result) { + common_log_db_error($role, 'DELETE', __FILE__); + // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. + // TRANS: %1$s is the role name, %2$s is the user ID (number). + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id)); + } + + Event::handle('EndRevokeRole', array($this, $name)); + + return true; + } } function isSandboxed() diff --git a/classes/Reply.php b/classes/Reply.php index dc6296bda..da8a4f685 100644 --- a/classes/Reply.php +++ b/classes/Reply.php @@ -55,7 +55,7 @@ class Reply extends Memcached_DataObject } if ($max_id != 0) { - $reply->whereAdd('notice_id < ' . $max_id); + $reply->whereAdd('notice_id <= ' . $max_id); } $reply->orderBy('notice_id DESC'); diff --git a/classes/Status_network_tag.php b/classes/Status_network_tag.php index a5893c114..2273ecb2e 100644 --- a/classes/Status_network_tag.php +++ b/classes/Status_network_tag.php @@ -43,7 +43,6 @@ class Status_network_tag extends Safe_DataObject $this->_connect(); } - /* Static get */ function staticGet($k,$v=null) { @@ -99,7 +98,7 @@ class Status_network_tag extends Safe_DataObject if (Status_network::$cache) { $packed = implode('|', $result); - Status_network::$cache->set($key, $packed, 3600); + Status_network::$cache->set($key, $packed, 0, 3600); } return $result; diff --git a/classes/User.php b/classes/User.php index 259df7e2c..9188938b1 100644 --- a/classes/User.php +++ b/classes/User.php @@ -870,4 +870,35 @@ class User extends Memcached_DataObject return $owner; } + + /** + * Pull the primary site account to use in single-user mode. + * If a valid user nickname is listed in 'singleuser':'nickname' + * in the config, this will be used; otherwise the site owner + * account is taken by default. + * + * @return User + * @throws ServerException if no valid single user account is present + * @throws ServerException if called when not in single-user mode + */ + static function singleUser() + { + if (common_config('singleuser', 'enabled')) { + $nickname = common_config('singleuser', 'nickname'); + if ($nickname) { + $user = User::staticGet('nickname', $nickname); + } else { + $user = User::siteOwner(); + } + if ($user) { + return $user; + } else { + // TRANS: Server exception. + throw new ServerException(_('No single user defined for single-user mode.')); + } + } else { + // TRANS: Server exception. + throw new ServerException(_('Single-user mode code called when not enabled.')); + } + } } diff --git a/classes/statusnet.ini b/classes/statusnet.ini index 920e0157d..d1d2980fd 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -401,6 +401,18 @@ modified = 384 profile_id = K application_id = K +[oauth_token_association] +profile_id = 129 +application_id = 129 +token = 130 +created = 142 +modified = 384 + +[oauth_token_association__keys] +profile_id = K +application_id = K +token = K + [profile] id = 129 nickname = 130 |