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 * Common base class for the Yammer import mappings for users, groups, and notices.
37 * Child classes must override these static methods, since we need to run
38 * on PHP 5.2.x which has no late static binding:
39 * - staticGet (as our other classes)
40 * - schemaDef (call self::doSchemaDef)
41 * - record (call self::doRecord)
44 class Yammer_common extends Memcached_DataObject
46 public $__table = 'yammer_XXXX'; // table name
47 public $__field = 'XXXX_id'; // field name to save into
48 public $id; // int primary_key not_null
49 public $user_id; // int(4)
50 public $created; // datetime
53 * @fixme add a 'references' thing for the foreign key when we support that
55 protected static function doSchemaDef($field)
57 return array(new ColumnDef('id', 'bigint', null,
59 new ColumnDef($field, 'integer', null,
61 new ColumnDef('created', 'datetime', null,
66 * return table definition for DB_DataObject
68 * DB_DataObject needs to know something about the table to manipulate
69 * instances. This method provides all the DB_DataObject needs to know.
71 * @return array array of column definitions
76 return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
77 $this->__field => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
78 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
82 * return key definitions for DB_DataObject
84 * DB_DataObject needs to know about keys that the table has, since it
85 * won't appear in StatusNet's own keys list. In most cases, this will
86 * simply reference your keyTypes() function.
88 * @return array list of key field names
93 return array_keys($this->keyTypes());
97 * return key definitions for Memcached_DataObject
99 * Our caching system uses the same key definitions, but uses a different
100 * method to get them. This key information is used to store and clear
101 * cached data, so be sure to list any key that will be used for static
104 * @return array associative array of key definitions, field name to type:
105 * 'K' for primary key: for compound keys, add an entry for each component;
106 * 'U' for unique keys: compound keys are not well supported here.
111 return array('id' => 'K', $this->__field => 'U');
115 * Magic formula for non-autoincrementing integer primary keys
117 * If a table has a single integer column as its primary key, DB_DataObject
118 * assumes that the column is auto-incrementing and makes a sequence table
119 * to do this incrementation. Since we don't need this for our class, we
120 * overload this method and return the magic formula that DB_DataObject needs.
122 * @return array magic three-false array that stops auto-incrementing.
125 function sequenceKey()
127 return array(false, false, false);
131 * Save a mapping between a remote Yammer and local imported user.
133 * @param integer $user_id ID of the status in StatusNet
134 * @param integer $orig_id ID of the notice in Yammer
136 * @return Yammer_common new object for this value
139 protected static function doRecord($class, $field, $orig_id, $local_id)
141 $map = parent::staticGet($class, 'id', $orig_id);
147 $map = parent::staticGet($class, $field, $local_id);
153 common_debug("Mapping Yammer $field {$orig_id} to local $field {$local_id}");
158 $map->$field = $local_id;
159 $map->created = common_sql_now();