3 * StatusNet, the distributed open-source microblogging tool
5 * Data class for Conversations
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @author Mikael Nordfeldth <mmn@hethane.se>
26 * @copyright 2010 StatusNet Inc.
27 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://status.net/
32 if (!defined('GNUSOCIAL')) { exit(1); }
34 class Conversation extends Managed_DataObject
36 public $__table = 'conversation'; // table name
37 public $id; // int(4) primary_key not_null
38 public $uri; // varchar(255) unique_key
39 public $created; // datetime not_null
40 public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
42 public static function schemaDef()
46 'id' => array('type' => 'int', 'not null' => true, 'description' => 'should be set from root notice id (since 2014-03-01 commit)'),
47 'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'URI of the conversation'),
48 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
49 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
51 'primary key' => array('id'),
52 'unique keys' => array(
53 'conversation_uri_key' => array('uri'),
59 * Factory method for creating a new conversation
61 * @return Conversation the new conversation DO
63 static function create(Notice $notice)
65 if (empty($notice->id)) {
66 throw new ServerException(_('Tried to create conversation for not yet inserted notice'));
68 $conv = new Conversation();
69 $conv->created = common_sql_now();
70 $conv->id = $notice->id;
71 $conv->uri = common_local_url('conversation', array('id' => $notice->id), null, null, false);
72 $result = $conv->insert();
74 if ($result === false) {
75 common_log_db_error($conv, 'INSERT', __FILE__);
76 throw new ServerException(_('Failed to create conversation for notice'));
82 static function noticeCount($id)
84 $keypart = sprintf('conversation:notice_count:%d', $id);
86 $cnt = self::cacheGet($keypart);
92 $notice = new Notice();
93 $notice->conversation = $id;
94 $cnt = $notice->count();
96 self::cacheSet($keypart, $cnt);