heartbeat.install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. // 'concatargs' => 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_friendship'] = array(
  113. 'fields' => array(
  114. 'id' => array(
  115. 'type' => 'serial',
  116. 'not null' => TRUE,
  117. ),
  118. 'uid' => array(
  119. 'type' => 'int',
  120. 'unsigned' => TRUE,
  121. 'not null' => TRUE,
  122. 'default' => 0,
  123. ),
  124. 'uid_target' => array(
  125. 'type' => 'int',
  126. 'unsigned' => TRUE,
  127. 'not null' => FALSE,
  128. 'default' => 0,
  129. ),
  130. 'status' => array(
  131. 'type' => 'int',
  132. 'not null' => TRUE,
  133. 'size' => 'tiny',
  134. 'default' => -1,
  135. ),
  136. 'created' => array(
  137. 'type' => 'int',
  138. 'not null' => TRUE,
  139. ),
  140. ),
  141. 'primary key' => array('id'),
  142. 'unique keys' => array(
  143. 'uid_relation' => array('uid', 'uid_target')
  144. )
  145. );
  146. $schema['heartbeat_term_usage'] = array(
  147. 'fields' => array(
  148. 'id' => array(
  149. 'type' => 'serial',
  150. 'not null' => TRUE,
  151. ),
  152. 'tid' => array(
  153. 'type' => 'int',
  154. 'unsigned' => TRUE,
  155. 'not null' => TRUE,
  156. 'default' => 0,
  157. ),
  158. 'timestamp' => array(
  159. 'type' => 'int',
  160. 'unsigned' => TRUE,
  161. 'not null' => TRUE,
  162. ),
  163. ),
  164. 'primary key' => array('id'),
  165. 'unique keys' => array(
  166. 'tid_use' => array('tid', 'timestamp')
  167. )
  168. );
  169. // 'indexes' => array(
  170. // 'created' => array('created'),
  171. // ),
  172. // );
  173. // $schema['heartbeat_activity']['fields']['in_group'] = array(
  174. // 'type' => 'int',
  175. // 'not null' => TRUE,
  176. // 'size' => 'big',
  177. // 'description' => 'Indicates whether the activity is related to a group.',
  178. // 'default' => 0,
  179. // );
  180. // $schema['heartbeat_activity']['indexes']['in_group'] = array('in_group');
  181. // $schema['heartbeat_user_templates'] = heartbeat_install_table_user_templates();
  182. // $schema['heartbeat_stream'] = array(
  183. // 'description' => 'Table that contains heartbeat streams.',
  184. // // CTools export definitions.
  185. //// 'export' => array(
  186. //// 'key' => 'class',
  187. //// 'key name' => 'name',
  188. //// 'primary key' => 'class',
  189. //// 'bulk export' => TRUE,
  190. //// 'identifier' => 'heartbeatstream',
  191. //// 'object' => 'HeartbeatStreamConfig',
  192. //// 'default hook' => 'heartbeat_stream_info',
  193. //// 'load callback' => '_heartbeat_stream_config_load',
  194. //// 'load all callback' => '_heartbeat_stream_config_load_all',
  195. //// 'can disable' => TRUE,
  196. //// 'api' => array(
  197. //// 'owner' => 'heartbeat',
  198. //// 'api' => 'heartbeat',
  199. //// 'minimum_version' => 1,
  200. //// 'current_version' => 1,
  201. //// ),
  202. //// ),
  203. // 'fields' => array(
  204. // //TODO find out if we need id or vid fields in this table
  205. //// 'id' => array(
  206. //// 'type' => 'serial',
  207. //// 'not null' => TRUE,
  208. //// 'description' => 'Primary Key: Unique heartbeat_activity event ID.',
  209. //// ),
  210. //// 'vid' => array(
  211. //// 'type' => 'int',
  212. //// 'not null' => TRUE,
  213. //// 'description' => 'The Revision ID',
  214. //// ),
  215. // 'class' => array(
  216. // 'type' => 'varchar',
  217. // 'length' => 100,
  218. // 'not null' => TRUE,
  219. // 'default' => '',
  220. // 'description' => 'Class of the stream to load.',
  221. // ),
  222. // 'real_class' => array(
  223. // 'type' => 'varchar',
  224. // 'length' => 100,
  225. // 'not null' => TRUE,
  226. // 'default' => '',
  227. // 'description' => 'Real Class of the stream to load.',
  228. // ),
  229. // 'name' => array(
  230. // 'type' => 'varchar',
  231. // 'length' => 100,
  232. // 'not null' => TRUE,
  233. // 'default' => '',
  234. // 'description' => 'Name of the stream. Cloned streams will have the same object but same cla
  235. //ss.',
  236. // ),
  237. // 'module' => array(
  238. // 'type' => 'varchar',
  239. // 'length' => 100,
  240. // 'not null' => TRUE,
  241. // 'default' => '',
  242. // 'description' => 'The module that defines the class and where the query builder is located.',
  243. // ),
  244. // 'title' => array(
  245. // 'type' => 'varchar',
  246. // 'length' => 100,
  247. // 'not null' => TRUE,
  248. // 'default' => '',
  249. // 'description' => 'Human readable name of the stream.',
  250. // ),
  251. // 'path' => array(
  252. // 'type' => 'varchar',
  253. // 'length' => 250,
  254. // 'not null' => TRUE,
  255. // 'default' => '',
  256. // 'description' => 'Path to the stream object.',
  257. // ),
  258. // 'settings' => array(
  259. // 'description' => 'Serialized settings for this stream.',
  260. // 'type' => 'blob',
  261. // 'serialize' => TRUE,
  262. // 'not null' => FALSE,
  263. // ),
  264. // 'variables' => array(
  265. // 'description' => 'Variables to parse into the message (used in message).',
  266. // 'type' => 'blob',
  267. // 'serialize' => TRUE,
  268. // 'not null' => FALSE,
  269. // ),
  270. // ),
  271. // 'primary key' => array('class'),
  272. // 'indexes' => array(
  273. // 'name' => array('name'),
  274. // ),
  275. // );
  276. //TODO determine if these foreign keys are to be added
  277. // db_add_unique_key('heartbeat_act/ivity', 'uaid', array('uaid'));
  278. // db_add_unique_key('heartbeat_activity', 'uaid_uid', array('uaid', 'uid'));
  279. // db_add_unique_key('heartbeat_activity', 'uaid_nid', array('uaid', 'nid'));
  280. // db_add_unique_key('heartbeat_activity', 'uaid_uid_nid', array('uaid', 'uid', 'nid'))
  281. return $schema;
  282. }
  283. function heartbeat_install_table_user_templates() {
  284. return array(
  285. 'description' => 'Table that connects translations of the same activity.',
  286. 'fields' => array(
  287. 'uid' => array(
  288. 'type' => 'int',
  289. 'not null' => TRUE,
  290. 'description' => 'The referenced user ID.',
  291. ),
  292. 'message_id' => array(
  293. 'type' => 'varchar',
  294. 'length' => 250,
  295. 'not null' => FALSE,
  296. 'default' => '',
  297. 'description' => 'The template message ID.',
  298. ),
  299. 'status' => array(
  300. 'type' => 'int',
  301. 'not null' => TRUE,
  302. 'description' => 'The status of the template.',
  303. ),
  304. ),
  305. );
  306. }
  307. function heartbeat_uninstall() {
  308. $entities = \Drupal::service("entity.query")->get("heartbeat")->execute();
  309. foreach($entities as $entity) {
  310. $heartbeat = \Drupal::service("entity_type.manager")->getStorage("heartbeat")->load($entity);
  311. $heartbeat->delete();
  312. }
  313. $entities = \Drupal::service("entity.query")->get("heartbeat_stream")->execute();
  314. foreach($entities as $entity) {
  315. $heartbeat = \Drupal::service("entity_type.manager")->getStorage("heartbeat_stream")->load($entity);
  316. $heartbeat->delete();
  317. }
  318. }