3 * Data class for storing notice-to-Facebook-item mappings
9 * @author Zach Copley <zach@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')) {
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
37 * Data class for mapping notices to Facebook stream items
39 * Note that notice_id is unique only within a single database; if you
40 * want to share this data for some reason, get the notice's URI and use
41 * that instead, since it's universally unique.
45 * @author Zach Copley <zach@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47 * @link http://status.net/
51 class Notice_to_item extends Managed_DataObject
53 public $__table = 'notice_to_item'; // table name
54 public $notice_id; // int(4) primary_key not_null
55 public $item_id; // varchar(191) not null not 255 because utf8mb4 takes more space
56 public $created; // datetime
59 * return table definition for DB_DataObject
61 * DB_DataObject needs to know something about the table to manipulate
62 * instances. This method provides all the DB_DataObject needs to know.
64 * @return array array of column definitions
69 'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
70 'item_id' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
71 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
75 static function schemaDef()
78 new ColumnDef('notice_id', 'integer', null, false, 'PRI'),
79 new ColumnDef('item_id', 'varchar', 191, false, 'UNI'),
80 new ColumnDef('created', 'datetime', null, false)
85 * return key definitions for DB_DataObject
87 * DB_DataObject needs to know about keys that the table has, since it
88 * won't appear in StatusNet's own keys list. In most cases, this will
89 * simply reference your keyTypes() function.
91 * @return array list of key field names
95 return array_keys($this->keyTypes());
99 * return key definitions for Memcached_DataObject
101 * Our caching system uses the same key definitions, but uses a different
102 * method to get them. This key information is used to store and clear
103 * cached data, so be sure to list any key that will be used for static
106 * @return array associative array of key definitions, field name to type:
107 * 'K' for primary key: for compound keys, add an entry for each component;
108 * 'U' for unique keys: compound keys are not well supported here.
112 return array('notice_id' => 'K', 'item_id' => 'U');
116 * Magic formula for non-autoincrementing integer primary keys
118 * If a table has a single integer column as its primary key, DB_DataObject
119 * assumes that the column is auto-incrementing and makes a sequence table
120 * to do this incrementation. Since we don't need this for our class, we
121 * overload this method and return the magic formula that DB_DataObject needs.
123 * @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 notice and a Facebook item
133 * @param integer $notice_id ID of the notice in StatusNet
134 * @param integer $item_id ID of the stream item on Facebook
136 * @return Notice_to_item new object for this value
138 static function saveNew($notice_id, $item_id)
140 $n2i = Notice_to_item::getKV('notice_id', $notice_id);
146 $n2i = Notice_to_item::getKV('item_id', $item_id);
153 "Mapping notice {$notice_id} to Facebook item {$item_id}",
157 $n2i = new Notice_to_item();
159 $n2i->notice_id = $notice_id;
160 $n2i->item_id = $item_id;
161 $n2i->created = common_sql_now();