. * * @category Data * @package StatusNet * @author Zach Copley * @author Mikael Nordfeldth * @copyright 2010 StatusNet Inc. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ if (!defined('GNUSOCIAL')) { exit(1); } class Conversation extends Managed_DataObject { public $__table = 'conversation'; // table name public $id; // int(4) primary_key not_null public $uri; // varchar(255) unique_key public $created; // datetime not_null public $modified; // timestamp not_null default_CURRENT_TIMESTAMP public static function schemaDef() { return array( 'fields' => array( 'id' => array('type' => 'int', 'not null' => true, 'description' => 'should be set from root notice id (since 2014-03-01 commit)'), 'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'URI of the conversation'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), ), 'primary key' => array('id'), 'unique keys' => array( 'conversation_uri_key' => array('uri'), ), ); } /** * Factory method for creating a new conversation * * @return Conversation the new conversation DO */ static function create(Notice $notice) { if (empty($notice->id)) { common_debug('Tried to create conversation for not yet inserted notice'); return null; } $conv = new Conversation(); $conv->created = common_sql_now(); $conv->id = $notice->id; $conv->uri = common_local_url('conversation', array('id' => $notice->id), null, null, false); $result = $conv->insert(); if ($result === false) { common_log_db_error($conv, 'INSERT', __FILE__); throw new ServerException(_('Failed to create conversation for notice')); } return $conv; } static function noticeCount($id) { $keypart = sprintf('conversation:notice_count:%d', $id); $cnt = self::cacheGet($keypart); if ($cnt !== false) { return $cnt; } $notice = new Notice(); $notice->conversation = $id; $cnt = $notice->count(); self::cacheSet($keypart, $cnt); return $cnt; } }