3 * Data class for remembering Yammer import mappings
9 * @author Brion Vibber <brion@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2010, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * Temporary storage for imported Yammer messages between fetching and saving
38 * The Yammer API only allows us to page down from the most recent items; in
39 * order to start saving the oldest notices first, we have to pull them all
40 * down in reverse chronological order, then go back over them from oldest to
41 * newest and actually save them into our notice table.
44 class Yammer_notice_stub extends Memcached_DataObject
46 public $__table = 'yammer_notice_stub'; // table name
47 public $id; // int primary_key not_null
48 public $json_data; // text
49 public $created; // datetime
52 * Get an instance by key
54 * This is a utility method to get a single instance with a given key value.
56 * @param string $k Key to use to lookup
57 * @param mixed $v Value to lookup
59 * @return Yammer_notice_stub object found, or null for no hits
63 function staticGet($k, $v=null)
65 return Memcached_DataObject::staticGet('Yammer_notice_stub', $k, $v);
69 * Return schema definition to set this table up in onCheckSchema
71 static function schemaDef()
73 return array(new ColumnDef('id', 'bigint', null,
75 new ColumnDef('json_data', 'text', null,
77 new ColumnDef('created', 'datetime', null,
82 * return table definition for DB_DataObject
84 * DB_DataObject needs to know something about the table to manipulate
85 * instances. This method provides all the DB_DataObject needs to know.
87 * @return array array of column definitions
92 return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
93 'json_data' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
94 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
98 * return key definitions for DB_DataObject
100 * DB_DataObject needs to know about keys that the table has, since it
101 * won't appear in StatusNet's own keys list. In most cases, this will
102 * simply reference your keyTypes() function.
104 * @return array list of key field names
109 return array_keys($this->keyTypes());
113 * return key definitions for Memcached_DataObject
115 * Our caching system uses the same key definitions, but uses a different
116 * method to get them. This key information is used to store and clear
117 * cached data, so be sure to list any key that will be used for static
120 * @return array associative array of key definitions, field name to type:
121 * 'K' for primary key: for compound keys, add an entry for each component;
122 * 'U' for unique keys: compound keys are not well supported here.
127 return array('id' => 'K');
131 * Magic formula for non-autoincrementing integer primary keys
133 * If a table has a single integer column as its primary key, DB_DataObject
134 * assumes that the column is auto-incrementing and makes a sequence table
135 * to do this incrementation. Since we don't need this for our class, we
136 * overload this method and return the magic formula that DB_DataObject needs.
138 * @return array magic three-false array that stops auto-incrementing.
141 function sequenceKey()
143 return array(false, false, false);
147 * Decode the stored data structure.
151 public function getData()
153 return json_decode($this->json_data, true);
157 * Save the native Yammer API representation of a message for the pending
158 * import. Since they come in in reverse chronological order, we need to
159 * record them all as stubs and then go through from the beginning and
160 * save them as native notices, or we'll lose ordering and threading
163 * @param integer $orig_id ID of the notice on Yammer
164 * @param array $data the message record fetched out of Yammer API returnd data
166 * @return Yammer_notice_stub new object for this value
169 static function record($orig_id, $data)
171 common_debug("Recording Yammer message stub {$orig_id} for pending import...");
173 $stub = new Yammer_notice_stub();
175 $stub->id = $orig_id;
176 $stub->json_data = json_encode($data);
177 $stub->created = common_sql_now();