Yammer_state.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Data class for remembering Yammer import state
  4. *
  5. * PHP version 5
  6. *
  7. * @category Data
  8. * @package StatusNet
  9. * @author Brion Vibber <brion@status.net>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2010, StatusNet, Inc.
  15. *
  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.
  20. *
  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.
  25. *
  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/>.
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. class Yammer_state extends Managed_DataObject
  33. {
  34. public $__table = 'yammer_state'; // table name
  35. public $id; // int primary_key not_null
  36. public $state; // import state key
  37. public $last_error; // text of last-encountered error, if any
  38. public $oauth_token; // actual oauth token! clear when import is done?
  39. public $oauth_secret; // actual oauth secret! clear when import is done?
  40. public $users_page; // last page of users we've fetched
  41. public $groups_page; // last page of groups we've fetched
  42. public $messages_oldest; // oldest message ID we've fetched
  43. public $messages_newest; // newest message ID we've imported
  44. public $created; // datetime
  45. public $modified; // datetime
  46. /**
  47. * Return schema definition to set this table up in onCheckSchema
  48. */
  49. static function schemaDef()
  50. {
  51. return array(new ColumnDef('id', 'int', null,
  52. false, 'PRI'),
  53. new ColumnDef('state', 'text'),
  54. new ColumnDef('last_error', 'text'),
  55. new ColumnDef('oauth_token', 'text'),
  56. new ColumnDef('oauth_secret', 'text'),
  57. new ColumnDef('users_page', 'int'),
  58. new ColumnDef('groups_page', 'int'),
  59. new ColumnDef('messages_oldest', 'bigint'),
  60. new ColumnDef('messages_newest', 'bigint'),
  61. new ColumnDef('created', 'datetime'),
  62. new ColumnDef('modified', 'datetime'));
  63. }
  64. /**
  65. * return table definition for DB_DataObject
  66. *
  67. * DB_DataObject needs to know something about the table to manipulate
  68. * instances. This method provides all the DB_DataObject needs to know.
  69. *
  70. * @return array array of column definitions
  71. */
  72. function table()
  73. {
  74. return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
  75. 'state' => DB_DATAOBJECT_STR,
  76. 'last_error' => DB_DATAOBJECT_STR,
  77. 'oauth_token' => DB_DATAOBJECT_STR,
  78. 'oauth_secret' => DB_DATAOBJECT_STR,
  79. 'users_page' => DB_DATAOBJECT_INT,
  80. 'groups_page' => DB_DATAOBJECT_INT,
  81. 'messages_oldest' => DB_DATAOBJECT_INT,
  82. 'messages_newest' => DB_DATAOBJECT_INT,
  83. 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
  84. }
  85. /**
  86. * return key definitions for DB_DataObject
  87. *
  88. * DB_DataObject needs to know about keys that the table has, since it
  89. * won't appear in StatusNet's own keys list. In most cases, this will
  90. * simply reference your keyTypes() function.
  91. *
  92. * @return array list of key field names
  93. */
  94. function keys()
  95. {
  96. return array_keys($this->keyTypes());
  97. }
  98. /**
  99. * return key definitions for Memcached_DataObject
  100. *
  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
  104. * lookups.
  105. *
  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.
  109. */
  110. function keyTypes()
  111. {
  112. return array('id' => 'K');
  113. }
  114. /**
  115. * Magic formula for non-autoincrementing integer primary keys
  116. *
  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.
  121. *
  122. * @return array magic three-false array that stops auto-incrementing.
  123. */
  124. function sequenceKey()
  125. {
  126. return array(false, false, false);
  127. }
  128. }