heartbeat.install 10 KB

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