From 0f1d0ab4d7d50467dd7d4ab0646f04da2735b720 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 15:43:11 -0500 Subject: add DB_DataObject for forward table --- classes/Forward.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ classes/statusnet.ini | 11 ++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 classes/Forward.php mode change 100644 => 100755 classes/statusnet.ini (limited to 'classes') diff --git a/classes/Forward.php b/classes/Forward.php new file mode 100755 index 000000000..61cec34e3 --- /dev/null +++ b/classes/Forward.php @@ -0,0 +1,45 @@ +. + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Table Definition for location_namespace + */ + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +class Forward extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'forward'; // table name + public $profile_id; // int(4) primary_key not_null + public $notice_id; // int(4) primary_key not_null + public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00 + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Forward',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/statusnet.ini b/classes/statusnet.ini old mode 100644 new mode 100755 index 253f45879..a5126795b --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -1,3 +1,4 @@ + [avatar] profile_id = 129 original = 17 @@ -195,6 +196,15 @@ id = K service = K uri = U +[forward] +profile_id = 129 +notice_id = 129 +created = 142 + +[forward__keys] +profile_id = K +notice_id = K + [group_alias] alias = 130 group_id = 129 @@ -260,7 +270,6 @@ modified = 384 [login_token__keys] user_id = K -token = K [message] id = 129 -- cgit v1.2.3-54-g00ecf From 6bc6af667ec51e41570e580de43eac1f9e155d30 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 15:43:34 -0500 Subject: fix exe flag --- classes/Forward.php | 0 classes/statusnet.ini | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 classes/Forward.php mode change 100755 => 100644 classes/statusnet.ini (limited to 'classes') diff --git a/classes/Forward.php b/classes/Forward.php old mode 100755 new mode 100644 diff --git a/classes/statusnet.ini b/classes/statusnet.ini old mode 100755 new mode 100644 -- cgit v1.2.3-54-g00ecf From 72c82a2e293549c10b60ca9e295f2f430224e814 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 16:30:33 -0500 Subject: Basic function to store forwards and redistribute --- classes/Forward.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ classes/Notice.php | 34 +------------------------ classes/Notice_inbox.php | 42 ++++++++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 34 deletions(-) (limited to 'classes') diff --git a/classes/Forward.php b/classes/Forward.php index 61cec34e3..6d4848438 100644 --- a/classes/Forward.php +++ b/classes/Forward.php @@ -42,4 +42,68 @@ class Forward extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + static function saveNew($profile_id, $notice_id) + { + $forward = new Forward(); + + $forward->profile_id = $profile_id; + $forward->notice_id = $notice_id; + $forward->created = common_sql_now(); + + $forward->query('BEGIN'); + + if (!$forward->insert()) { + throw new ServerException(_("Couldn't insert forward.")); + } + + $ni = $forward->addToInboxes(); + + $forward->query('COMMIT'); + + $forward->blowCache($ni); + } + + function addToInboxes() + { + $inbox = new Notice_inbox(); + + $user = new User(); + + $user->query('SELECT id FROM user JOIN subscription ON user.id = subscription.subscriber '. + 'WHERE subscription.subscribed = '.$this->profile_id); + + $ni = array(); + + while ($user->fetch()) { + $inbox = Notice_inbox::pkeyGet(array('user_id' => $user->id, + 'notice_id' => $this->notice_id)); + + if (empty($inbox)) { + $ni[$user->id] = NOTICE_INBOX_SOURCE_FORWARD; + } else { + $inbox->free(); + } + } + + $user->free(); + + Notice_inbox::bulkInsert($this->notice_id, $this->created, $ni); + + return $ni; + } + + function blowCache($ni) + { + $cache = common_memcache(); + + if (!empty($cache)) { + foreach ($ni as $id => $source) { + $cache->delete(common_cache_key('notice_inbox:by_user:'.$id)); + $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$id)); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$id.';last')); + $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$id.';last')); + } + } + } } diff --git a/classes/Notice.php b/classes/Notice.php index 661072156..bcd7947bd 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -948,39 +948,7 @@ class Notice extends Memcached_DataObject } } - $cnt = 0; - - $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES '; - $qry = $qryhdr; - - foreach ($ni as $id => $source) { - if ($cnt > 0) { - $qry .= ', '; - } - $qry .= '('.$id.', '.$this->id.', '.$source.", '".$this->created. "') "; - $cnt++; - if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) { - // FIXME: Causes lag in replicated servers - // Notice_inbox::gc($id); - } - if ($cnt >= MAX_BOXCARS) { - $inbox = new Notice_inbox(); - $result = $inbox->query($qry); - if (PEAR::isError($result)) { - common_log_db_error($inbox, $qry); - } - $qry = $qryhdr; - $cnt = 0; - } - } - - if ($cnt > 0) { - $inbox = new Notice_inbox(); - $result = $inbox->query($qry); - if (PEAR::isError($result)) { - common_log_db_error($inbox, $qry); - } - } + Notice_inbox::bulkInsert($this->id, $this->created, $ni); return; } diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index d3e7853b1..b39006542 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -32,6 +32,7 @@ define('NOTICE_INBOX_SOFT_LIMIT', 1000); define('NOTICE_INBOX_SOURCE_SUB', 1); define('NOTICE_INBOX_SOURCE_GROUP', 2); define('NOTICE_INBOX_SOURCE_REPLY', 3); +define('NOTICE_INBOX_SOURCE_FORWARD', 4); define('NOTICE_INBOX_SOURCE_GATEWAY', -1); class Notice_inbox extends Memcached_DataObject @@ -83,7 +84,7 @@ class Notice_inbox extends Memcached_DataObject $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); } - $inbox->orderBy('notice_id DESC'); + $inbox->orderBy('created DESC'); if (!is_null($offset)) { $inbox->limit($offset, $limit); @@ -141,4 +142,43 @@ class Notice_inbox extends Memcached_DataObject 'WHERE user_id = ' . $user_id . ' ' . 'AND notice_id in ('.implode(',', $notices).')'); } + + static function bulkInsert($notice_id, $created, $ni) + { + $cnt = 0; + + $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES '; + $qry = $qryhdr; + + foreach ($ni as $id => $source) { + if ($cnt > 0) { + $qry .= ', '; + } + $qry .= '('.$id.', '.$notice_id.', '.$source.", '".$created. "') "; + $cnt++; + if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) { + // FIXME: Causes lag in replicated servers + // Notice_inbox::gc($id); + } + if ($cnt >= MAX_BOXCARS) { + $inbox = new Notice_inbox(); + $result = $inbox->query($qry); + if (PEAR::isError($result)) { + common_log_db_error($inbox, $qry); + } + $qry = $qryhdr; + $cnt = 0; + } + } + + if ($cnt > 0) { + $inbox = new Notice_inbox(); + $result = $inbox->query($qry); + if (PEAR::isError($result)) { + common_log_db_error($inbox, $qry); + } + } + + return; + } } -- cgit v1.2.3-54-g00ecf From 7dd0f2fa9c8e9332c5ff481c93b53169c2510ff7 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 17:20:04 -0500 Subject: pkeyGet() method for Forward and return value from saveNew() --- classes/Forward.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'classes') diff --git a/classes/Forward.php b/classes/Forward.php index 6d4848438..52ec53871 100644 --- a/classes/Forward.php +++ b/classes/Forward.php @@ -43,6 +43,11 @@ class Forward extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + function &pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Forward', $kv); + } + static function saveNew($profile_id, $notice_id) { $forward = new Forward(); @@ -62,6 +67,8 @@ class Forward extends Memcached_DataObject $forward->query('COMMIT'); $forward->blowCache($ni); + + return $forward; } function addToInboxes() -- cgit v1.2.3-54-g00ecf From c49ece9fb40c68e6d6a47343208dc3da5726cf44 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 17:20:17 -0500 Subject: method to check if a profile has forwarded a notice --- classes/Profile.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'classes') diff --git a/classes/Profile.php b/classes/Profile.php index 4b2e09006..4c14f62a0 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -716,4 +716,12 @@ class Profile extends Memcached_DataObject } return $result; } + + function hasForwarded($notice_id) + { + $forward = Forward::pkeyGet(array('profile_id' => $this->id, + 'notice_id' => $notice_id)); + + return (!empty($forward)); + } } -- cgit v1.2.3-54-g00ecf From 9dff9e6cea6c46734de85081856064561a34a501 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 17:42:07 -0500 Subject: make sure not to forward blocked users --- classes/Forward.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Forward.php b/classes/Forward.php index 52ec53871..e9b83a58b 100644 --- a/classes/Forward.php +++ b/classes/Forward.php @@ -77,23 +77,33 @@ class Forward extends Memcached_DataObject $user = new User(); - $user->query('SELECT id FROM user JOIN subscription ON user.id = subscription.subscriber '. + $user->query('SELECT user.* FROM user JOIN subscription ON user.id = subscription.subscriber '. 'WHERE subscription.subscribed = '.$this->profile_id); $ni = array(); + $notice = Notice::staticGet('id', $this->notice_id); + + $author = Profile::staticGet('id', $notice->profile_id); + while ($user->fetch()) { $inbox = Notice_inbox::pkeyGet(array('user_id' => $user->id, 'notice_id' => $this->notice_id)); if (empty($inbox)) { - $ni[$user->id] = NOTICE_INBOX_SOURCE_FORWARD; + if (!$user->hasBlocked($author)) { + $ni[$user->id] = NOTICE_INBOX_SOURCE_FORWARD; + } } else { $inbox->free(); } } $user->free(); + $author->free(); + + unset($user); + unset($author); Notice_inbox::bulkInsert($this->notice_id, $this->created, $ni); -- cgit v1.2.3-54-g00ecf From 789378838b9a3ad6bff906d70c8316527aed9e98 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 9 Dec 2009 13:26:59 +1300 Subject: that pesky table named user - now quoted --- classes/Forward.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Forward.php b/classes/Forward.php index e9b83a58b..09b2d6a4e 100644 --- a/classes/Forward.php +++ b/classes/Forward.php @@ -77,7 +77,8 @@ class Forward extends Memcached_DataObject $user = new User(); - $user->query('SELECT user.* FROM user JOIN subscription ON user.id = subscription.subscriber '. + $usertable = common_database_tablename('user'); + $user->query("SELECT $usertable.* FROM $usertable INNER JOIN subscription ON $usertable.id = subscription.subscriber ". 'WHERE subscription.subscribed = '.$this->profile_id); $ni = array(); -- cgit v1.2.3-54-g00ecf From 45408142e9d7431dd4a664262d4806c655cc5c68 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 21:02:54 -0500 Subject: reorder notices when not using memcached --- classes/Notice.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index bcd7947bd..c36c5a9c6 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -788,10 +788,24 @@ class Notice extends Memcached_DataObject return $notice; } $notice->whereAdd('id in (' . implode(', ', $ids) . ')'); - $notice->orderBy('id DESC'); $notice->find(); - return $notice; + + $temp = array(); + + while ($notice->fetch()) { + $temp[$notice->id] = clone($notice); + } + + $wrapped = array(); + + foreach ($ids as $id) { + if (array_key_exists($id, $temp)) { + $wrapped[] = $temp[$id]; + } + } + + return new ArrayWrapper($wrapped); } } -- cgit v1.2.3-54-g00ecf From b07e1143cc8f07bf0613835debe08be227970c73 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 10 Dec 2009 13:08:24 -0500 Subject: Override login_token's sequenceKey() so that it behaves correctly --- classes/Login_token.php | 13 +++++++++++++ lib/command.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Login_token.php b/classes/Login_token.php index c172b30ab..746cd7f22 100644 --- a/classes/Login_token.php +++ b/classes/Login_token.php @@ -39,4 +39,17 @@ class Login_token extends Memcached_DataObject /* 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); + } } diff --git a/lib/command.php b/lib/command.php index e2a665511..af8855a7f 100644 --- a/lib/command.php +++ b/lib/command.php @@ -584,7 +584,7 @@ class LoginCommand extends Command function execute($channel) { $disabled = common_config('logincommand','disabled'); - if(isset($disabled)) { + if(isset($disabled) && $disabled) { $channel->error($this->user, _('Login command is disabled')); return; } -- cgit v1.2.3-54-g00ecf From 144faade3b3d366fc6f3a254ce6b1c36bd4f4cdb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 10 Dec 2009 13:31:16 -0500 Subject: move forwarding stuff to Repeat plugin --- actions/forward.php | 122 ------------------------------------------- classes/Forward.php | 127 --------------------------------------------- plugins/Repeat/Forward.php | 127 +++++++++++++++++++++++++++++++++++++++++++++ plugins/Repeat/forward.php | 122 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+), 249 deletions(-) delete mode 100644 actions/forward.php delete mode 100644 classes/Forward.php create mode 100644 plugins/Repeat/Forward.php create mode 100644 plugins/Repeat/forward.php (limited to 'classes') diff --git a/actions/forward.php b/actions/forward.php deleted file mode 100644 index 194833fe0..000000000 --- a/actions/forward.php +++ /dev/null @@ -1,122 +0,0 @@ - - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - * - * StatusNet - the distributed open-source microblogging tool - * Copyright (C) 2008, 2009, 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 . - */ - -if (!defined('STATUSNET')) { - exit(1); -} - -/** - * Forward action - * - * @category Action - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - */ - -class ForwardAction extends Action -{ - var $user = null; - var $notice = null; - - function prepare($args) - { - parent::prepare($args); - - $this->user = common_current_user(); - - if (empty($this->user)) { - $this->clientError(_("Only logged-in users can forward notices.")); - return false; - } - - $id = $this->trimmed('notice'); - - if (empty($id)) { - $this->clientError(_("No notice specified.")); - return false; - } - - $this->notice = Notice::staticGet('id', $id); - - if (empty($this->notice)) { - $this->clientError(_("No notice specified.")); - return false; - } - - if ($this->user->id == $this->notice->profile_id) { - $this->clientError(_("You can't forward your own notice.")); - return false; - } - - $token = $this->trimmed('token-'.$id); - - if (empty($token) || $token != common_session_token()) { - $this->clientError(_("There was a problem with your session token. Try again, please.")); - return false; - } - - $profile = $this->user->getProfile(); - - if ($profile->hasForwarded($id)) { - $this->clientError(_("You already forwarded that notice.")); - return false; - } - - return true; - } - - /** - * Class handler. - * - * @param array $args query arguments - * - * @return void - */ - - function handle($args) - { - $forward = Forward::saveNew($this->user->id, $this->notice->id); - - if ($this->boolean('ajax')) { - $this->startHTML('text/xml;charset=utf-8'); - $this->elementStart('head'); - $this->element('title', null, _('Forwarded')); - $this->elementEnd('head'); - $this->elementStart('body'); - $this->element('p', array('id' => 'forward_response'), _('Forwarded!')); - $this->elementEnd('body'); - $this->elementEnd('html'); - } else { - // FIXME! - } - } -} diff --git a/classes/Forward.php b/classes/Forward.php deleted file mode 100644 index 09b2d6a4e..000000000 --- a/classes/Forward.php +++ /dev/null @@ -1,127 +0,0 @@ -. - */ - -if (!defined('STATUSNET')) { - exit(1); -} - -/** - * Table Definition for location_namespace - */ - -require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; - -class Forward extends Memcached_DataObject -{ - ###START_AUTOCODE - /* the code below is auto generated do not remove the above tag */ - - public $__table = 'forward'; // table name - public $profile_id; // int(4) primary_key not_null - public $notice_id; // int(4) primary_key not_null - public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00 - - /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Forward',$k,$v); } - - /* the code above is auto generated do not remove the tag below */ - ###END_AUTOCODE - - function &pkeyGet($kv) - { - return Memcached_DataObject::pkeyGet('Forward', $kv); - } - - static function saveNew($profile_id, $notice_id) - { - $forward = new Forward(); - - $forward->profile_id = $profile_id; - $forward->notice_id = $notice_id; - $forward->created = common_sql_now(); - - $forward->query('BEGIN'); - - if (!$forward->insert()) { - throw new ServerException(_("Couldn't insert forward.")); - } - - $ni = $forward->addToInboxes(); - - $forward->query('COMMIT'); - - $forward->blowCache($ni); - - return $forward; - } - - function addToInboxes() - { - $inbox = new Notice_inbox(); - - $user = new User(); - - $usertable = common_database_tablename('user'); - $user->query("SELECT $usertable.* FROM $usertable INNER JOIN subscription ON $usertable.id = subscription.subscriber ". - 'WHERE subscription.subscribed = '.$this->profile_id); - - $ni = array(); - - $notice = Notice::staticGet('id', $this->notice_id); - - $author = Profile::staticGet('id', $notice->profile_id); - - while ($user->fetch()) { - $inbox = Notice_inbox::pkeyGet(array('user_id' => $user->id, - 'notice_id' => $this->notice_id)); - - if (empty($inbox)) { - if (!$user->hasBlocked($author)) { - $ni[$user->id] = NOTICE_INBOX_SOURCE_FORWARD; - } - } else { - $inbox->free(); - } - } - - $user->free(); - $author->free(); - - unset($user); - unset($author); - - Notice_inbox::bulkInsert($this->notice_id, $this->created, $ni); - - return $ni; - } - - function blowCache($ni) - { - $cache = common_memcache(); - - if (!empty($cache)) { - foreach ($ni as $id => $source) { - $cache->delete(common_cache_key('notice_inbox:by_user:'.$id)); - $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$id)); - $cache->delete(common_cache_key('notice_inbox:by_user:'.$id.';last')); - $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$id.';last')); - } - } - } -} diff --git a/plugins/Repeat/Forward.php b/plugins/Repeat/Forward.php new file mode 100644 index 000000000..09b2d6a4e --- /dev/null +++ b/plugins/Repeat/Forward.php @@ -0,0 +1,127 @@ +. + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Table Definition for location_namespace + */ + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +class Forward extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'forward'; // table name + public $profile_id; // int(4) primary_key not_null + public $notice_id; // int(4) primary_key not_null + public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00 + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Forward',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + function &pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Forward', $kv); + } + + static function saveNew($profile_id, $notice_id) + { + $forward = new Forward(); + + $forward->profile_id = $profile_id; + $forward->notice_id = $notice_id; + $forward->created = common_sql_now(); + + $forward->query('BEGIN'); + + if (!$forward->insert()) { + throw new ServerException(_("Couldn't insert forward.")); + } + + $ni = $forward->addToInboxes(); + + $forward->query('COMMIT'); + + $forward->blowCache($ni); + + return $forward; + } + + function addToInboxes() + { + $inbox = new Notice_inbox(); + + $user = new User(); + + $usertable = common_database_tablename('user'); + $user->query("SELECT $usertable.* FROM $usertable INNER JOIN subscription ON $usertable.id = subscription.subscriber ". + 'WHERE subscription.subscribed = '.$this->profile_id); + + $ni = array(); + + $notice = Notice::staticGet('id', $this->notice_id); + + $author = Profile::staticGet('id', $notice->profile_id); + + while ($user->fetch()) { + $inbox = Notice_inbox::pkeyGet(array('user_id' => $user->id, + 'notice_id' => $this->notice_id)); + + if (empty($inbox)) { + if (!$user->hasBlocked($author)) { + $ni[$user->id] = NOTICE_INBOX_SOURCE_FORWARD; + } + } else { + $inbox->free(); + } + } + + $user->free(); + $author->free(); + + unset($user); + unset($author); + + Notice_inbox::bulkInsert($this->notice_id, $this->created, $ni); + + return $ni; + } + + function blowCache($ni) + { + $cache = common_memcache(); + + if (!empty($cache)) { + foreach ($ni as $id => $source) { + $cache->delete(common_cache_key('notice_inbox:by_user:'.$id)); + $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$id)); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$id.';last')); + $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$id.';last')); + } + } + } +} diff --git a/plugins/Repeat/forward.php b/plugins/Repeat/forward.php new file mode 100644 index 000000000..194833fe0 --- /dev/null +++ b/plugins/Repeat/forward.php @@ -0,0 +1,122 @@ + + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2008, 2009, 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 . + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Forward action + * + * @category Action + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ + +class ForwardAction extends Action +{ + var $user = null; + var $notice = null; + + function prepare($args) + { + parent::prepare($args); + + $this->user = common_current_user(); + + if (empty($this->user)) { + $this->clientError(_("Only logged-in users can forward notices.")); + return false; + } + + $id = $this->trimmed('notice'); + + if (empty($id)) { + $this->clientError(_("No notice specified.")); + return false; + } + + $this->notice = Notice::staticGet('id', $id); + + if (empty($this->notice)) { + $this->clientError(_("No notice specified.")); + return false; + } + + if ($this->user->id == $this->notice->profile_id) { + $this->clientError(_("You can't forward your own notice.")); + return false; + } + + $token = $this->trimmed('token-'.$id); + + if (empty($token) || $token != common_session_token()) { + $this->clientError(_("There was a problem with your session token. Try again, please.")); + return false; + } + + $profile = $this->user->getProfile(); + + if ($profile->hasForwarded($id)) { + $this->clientError(_("You already forwarded that notice.")); + return false; + } + + return true; + } + + /** + * Class handler. + * + * @param array $args query arguments + * + * @return void + */ + + function handle($args) + { + $forward = Forward::saveNew($this->user->id, $this->notice->id); + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, _('Forwarded')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'forward_response'), _('Forwarded!')); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + // FIXME! + } + } +} -- cgit v1.2.3-54-g00ecf From dd098fee776fbb794080b8f95beab16b2f31556b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 10 Dec 2009 14:34:47 -0500 Subject: remove forward table from db scripts --- classes/statusnet.ini | 10 ---------- db/08to09.sql | 12 ------------ db/statusnet.sql | 11 ----------- 3 files changed, 33 deletions(-) (limited to 'classes') diff --git a/classes/statusnet.ini b/classes/statusnet.ini index a5126795b..835faeb0b 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -1,4 +1,3 @@ - [avatar] profile_id = 129 original = 17 @@ -196,15 +195,6 @@ id = K service = K uri = U -[forward] -profile_id = 129 -notice_id = 129 -created = 142 - -[forward__keys] -profile_id = K -notice_id = K - [group_alias] alias = 130 group_id = 129 diff --git a/db/08to09.sql b/db/08to09.sql index a945416ea..64640f4ce 100644 --- a/db/08to09.sql +++ b/db/08to09.sql @@ -82,15 +82,3 @@ create table login_token ( constraint primary key (user_id) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; - -create table forward ( - - profile_id integer not null comment 'profile who forwarded the notice' references profile (id), - notice_id integer not null comment 'notice they forwarded' references notice (id), - - created datetime not null comment 'date this record was created', - - constraint primary key (profile_id, notice_id) - -) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; - diff --git a/db/statusnet.sql b/db/statusnet.sql index b500b81f2..18abcdfdb 100644 --- a/db/statusnet.sql +++ b/db/statusnet.sql @@ -585,14 +585,3 @@ create table login_token ( constraint primary key (user_id) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; -create table forward ( - - profile_id integer not null comment 'profile who forwarded the notice' references profile (id), - notice_id integer not null comment 'notice they forwarded' references notice (id), - - created datetime not null comment 'date this record was created', - - constraint primary key (profile_id, notice_id) - -) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; - -- cgit v1.2.3-54-g00ecf From 433106dfc512605f93a1354034c23452fbb3956b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 10 Dec 2009 14:40:48 -0500 Subject: remove 'has forwarded' method from Profile --- classes/Profile.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'classes') diff --git a/classes/Profile.php b/classes/Profile.php index 4c14f62a0..4b2e09006 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -716,12 +716,4 @@ class Profile extends Memcached_DataObject } return $result; } - - function hasForwarded($notice_id) - { - $forward = Forward::pkeyGet(array('profile_id' => $this->id, - 'notice_id' => $notice_id)); - - return (!empty($forward)); - } } -- cgit v1.2.3-54-g00ecf