/** * Factory method for creating a new conversation. * * Use this for locally initiated conversations. Remote notices should * preferrably supply their own conversation URIs in the OStatus feed. * * @return Conversation the new conversation DO */ static function create(Notice $notice, $uri = null) { if (empty($notice->id)) { throw new ServerException(_('Tried to create conversation for not yet inserted notice')); } $conv = new Conversation(); $conv->created = common_sql_now(); $conv->id = $notice->id; $conv->uri = $uri ?: sprintf('%s%s=%d:%s=%s:%s=%x', TagURI::mint(), 'noticeId', $notice->id, 'objectType', 'thread', 'crc32', crc32($notice->content)); $result = $conv->insert(); if ($result === false) { common_log_db_error($conv, 'INSERT', __FILE__); throw new ServerException(_('Failed to create conversation for notice')); } return $conv; }
/** * Factory method for creating a new conversation * * @return Conversation the new conversation DO */ static function create() { $conv = new Conversation(); $conv->created = common_sql_now(); $id = $conv->insert(); if (empty($id)) { common_log_db_error($conv, 'INSERT', __FILE__); return null; } $orig = clone $conv; $orig->uri = common_local_url('conversation', array('id' => $id), null, null, false); $result = $orig->update($conv); if (empty($result)) { common_log_db_error($conv, 'UPDATE', __FILE__); return null; } return $conv; }
/** * Factory method for creating a new conversation. * * Use this for locally initiated conversations. Remote notices should * preferrably supply their own conversation URIs in the OStatus feed. * * @return Conversation the new conversation DO */ static function create($uri = null, $created = null) { // Be aware that the Notice does not have an id yet since it's not inserted! $conv = new Conversation(); $conv->created = $created ?: common_sql_now(); $conv->uri = $uri ?: sprintf('%s%s=%s:%s=%s', TagURI::mint(), 'objectType', 'thread', 'nonce', common_random_hexstr(8)); // This insert throws exceptions on failure $conv->insert(); return $conv; }