heartbeat.install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the node module.
  5. */
  6. use Drupal\Core\Field\BaseFieldDefinition;
  7. use Drupal\user\RoleInterface;
  8. /**
  9. * Implements hook_requirements().
  10. */
  11. function heartbeat_requirements($phase) {
  12. $requirements = array();
  13. if ($phase === 'runtime') {
  14. // Only show rebuild button if there are either 0, or 2 or more, rows
  15. // in the {node_access} table, or if there are modules that
  16. // implement hook_node_grants().
  17. $grant_count = \Drupal::entityManager()->getAccessControlHandler('node')->countGrants();
  18. if ($grant_count != 1 || count(\Drupal::moduleHandler()->getImplementations('node_grants')) > 0) {
  19. $value = \Drupal::translation()->formatPlural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count));
  20. }
  21. else {
  22. $value = t('Disabled');
  23. }
  24. $requirements['node_access'] = array(
  25. 'title' => t('Node Access Permissions'),
  26. 'value' => $value,
  27. 'description' => t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Rebuilding will remove all privileges to content and replace them with permissions based on the current modules and settings. Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed, content will automatically use the new permissions. <a href=":rebuild">Rebuild permissions</a>', array(
  28. ':rebuild' => \Drupal::url('node.configure_rebuild_confirm'),
  29. )),
  30. );
  31. }
  32. return $requirements;
  33. }
  34. /**
  35. * Implements hook_schema().
  36. * ** //TODO Have not yet set export schema for CTOOLS as CTOOLS is not yet a part of Drupal 8
  37. */
  38. function heartbeat_schema() {
  39. $schema['heartbeat_messages'] = array(
  40. 'description' => 'Table that contains predefined messages that can be used in heartbeat views.',
  41. 'fields' => array(
  42. 'hid' => array(
  43. 'description' => 'Primary Key: Unique heartbeat_messages event ID.',
  44. 'type' => 'serial',
  45. 'not null' => TRUE,
  46. ),
  47. 'message_id' => array(
  48. 'description' => 'The message id which is unique to identify activity.',
  49. 'type' => 'varchar',
  50. 'length' => 255,
  51. 'not null' => FALSE,
  52. 'default' => '',
  53. ),
  54. 'description' => array(
  55. 'description' => 'Description and help text',
  56. 'type' => 'text',
  57. 'not null' => FALSE,
  58. 'size' => 'big'
  59. ),
  60. 'message' => array(
  61. 'type' => 'text',
  62. 'not null' => TRUE,
  63. 'size' => 'big',
  64. 'description' => 'Text of log message to be passed into the ) function.',
  65. //'alias' => 'message_orig', // Internal heartbeat field/property
  66. ),
  67. 'message_concat' => array(
  68. 'type' => 'text',
  69. 'not null' => TRUE,
  70. 'size' => 'big',
  71. 'description' => 'Text of translatable log message for in concatenated form.',
  72. //'alias' => 'message_concat_orig', // Internal heartbeat field/property
  73. ),
  74. 'perms' => array(
  75. 'type' => 'int',
  76. 'unsigned' => TRUE,
  77. 'not null' => FALSE,
  78. 'default' => 4,
  79. 'description' => 'Permissions for this message.',
  80. ),
  81. 'group_type' => array(
  82. 'type' => 'varchar',
  83. 'length' => 20,
  84. 'not null' => TRUE,
  85. 'default' => 'single',
  86. 'description' => 'The group type of the template',
  87. ),
  88. 'concat_args' => array(
  89. 'description' => 'Arguments for concatenation message.',
  90. 'type' => 'blob',
  91. 'serialize' => TRUE,
  92. 'not null' => FALSE,
  93. ),
  94. 'variables' => array(
  95. 'description' => 'Variables to parse into the message (used in message).',
  96. 'type' => 'blob',
  97. 'serialize' => TRUE,
  98. 'not null' => FALSE,
  99. ),
  100. 'attachments' => array(
  101. 'description' => 'Attachments on messages.',
  102. 'type' => 'blob',
  103. 'serialize' => TRUE,
  104. 'not null' => FALSE,
  105. ),
  106. ),
  107. 'primary key' => array('hid'),
  108. 'indexes' => array(
  109. 'message_id' => array('message_id'),
  110. ),
  111. );
  112. $schema['heartbeat_activity'] = array(
  113. 'description' => 'Table that contains logs of all user triggerable actions.',
  114. 'fields' => array(
  115. 'uaid' => array(
  116. 'type' => 'serial',
  117. 'not null' => TRUE,
  118. 'description' => 'Primary Key: Unique heartbeat_activity event ID.',
  119. ),
  120. 'uid' => array(
  121. 'type' => 'int',
  122. 'unsigned' => TRUE,
  123. 'not null' => TRUE,
  124. 'default' => 0,
  125. 'description' => 'The {users}.uid of the user who triggered the event (requester).',
  126. ),
  127. 'uid_target' => array(
  128. 'type' => 'int',
  129. 'unsigned' => TRUE,
  130. 'not null' => FALSE,
  131. 'default' => 0,
  132. 'description' => 'The target User ID',
  133. ),
  134. 'nid' => array(
  135. 'description' => 'The Node ID.',
  136. 'type' => 'int',
  137. 'unsigned' => TRUE,
  138. 'not null' => FALSE,
  139. ),
  140. 'nid_target' => array(
  141. 'description' => 'The target Node ID (E.g. Group id, node reference, ...).',
  142. 'type' => 'int',
  143. 'unsigned' => TRUE,
  144. 'not null' => FALSE,
  145. ),
  146. 'cid' => array(
  147. 'description' => 'The target comment ID (optional).',
  148. 'type' => 'int',
  149. 'unsigned' => TRUE,
  150. 'not null' => FALSE,
  151. ),
  152. 'access' => array(
  153. 'type' => 'int',
  154. 'not null' => TRUE,
  155. 'size' => 'tiny',
  156. 'description' => 'Access for this message to others.',
  157. 'default' => 0,
  158. ),
  159. 'message_id' => array(
  160. 'type' => 'varchar',
  161. 'length' => 255,
  162. 'not null' => FALSE,
  163. 'default' => '',
  164. 'description' => 'The message id which links to the heartbeat message.',
  165. ),
  166. 'timestamp' => array(
  167. 'description' => 'The activity\'s unix timestamp when action occurred',
  168. 'type' => 'int',
  169. 'unsigned' => TRUE,
  170. 'not null' => TRUE,
  171. 'default' => 0,
  172. ),
  173. 'language' => array(
  174. 'type' => 'varchar',
  175. 'length' => 12,
  176. 'not null' => FALSE,
  177. 'default' => 'en',
  178. 'description' => 'language for a log".',
  179. ),
  180. 'variables' => array(
  181. 'type' => 'text',
  182. 'not null' => FALSE,
  183. 'size' => 'big',
  184. 'description' => 'Serialized array of variables that match the message string and that is passed into the ) function.',
  185. ),
  186. 'in_group' => array(
  187. 'type' => 'int',
  188. 'not null' => TRUE,
  189. 'size' => 'big',
  190. 'description' => 'Indicates whether the activity is related to a group',
  191. 'default' => 0,
  192. ),
  193. ),
  194. 'primary key' => array('uaid'),
  195. 'indexes' => array(
  196. 'timestamp' => array('timestamp'),
  197. 'uid' => array('uid'),
  198. 'message_id' => array('message_id'),
  199. 'uid_target' => array('uid_target'),
  200. 'nid' => array('nid'),
  201. 'nid_target' => array('nid_target'),
  202. 'cid' => array('cid'),
  203. 'language' => array('language'),
  204. ),
  205. );
  206. $schema['heartbeat_activity']['fields']['in_group'] = array(
  207. 'type' => 'int',
  208. 'not null' => TRUE,
  209. 'size' => 'big',
  210. 'description' => 'Indicates whether the activity is related to a group.',
  211. 'default' => 0,
  212. );
  213. $schema['heartbeat_activity']['indexes']['in_group'] = array('in_group');
  214. $schema['heartbeat_user_templates'] = heartbeat_install_table_user_templates();
  215. $schema['heartbeat_streams'] = array(
  216. 'description' => 'Table that contains heartbeat streams.',
  217. // CTools export definitions.
  218. // 'export' => array(
  219. // 'key' => 'class',
  220. // 'key name' => 'name',
  221. // 'primary key' => 'class',
  222. // 'bulk export' => TRUE,
  223. // 'identifier' => 'heartbeatstream',
  224. // 'object' => 'HeartbeatStreamConfig',
  225. // 'default hook' => 'heartbeat_stream_info',
  226. // 'load callback' => '_heartbeat_stream_config_load',
  227. // 'load all callback' => '_heartbeat_stream_config_load_all',
  228. // 'can disable' => TRUE,
  229. // 'api' => array(
  230. // 'owner' => 'heartbeat',
  231. // 'api' => 'heartbeat',
  232. // 'minimum_version' => 1,
  233. // 'current_version' => 1,
  234. // ),
  235. // ),
  236. 'fields' => array(
  237. 'class' => array(
  238. 'type' => 'varchar',
  239. 'length' => 100,
  240. 'not null' => TRUE,
  241. 'default' => '',
  242. 'description' => 'Class of the stream to load.',
  243. ),
  244. 'real_class' => array(
  245. 'type' => 'varchar',
  246. 'length' => 100,
  247. 'not null' => TRUE,
  248. 'default' => '',
  249. 'description' => 'Real Class of the stream to load.',
  250. ),
  251. 'name' => array(
  252. 'type' => 'varchar',
  253. 'length' => 100,
  254. 'not null' => TRUE,
  255. 'default' => '',
  256. 'description' => 'Name of the stream. Cloned streams will have the same object but same cla
  257. ss.',
  258. ),
  259. 'module' => array(
  260. 'type' => 'varchar',
  261. 'length' => 100,
  262. 'not null' => TRUE,
  263. 'default' => '',
  264. 'description' => 'The module that defines the class and where the query builder is located.
  265. ',
  266. ),
  267. 'title' => array(
  268. 'type' => 'varchar',
  269. 'length' => 100,
  270. 'not null' => TRUE,
  271. 'default' => '',
  272. 'description' => 'Human readable name of the stream.',
  273. ),
  274. 'path' => array(
  275. 'type' => 'varchar',
  276. 'length' => 250,
  277. 'not null' => TRUE,
  278. 'default' => '',
  279. 'description' => 'Path to the stream object.',
  280. ),
  281. 'settings' => array(
  282. 'description' => 'Serialized settings for this stream.',
  283. 'type' => 'blob',
  284. 'serialize' => TRUE,
  285. 'not null' => FALSE,
  286. ),
  287. 'variables' => array(
  288. 'description' => 'Variables to parse into the message (used in message).',
  289. 'type' => 'blob',
  290. 'serialize' => TRUE,
  291. 'not null' => FALSE,
  292. ),
  293. 'real_class' => array(
  294. 'type' => 'varchar',
  295. 'length' => 100,
  296. 'not null' => TRUE,
  297. 'default' => '',
  298. 'description' => 'Real Class of the stream to load',
  299. )
  300. ),
  301. 'primary key' => array('class'),
  302. 'indexes' => array(
  303. 'name' => array('name'),
  304. ),
  305. );
  306. //TODO determine if these foreign keys are to be added
  307. // db_add_unique_key('heartbeat_activity', 'uaid', array('uaid'));
  308. // db_add_unique_key('heartbeat_activity', 'uaid_uid', array('uaid', 'uid'));
  309. // db_add_unique_key('heartbeat_activity', 'uaid_nid', array('uaid', 'nid'));
  310. // db_add_unique_key('heartbeat_activity', 'uaid_uid_nid', array('uaid', 'uid', 'nid'))
  311. return $schema;
  312. }
  313. function heartbeat_install_table_user_templates() {
  314. return array(
  315. 'description' => 'Table that connects translations of the same activity.',
  316. 'fields' => array(
  317. 'uid' => array(
  318. 'type' => 'int',
  319. 'not null' => TRUE,
  320. 'description' => 'The referenced user ID.',
  321. ),
  322. 'message_id' => array(
  323. 'type' => 'varchar',
  324. 'length' => 250,
  325. 'not null' => FALSE,
  326. 'default' => '',
  327. 'description' => 'The template message ID.',
  328. ),
  329. 'status' => array(
  330. 'type' => 'int',
  331. 'not null' => TRUE,
  332. 'description' => 'The status of the template.',
  333. ),
  334. ),
  335. );
  336. }