diff options
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Config.php | 6 | ||||
-rw-r--r-- | classes/File_redirection.php | 39 | ||||
-rw-r--r-- | classes/Managed_DataObject.php | 154 | ||||
-rw-r--r-- | classes/Memcached_DataObject.php | 32 | ||||
-rw-r--r-- | classes/Notice.php | 24 | ||||
-rw-r--r-- | classes/Notice_tag.php | 6 | ||||
-rw-r--r-- | classes/Profile.php | 52 | ||||
-rw-r--r-- | classes/Schema_version.php | 22 | ||||
-rw-r--r-- | classes/User.php | 7 | ||||
-rw-r--r-- | classes/User_im_prefs.php | 94 | ||||
-rwxr-xr-x | classes/User_urlshortener_prefs.php | 105 | ||||
-rw-r--r-- | classes/statusnet.ini | 44 |
12 files changed, 515 insertions, 70 deletions
diff --git a/classes/Config.php b/classes/Config.php index 43b99587f..e14730438 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -58,7 +58,7 @@ class Config extends Memcached_DataObject $c = self::memcache(); if (!empty($c)) { - $settings = $c->get(common_cache_key(self::settingsKey)); + $settings = $c->get(Cache::key(self::settingsKey)); if ($settings !== false) { return $settings; } @@ -77,7 +77,7 @@ class Config extends Memcached_DataObject $config->free(); if (!empty($c)) { - $c->set(common_cache_key(self::settingsKey), $settings); + $c->set(Cache::key(self::settingsKey), $settings); } return $settings; @@ -154,7 +154,7 @@ class Config extends Memcached_DataObject $c = self::memcache(); if (!empty($c)) { - $c->delete(common_cache_key(self::settingsKey)); + $c->delete(Cache::key(self::settingsKey)); } } } diff --git a/classes/File_redirection.php b/classes/File_redirection.php index 53c15bf8b..1096f500b 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -190,22 +190,51 @@ class File_redirection extends Memcached_DataObject * @param User $user whose shortening options to use; defaults to the current web session user * @return string */ - function makeShort($long_url, $user=null) { - + function makeShort($long_url, $user=null) + { $canon = File_redirection::_canonUrl($long_url); $short_url = File_redirection::_userMakeShort($canon, $user); // Did we get one? Is it shorter? - if (!empty($short_url) && mb_strlen($short_url) < mb_strlen($long_url)) { + + if (!empty($short_url)) { + return $short_url; + } else { + return $long_url; + } + } + + /** + * Shorten a URL with the current user's configured shortening + * options, if applicable. + * + * If it cannot be shortened or the "short" URL is longer than the + * original, the original is returned. + * + * If the referenced item has not been seen before, embedding data + * may be saved. + * + * @param string $long_url + * @return string + */ + + function forceShort($long_url, $user) + { + $canon = File_redirection::_canonUrl($long_url); + + $short_url = File_redirection::_userMakeShort($canon, $user, true); + + // Did we get one? Is it shorter? + if (!empty($short_url)) { return $short_url; } else { return $long_url; } } - function _userMakeShort($long_url, User $user=null) { - $short_url = common_shorten_url($long_url, $user); + function _userMakeShort($long_url, User $user=null, $force = false) { + $short_url = common_shorten_url($long_url, $user, $force); if (!empty($short_url) && $short_url != $long_url) { $short_url = (string)$short_url; // store it diff --git a/classes/Managed_DataObject.php b/classes/Managed_DataObject.php new file mode 100644 index 000000000..7990d7f40 --- /dev/null +++ b/classes/Managed_DataObject.php @@ -0,0 +1,154 @@ +<?php +/* + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2010, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * Wrapper for Memcached_DataObject which knows its own schema definition. + * Builds its own damn settings from a schema definition. + * + * @author Brion Vibber <brion@status.net> + */ +abstract class Managed_DataObject extends Memcached_DataObject +{ + /** + * The One True Thingy that must be defined and declared. + */ + public static abstract function schemaDef(); + + /** + * get/set an associative array of table columns + * + * @access public + * @return array (associative) + */ + function table() + { + // Hack for PHP 5.2 not supporting late static binding + //$table = static::schemaDef(); + $table = call_user_func(array(get_class($this), 'schemaDef')); + return array_map(array($this, 'columnBitmap'), $table['fields']); + } + + /** + * get/set an array of table primary keys + * + * Key info is pulled from the table definition array. + * + * @access private + * @return array + */ + function keys() + { + return array_keys($this->keyTypes()); + } + + /** + * Get a sequence key + * + * Returns the first serial column defined in the table, if any. + * + * @access private + * @return array (column,use_native,sequence_name) + */ + + function sequenceKey() + { + $table = call_user_func(array(get_class($this), 'schemaDef')); + foreach ($table['fields'] as $name => $column) { + if ($column['type'] == 'serial') { + // We have a serial/autoincrement column. + // Declare it to be a native sequence! + return array($name, true, false); + } + } + + // No sequence key on this table. + return array(false, false, false); + } + + /** + * Return key definitions for DB_DataObject and Memcache_DataObject. + * + * DB_DataObject needs to know about keys that the table has; this function + * defines them. + * + * @return array key definitions + */ + + function keyTypes() + { + $table = call_user_func(array(get_class($this), 'schemaDef')); + + if (!empty($table['unique keys'])) { + foreach ($table['unique keys'] as $idx => $fields) { + foreach ($fields as $name) { + $keys[$name] = 'U'; + } + } + } + + if (!empty($table['primary key'])) { + foreach ($table['primary key'] as $name) { + $keys[$name] = 'K'; + } + } + return $keys; + } + + /** + * Build the appropriate DB_DataObject bitfield map for this field. + * + * @param array $column + * @return int + */ + function columnBitmap($column) + { + $type = $column['type']; + + // For quoting style... + $intTypes = array('int', + 'integer', + 'float', + 'serial', + 'numeric'); + if (in_array($type, $intTypes)) { + $style = DB_DATAOBJECT_INT; + } else { + $style = DB_DATAOBJECT_STR; + } + + // Data type formatting style... + $formatStyles = array('blob' => DB_DATAOBJECT_BLOB, + 'text' => DB_DATAOBJECT_TXT, + 'date' => DB_DATAOBJECT_DATE, + 'time' => DB_DATAOBJECT_TIME, + 'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME, + 'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP); + + if (isset($formatStyles[$type])) { + $style |= $formatStyles[$type]; + } + + // Nullable? + if (!empty($column['not null'])) { + $style |= DB_DATAOBJECT_NOTNULL; + } + + return $style; + } +}
\ No newline at end of file diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index ccfd886a1..27bb5d3c9 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -124,7 +124,7 @@ class Memcached_DataObject extends Safe_DataObject } static function memcache() { - return common_memcache(); + return Cache::instance(); } static function cacheKey($cls, $k, $v) { @@ -134,7 +134,7 @@ class Memcached_DataObject extends Safe_DataObject str_replace("\n", " ", $e->getTraceAsString())); } $vstr = self::valueString($v); - return common_cache_key(strtolower($cls).':'.$k.':'.$vstr); + return Cache::key(strtolower($cls).':'.$k.':'.$vstr); } static function getcached($cls, $k, $v) { @@ -302,8 +302,8 @@ class Memcached_DataObject extends Safe_DataObject $inst->query($qry); return $inst; } - $key_part = common_keyize($cls).':'.md5($qry); - $ckey = common_cache_key($key_part); + $key_part = Cache::keyize($cls).':'.md5($qry); + $ckey = Cache::key($key_part); $stored = $c->get($ckey); if ($stored !== false) { @@ -338,13 +338,27 @@ class Memcached_DataObject extends Safe_DataObject } $start = microtime(true); - $result = parent::_query($string); + $fail = false; + try { + $result = parent::_query($string); + } catch (Exception $e) { + $fail = $e; + } $delta = microtime(true) - $start; $limit = common_config('db', 'log_slow_queries'); if (($limit > 0 && $delta >= $limit) || common_config('db', 'log_queries')) { $clean = $this->sanitizeQuery($string); - common_log(LOG_DEBUG, sprintf("DB query (%0.3fs): %s", $delta, $clean)); + if ($fail) { + $msg = sprintf("FAILED DB query (%0.3fs): %s - %s", $delta, $fail->getMessage(), $clean); + } else { + $msg = sprintf("DB query (%0.3fs): %s", $delta, $clean); + } + common_log(LOG_DEBUG, $msg); + } + + if ($fail) { + throw $fail; } return $result; } @@ -550,7 +564,7 @@ class Memcached_DataObject extends Safe_DataObject $keyPart = vsprintf($format, $args); - $cacheKey = common_cache_key($keyPart); + $cacheKey = Cache::key($keyPart); return $c->delete($cacheKey); } @@ -592,7 +606,7 @@ class Memcached_DataObject extends Safe_DataObject return false; } - $cacheKey = common_cache_key($keyPart); + $cacheKey = Cache::key($keyPart); return $c->get($cacheKey); } @@ -605,7 +619,7 @@ class Memcached_DataObject extends Safe_DataObject return false; } - $cacheKey = common_cache_key($keyPart); + $cacheKey = Cache::key($keyPart); return $c->set($cacheKey, $value, $flag, $expiry); } diff --git a/classes/Notice.php b/classes/Notice.php index d6710c3e2..c36fb702b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -599,7 +599,7 @@ class Notice extends Memcached_DataObject function getStreamByIds($ids) { - $cache = common_memcache(); + $cache = Cache::instance(); if (!empty($cache)) { $notices = array(); @@ -775,7 +775,7 @@ class Notice extends Memcached_DataObject $c = self::memcache(); if (!empty($c)) { - $ni = $c->get(common_cache_key('notice:who_gets:'.$this->id)); + $ni = $c->get(Cache::key('notice:who_gets:'.$this->id)); if ($ni !== false) { return $ni; } @@ -827,7 +827,7 @@ class Notice extends Memcached_DataObject if (!empty($c)) { // XXX: pack this data better - $c->set(common_cache_key('notice:who_gets:'.$this->id), $ni); + $c->set(Cache::key('notice:who_gets:'.$this->id), $ni); } return $ni; @@ -1451,7 +1451,7 @@ class Notice extends Memcached_DataObject function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0) { - $cache = common_memcache(); + $cache = Cache::instance(); if (empty($cache) || $since_id != 0 || $max_id != 0 || @@ -1461,7 +1461,7 @@ class Notice extends Memcached_DataObject $max_id))); } - $idkey = common_cache_key($cachekey); + $idkey = Cache::key($cachekey); $idstr = $cache->get($idkey); @@ -1643,17 +1643,17 @@ class Notice extends Memcached_DataObject function repeatStream($limit=100) { - $cache = common_memcache(); + $cache = Cache::instance(); if (empty($cache)) { $ids = $this->_repeatStreamDirect($limit); } else { - $idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id)); + $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id)); if ($idstr !== false) { $ids = explode(',', $idstr); } else { $ids = $this->_repeatStreamDirect(100); - $cache->set(common_cache_key('notice:repeats:'.$this->id), implode(',', $ids)); + $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids)); } if ($limit < 100) { // We do a max of 100, so slice down to limit @@ -1804,10 +1804,10 @@ class Notice extends Memcached_DataObject if ($tag->find()) { while ($tag->fetch()) { - self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, common_keyize($tag->tag)); - self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, common_keyize($tag->tag)); - self::blow('notice_tag:notice_ids:%s', common_keyize($tag->tag)); - self::blow('notice_tag:notice_ids:%s;last', common_keyize($tag->tag)); + self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, Cache::keyize($tag->tag)); + self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, Cache::keyize($tag->tag)); + self::blow('notice_tag:notice_ids:%s', Cache::keyize($tag->tag)); + self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($tag->tag)); $tag->delete(); } } diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index 6eada7022..ea38bb350 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -40,7 +40,7 @@ class Notice_tag extends Memcached_DataObject $ids = Notice::stream(array('Notice_tag', '_streamDirect'), array($tag), - 'notice_tag:notice_ids:' . common_keyize($tag), + 'notice_tag:notice_ids:' . Cache::keyize($tag), $offset, $limit); return Notice::getStreamByIds($ids); @@ -82,9 +82,9 @@ class Notice_tag extends Memcached_DataObject function blowCache($blowLast=false) { - self::blow('notice_tag:notice_ids:%s', common_keyize($this->tag)); + self::blow('notice_tag:notice_ids:%s', Cache::keyize($this->tag)); if ($blowLast) { - self::blow('notice_tag:notice_ids:%s;last', common_keyize($this->tag)); + self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($this->tag)); } } diff --git a/classes/Profile.php b/classes/Profile.php index 8dbdcbd97..05df8899e 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -457,10 +457,10 @@ class Profile extends Memcached_DataObject function subscriptionCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $cnt = $c->get(common_cache_key('profile:subscription_count:'.$this->id)); + $cnt = $c->get(Cache::key('profile:subscription_count:'.$this->id)); if (is_integer($cnt)) { return (int) $cnt; } @@ -474,7 +474,7 @@ class Profile extends Memcached_DataObject $cnt = ($cnt > 0) ? $cnt - 1 : $cnt; if (!empty($c)) { - $c->set(common_cache_key('profile:subscription_count:'.$this->id), $cnt); + $c->set(Cache::key('profile:subscription_count:'.$this->id), $cnt); } return $cnt; @@ -482,9 +482,9 @@ class Profile extends Memcached_DataObject function subscriberCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $cnt = $c->get(common_cache_key('profile:subscriber_count:'.$this->id)); + $cnt = $c->get(Cache::key('profile:subscriber_count:'.$this->id)); if (is_integer($cnt)) { return (int) $cnt; } @@ -496,7 +496,7 @@ class Profile extends Memcached_DataObject $cnt = (int) $sub->count('distinct subscriber'); if (!empty($c)) { - $c->set(common_cache_key('profile:subscriber_count:'.$this->id), $cnt); + $c->set(Cache::key('profile:subscriber_count:'.$this->id), $cnt); } return $cnt; @@ -527,7 +527,7 @@ class Profile extends Memcached_DataObject function hasFave($notice) { - $cache = common_memcache(); + $cache = Cache::instance(); // XXX: Kind of a hack. @@ -562,9 +562,9 @@ class Profile extends Memcached_DataObject function faveCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $cnt = $c->get(common_cache_key('profile:fave_count:'.$this->id)); + $cnt = $c->get(Cache::key('profile:fave_count:'.$this->id)); if (is_integer($cnt)) { return (int) $cnt; } @@ -575,7 +575,7 @@ class Profile extends Memcached_DataObject $cnt = (int) $faves->count('distinct notice_id'); if (!empty($c)) { - $c->set(common_cache_key('profile:fave_count:'.$this->id), $cnt); + $c->set(Cache::key('profile:fave_count:'.$this->id), $cnt); } return $cnt; @@ -583,10 +583,10 @@ class Profile extends Memcached_DataObject function noticeCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $cnt = $c->get(common_cache_key('profile:notice_count:'.$this->id)); + $cnt = $c->get(Cache::key('profile:notice_count:'.$this->id)); if (is_integer($cnt)) { return (int) $cnt; } @@ -597,7 +597,7 @@ class Profile extends Memcached_DataObject $cnt = (int) $notices->count('distinct id'); if (!empty($c)) { - $c->set(common_cache_key('profile:notice_count:'.$this->id), $cnt); + $c->set(Cache::key('profile:notice_count:'.$this->id), $cnt); } return $cnt; @@ -605,47 +605,47 @@ class Profile extends Memcached_DataObject function blowFavesCache() { - $cache = common_memcache(); + $cache = Cache::instance(); if ($cache) { // Faves don't happen chronologically, so we need to blow // ;last cache, too - $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id)); - $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last')); - $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id)); - $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last')); + $cache->delete(Cache::key('fave:ids_by_user:'.$this->id)); + $cache->delete(Cache::key('fave:ids_by_user:'.$this->id.';last')); + $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id)); + $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id.';last')); } $this->blowFaveCount(); } function blowSubscriberCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $c->delete(common_cache_key('profile:subscriber_count:'.$this->id)); + $c->delete(Cache::key('profile:subscriber_count:'.$this->id)); } } function blowSubscriptionCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $c->delete(common_cache_key('profile:subscription_count:'.$this->id)); + $c->delete(Cache::key('profile:subscription_count:'.$this->id)); } } function blowFaveCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $c->delete(common_cache_key('profile:fave_count:'.$this->id)); + $c->delete(Cache::key('profile:fave_count:'.$this->id)); } } function blowNoticeCount() { - $c = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { - $c->delete(common_cache_key('profile:notice_count:'.$this->id)); + $c->delete(Cache::key('profile:notice_count:'.$this->id)); } } diff --git a/classes/Schema_version.php b/classes/Schema_version.php new file mode 100644 index 000000000..6b464c6d1 --- /dev/null +++ b/classes/Schema_version.php @@ -0,0 +1,22 @@ +<?php +/** + * Table Definition for schema_version + */ + +class Schema_version extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'schema_version'; // table name + public $table_name; // varchar(64) primary_key not_null + public $checksum; // varchar(64) not_null + public $modified; // datetime() not_null + + /* Static get */ + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Schema_version',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/User.php b/classes/User.php index 8a3190cbf..d4f182f7e 100644 --- a/classes/User.php +++ b/classes/User.php @@ -48,11 +48,6 @@ class User extends Memcached_DataObject public $language; // varchar(50) public $timezone; // varchar(50) public $emailpost; // tinyint(1) default_1 - public $jabber; // varchar(255) unique_key - public $jabbernotify; // tinyint(1) - public $jabberreplies; // tinyint(1) - public $jabbermicroid; // tinyint(1) default_1 - public $updatefrompresence; // tinyint(1) public $sms; // varchar(64) unique_key public $carrier; // int(4) public $smsnotify; // tinyint(1) @@ -94,7 +89,7 @@ class User extends Memcached_DataObject { $this->_connect(); $parts = array(); - foreach (array('nickname', 'email', 'jabber', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) { + foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) { if (strcmp($this->$k, $orig->$k) != 0) { $parts[] = $k . ' = ' . $this->_quote($this->$k); } diff --git a/classes/User_im_prefs.php b/classes/User_im_prefs.php new file mode 100644 index 000000000..75be8969e --- /dev/null +++ b/classes/User_im_prefs.php @@ -0,0 +1,94 @@ +<?php +/** + * StatusNet, the distributed open-source microblogging tool + * + * Data class for user IM preferences + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Data + * @package StatusNet + * @author Craig Andrews <candrews@integralblue.com> + * @copyright 2009 StatusNet Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +class User_im_prefs extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'user_im_prefs'; // table name + public $user_id; // int(4) primary_key not_null + public $screenname; // varchar(255) not_null + public $transport; // varchar(255) not_null + public $notify; // tinyint(1) + public $replies; // tinyint(1) + public $microid; // tinyint(1) + public $updatefrompresence; // tinyint(1) + public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00 + public $modified; // timestamp not_null default_CURRENT_TIMESTAMP + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_im_prefs',$k,$v); } + + function pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('User_im_prefs', $kv); + } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + /* + DB_DataObject calculates the sequence key(s) by taking the first key returned by the keys() function. + In this case, the keys() function returns user_id as the first key. user_id is not a sequence, but + DB_DataObject's sequenceKey() will incorrectly think it is. Then, since the sequenceKey() is a numeric + type, but is not set to autoincrement in the database, DB_DataObject will create a _seq table and + manage the sequence itself. This is not the correct behavior for the user_id in this class. + So we override that incorrect behavior, and simply say there is no sequence key. + */ + function sequenceKey() + { + return array(false,false); + } + + /** + * We have two compound keys with unique constraints: + * (transport, user_id) which is our primary key, and + * (transport, screenname) which is an additional constraint. + * + * Currently there's not a way to represent that second key + * in the general keys list, so we're adding it here to the + * list of keys to use for caching, ensuring that it gets + * cleared as well when we change. + * + * @return array of cache keys + */ + function _allCacheKeys() + { + $ukeys = 'transport,screenname'; + $uvals = $this->transport . ',' . $this->screenname; + + $ckeys = parent::_allCacheKeys(); + $ckeys[] = $this->cacheKey($this->tableName(), $ukeys, $uvals); + return $ckeys; + } + +} diff --git a/classes/User_urlshortener_prefs.php b/classes/User_urlshortener_prefs.php new file mode 100755 index 000000000..e0f85af01 --- /dev/null +++ b/classes/User_urlshortener_prefs.php @@ -0,0 +1,105 @@ +<?php +/* + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2010, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +class User_urlshortener_prefs extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'user_urlshortener_prefs'; // table name + public $user_id; // int(4) primary_key not_null + public $urlshorteningservice; // varchar(50) default_ur1.ca + public $maxurllength; // int(4) not_null + public $maxnoticelength; // int(4) not_null + public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00 + public $modified; // timestamp not_null default_CURRENT_TIMESTAMP + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_urlshortener_prefs',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + function sequenceKey() + { + return array(false, false, false); + } + + static function maxUrlLength($user) + { + $def = common_config('url', 'maxlength'); + + $prefs = self::getPrefs($user); + + if (empty($prefs)) { + return $def; + } else { + return $prefs->maxurllength; + } + } + + static function maxNoticeLength($user) + { + $def = common_config('url', 'maxnoticelength'); + + if ($def == -1) { + $def = Notice::maxContent(); + } + + $prefs = self::getPrefs($user); + + if (empty($prefs)) { + return $def; + } else { + return $prefs->maxnoticelength; + } + } + + static function urlShorteningService($user) + { + $def = common_config('url', 'shortener'); + + $prefs = self::getPrefs($user); + + if (empty($prefs)) { + if (!empty($user)) { + return $user->urlshorteningservice; + } else { + return $def; + } + } else { + return $prefs->urlshorteningservice; + } + } + + static function getPrefs($user) + { + if (empty($user)) { + return null; + } + + $prefs = User_urlshortener_prefs::staticGet('user_id', $user->id); + + return $prefs; + } +} diff --git a/classes/statusnet.ini b/classes/statusnet.ini index ef631e28d..d1d2980fd 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -509,6 +509,14 @@ replied_id = 1 notice_id = K profile_id = K +[schema_version] +table_name = 130 +checksum = 130 +modified = 384 + +[schema_version__keys] +table_name = K + [session] id = 130 session_data = 34 @@ -573,11 +581,6 @@ emailmicroid = 17 language = 2 timezone = 2 emailpost = 17 -jabber = 2 -jabbernotify = 17 -jabberreplies = 17 -jabbermicroid = 17 -updatefrompresence = 17 sms = 2 carrier = 1 smsnotify = 17 @@ -597,7 +600,6 @@ id = K nickname = U email = U incomingemail = U -jabber = U sms = U uri = U @@ -650,3 +652,33 @@ modified = 384 [user_location_prefs__keys] user_id = K + +[user_im_prefs] +user_id = 129 +screenname = 130 +transport = 130 +notify = 17 +replies = 17 +microid = 17 +updatefrompresence = 17 +created = 142 +modified = 384 + +[user_im_prefs__keys] +user_id = K +transport = K +; There's another unique index on (transport, screenname) +; but we have no way to represent a compound index other than +; the primary key in here. To ensure proper cache purging, +; we need to tweak the class. + +[user_urlshortener_prefs] +user_id = 129 +urlshorteningservice = 2 +maxurllength = 129 +maxnoticelength = 129 +created = 142 +modified = 384 + +[user_urlshortener_prefs__keys] +user_id = K |