node.install

  1. drupal
    1. 6 modules/node/node.install
    2. 7 modules/node/node.install
    3. 8 core/modules/node/node.install

Install, update and uninstall functions for the node module.

Functions & methods

NameDescription
node_installImplements hook_install().
node_schemaImplements hook_schema().
node_uninstallImplements hook_uninstall().
node_update_8000Set 'node' as front page path if it implicitly was before.
node_update_8001Rename node type language variable names.
node_update_8002Rename node.language field to node.langcode.
_update_7000_node_get_typesFetches node types directly from the database.

File

core/modules/node/node.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the node module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function node_schema() {
  10. $schema['node'] = array(
  11. 'description' => 'The base table for nodes.',
  12. 'fields' => array(
  13. 'nid' => array(
  14. 'description' => 'The primary identifier for a node.',
  15. 'type' => 'serial',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. ),
  19. // Defaults to NULL in order to avoid a brief period of potential
  20. // deadlocks on the index.
  21. 'vid' => array(
  22. 'description' => 'The current {node_revision}.vid version identifier.',
  23. 'type' => 'int',
  24. 'unsigned' => TRUE,
  25. 'not null' => FALSE,
  26. 'default' => NULL,
  27. ),
  28. 'type' => array(
  29. 'description' => 'The {node_type}.type of this node.',
  30. 'type' => 'varchar',
  31. 'length' => 32,
  32. 'not null' => TRUE,
  33. 'default' => '',
  34. ),
  35. 'langcode' => array(
  36. 'description' => 'The {language}.langcode of this node.',
  37. 'type' => 'varchar',
  38. 'length' => 12,
  39. 'not null' => TRUE,
  40. 'default' => '',
  41. ),
  42. 'title' => array(
  43. 'description' => 'The title of this node, always treated as non-markup plain text.',
  44. 'type' => 'varchar',
  45. 'length' => 255,
  46. 'not null' => TRUE,
  47. 'default' => '',
  48. ),
  49. 'uid' => array(
  50. 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
  51. 'type' => 'int',
  52. 'not null' => TRUE,
  53. 'default' => 0,
  54. ),
  55. 'status' => array(
  56. 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
  57. 'type' => 'int',
  58. 'not null' => TRUE,
  59. 'default' => 1,
  60. ),
  61. 'created' => array(
  62. 'description' => 'The Unix timestamp when the node was created.',
  63. 'type' => 'int',
  64. 'not null' => TRUE,
  65. 'default' => 0,
  66. ),
  67. 'changed' => array(
  68. 'description' => 'The Unix timestamp when the node was most recently saved.',
  69. 'type' => 'int',
  70. 'not null' => TRUE,
  71. 'default' => 0,
  72. ),
  73. 'comment' => array(
  74. 'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).',
  75. 'type' => 'int',
  76. 'not null' => TRUE,
  77. 'default' => 0,
  78. ),
  79. 'promote' => array(
  80. 'description' => 'Boolean indicating whether the node should be displayed on the front page.',
  81. 'type' => 'int',
  82. 'not null' => TRUE,
  83. 'default' => 0,
  84. ),
  85. 'sticky' => array(
  86. 'description' => 'Boolean indicating whether the node should be displayed at the top of lists in which it appears.',
  87. 'type' => 'int',
  88. 'not null' => TRUE,
  89. 'default' => 0,
  90. ),
  91. 'tnid' => array(
  92. 'description' => 'The translation set id for this node, which equals the node id of the source post in each set.',
  93. 'type' => 'int',
  94. 'unsigned' => TRUE,
  95. 'not null' => TRUE,
  96. 'default' => 0,
  97. ),
  98. 'translate' => array(
  99. 'description' => 'A boolean indicating whether this translation page needs to be updated.',
  100. 'type' => 'int',
  101. 'not null' => TRUE,
  102. 'default' => 0,
  103. ),
  104. ),
  105. 'indexes' => array(
  106. 'node_changed' => array('changed'),
  107. 'node_created' => array('created'),
  108. 'node_frontpage' => array('promote', 'status', 'sticky', 'created'),
  109. 'node_status_type' => array('status', 'type', 'nid'),
  110. 'node_title_type' => array('title', array('type', 4)),
  111. 'node_type' => array(array('type', 4)),
  112. 'uid' => array('uid'),
  113. 'tnid' => array('tnid'),
  114. 'translate' => array('translate'),
  115. ),
  116. 'unique keys' => array(
  117. 'vid' => array('vid'),
  118. ),
  119. 'foreign keys' => array(
  120. 'node_revision' => array(
  121. 'table' => 'node_revision',
  122. 'columns' => array('vid' => 'vid'),
  123. ),
  124. 'node_author' => array(
  125. 'table' => 'users',
  126. 'columns' => array('uid' => 'uid'),
  127. ),
  128. ),
  129. 'primary key' => array('nid'),
  130. );
  131. $schema['node_access'] = array(
  132. 'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
  133. 'fields' => array(
  134. 'nid' => array(
  135. 'description' => 'The {node}.nid this record affects.',
  136. 'type' => 'int',
  137. 'unsigned' => TRUE,
  138. 'not null' => TRUE,
  139. 'default' => 0,
  140. ),
  141. 'gid' => array(
  142. 'description' => "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.",
  143. 'type' => 'int',
  144. 'unsigned' => TRUE,
  145. 'not null' => TRUE,
  146. 'default' => 0,
  147. ),
  148. 'realm' => array(
  149. 'description' => 'The realm in which the user must possess the grant ID. Each node access node can define one or more realms.',
  150. 'type' => 'varchar',
  151. 'length' => 255,
  152. 'not null' => TRUE,
  153. 'default' => '',
  154. ),
  155. 'grant_view' => array(
  156. 'description' => 'Boolean indicating whether a user with the realm/grant pair can view this node.',
  157. 'type' => 'int',
  158. 'unsigned' => TRUE,
  159. 'not null' => TRUE,
  160. 'default' => 0,
  161. 'size' => 'tiny',
  162. ),
  163. 'grant_update' => array(
  164. 'description' => 'Boolean indicating whether a user with the realm/grant pair can edit this node.',
  165. 'type' => 'int',
  166. 'unsigned' => TRUE,
  167. 'not null' => TRUE,
  168. 'default' => 0,
  169. 'size' => 'tiny',
  170. ),
  171. 'grant_delete' => array(
  172. 'description' => 'Boolean indicating whether a user with the realm/grant pair can delete this node.',
  173. 'type' => 'int',
  174. 'unsigned' => TRUE,
  175. 'not null' => TRUE,
  176. 'default' => 0,
  177. 'size' => 'tiny',
  178. ),
  179. ),
  180. 'primary key' => array('nid', 'gid', 'realm'),
  181. 'foreign keys' => array(
  182. 'affected_node' => array(
  183. 'table' => 'node',
  184. 'columns' => array('nid' => 'nid'),
  185. ),
  186. ),
  187. );
  188. $schema['node_revision'] = array(
  189. 'description' => 'Stores information about each saved version of a {node}.',
  190. 'fields' => array(
  191. 'nid' => array(
  192. 'description' => 'The {node} this version belongs to.',
  193. 'type' => 'int',
  194. 'unsigned' => TRUE,
  195. 'not null' => TRUE,
  196. 'default' => 0,
  197. ),
  198. 'vid' => array(
  199. 'description' => 'The primary identifier for this version.',
  200. 'type' => 'serial',
  201. 'unsigned' => TRUE,
  202. 'not null' => TRUE,
  203. ),
  204. 'uid' => array(
  205. 'description' => 'The {users}.uid that created this version.',
  206. 'type' => 'int',
  207. 'not null' => TRUE,
  208. 'default' => 0,
  209. ),
  210. 'title' => array(
  211. 'description' => 'The title of this version.',
  212. 'type' => 'varchar',
  213. 'length' => 255,
  214. 'not null' => TRUE,
  215. 'default' => '',
  216. ),
  217. 'log' => array(
  218. 'description' => 'The log entry explaining the changes in this version.',
  219. 'type' => 'text',
  220. 'not null' => TRUE,
  221. 'size' => 'big',
  222. ),
  223. 'timestamp' => array(
  224. 'description' => 'A Unix timestamp indicating when this version was created.',
  225. 'type' => 'int',
  226. 'not null' => TRUE,
  227. 'default' => 0,
  228. ),
  229. 'status' => array(
  230. 'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).',
  231. 'type' => 'int',
  232. 'not null' => TRUE,
  233. 'default' => 1,
  234. ),
  235. 'comment' => array(
  236. 'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).',
  237. 'type' => 'int',
  238. 'not null' => TRUE,
  239. 'default' => 0,
  240. ),
  241. 'promote' => array(
  242. 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.',
  243. 'type' => 'int',
  244. 'not null' => TRUE,
  245. 'default' => 0,
  246. ),
  247. 'sticky' => array(
  248. 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.',
  249. 'type' => 'int',
  250. 'not null' => TRUE,
  251. 'default' => 0,
  252. ),
  253. ),
  254. 'indexes' => array(
  255. 'nid' => array('nid'),
  256. 'uid' => array('uid'),
  257. ),
  258. 'primary key' => array('vid'),
  259. 'foreign keys' => array(
  260. 'versioned_node' => array(
  261. 'table' => 'node',
  262. 'columns' => array('nid' => 'nid'),
  263. ),
  264. 'version_author' => array(
  265. 'table' => 'users',
  266. 'columns' => array('uid' => 'uid'),
  267. ),
  268. ),
  269. );
  270. $schema['node_type'] = array(
  271. 'description' => 'Stores information about all defined {node} types.',
  272. 'fields' => array(
  273. 'type' => array(
  274. 'description' => 'The machine-readable name of this type.',
  275. 'type' => 'varchar',
  276. 'length' => 32,
  277. 'not null' => TRUE,
  278. ),
  279. 'name' => array(
  280. 'description' => 'The human-readable name of this type.',
  281. 'type' => 'varchar',
  282. 'length' => 255,
  283. 'not null' => TRUE,
  284. 'default' => '',
  285. 'translatable' => TRUE,
  286. ),
  287. 'base' => array(
  288. 'description' => 'The base string used to construct callbacks corresponding to this node type.',
  289. 'type' => 'varchar',
  290. 'length' => 255,
  291. 'not null' => TRUE,
  292. ),
  293. 'module' => array(
  294. 'description' => 'The module defining this node type.',
  295. 'type' => 'varchar',
  296. 'length' => 255,
  297. 'not null' => TRUE,
  298. ),
  299. 'description' => array(
  300. 'description' => 'A brief description of this type.',
  301. 'type' => 'text',
  302. 'not null' => TRUE,
  303. 'size' => 'medium',
  304. 'translatable' => TRUE,
  305. ),
  306. 'help' => array(
  307. 'description' => 'Help information shown to the user when creating a {node} of this type.',
  308. 'type' => 'text',
  309. 'not null' => TRUE,
  310. 'size' => 'medium',
  311. 'translatable' => TRUE,
  312. ),
  313. 'has_title' => array(
  314. 'description' => 'Boolean indicating whether this type uses the {node}.title field.',
  315. 'type' => 'int',
  316. 'unsigned' => TRUE,
  317. 'not null' => TRUE,
  318. 'size' => 'tiny',
  319. ),
  320. 'title_label' => array(
  321. 'description' => 'The label displayed for the title field on the edit form.',
  322. 'type' => 'varchar',
  323. 'length' => 255,
  324. 'not null' => TRUE,
  325. 'default' => '',
  326. 'translatable' => TRUE,
  327. ),
  328. 'custom' => array(
  329. 'description' => 'A boolean indicating whether this type is defined by a module (FALSE) or by a user via Add content type (TRUE).',
  330. 'type' => 'int',
  331. 'not null' => TRUE,
  332. 'default' => 0,
  333. 'size' => 'tiny',
  334. ),
  335. 'modified' => array(
  336. 'description' => 'A boolean indicating whether this type has been modified by an administrator; currently not used in any way.',
  337. 'type' => 'int',
  338. 'not null' => TRUE,
  339. 'default' => 0,
  340. 'size' => 'tiny',
  341. ),
  342. 'locked' => array(
  343. 'description' => 'A boolean indicating whether the administrator can change the machine name of this type.',
  344. 'type' => 'int',
  345. 'not null' => TRUE,
  346. 'default' => 0,
  347. 'size' => 'tiny',
  348. ),
  349. 'disabled' => array(
  350. 'description' => 'A boolean indicating whether the node type is disabled.',
  351. 'type' => 'int',
  352. 'not null' => TRUE,
  353. 'default' => 0,
  354. 'size' => 'tiny'
  355. ),
  356. 'orig_type' => array(
  357. 'description' => 'The original machine-readable name of this node type. This may be different from the current type name if the locked field is 0.',
  358. 'type' => 'varchar',
  359. 'length' => 255,
  360. 'not null' => TRUE,
  361. 'default' => '',
  362. ),
  363. ),
  364. 'primary key' => array('type'),
  365. );
  366. $schema['block_node_type'] = array(
  367. 'description' => 'Sets up display criteria for blocks based on content types',
  368. 'fields' => array(
  369. 'module' => array(
  370. 'type' => 'varchar',
  371. 'length' => 64,
  372. 'not null' => TRUE,
  373. 'description' => "The block's origin module, from {block}.module.",
  374. ),
  375. 'delta' => array(
  376. 'type' => 'varchar',
  377. 'length' => 32,
  378. 'not null' => TRUE,
  379. 'description' => "The block's unique delta within module, from {block}.delta.",
  380. ),
  381. 'type' => array(
  382. 'type' => 'varchar',
  383. 'length' => 32,
  384. 'not null' => TRUE,
  385. 'description' => "The machine-readable name of this type from {node_type}.type.",
  386. ),
  387. ),
  388. 'primary key' => array('module', 'delta', 'type'),
  389. 'indexes' => array(
  390. 'type' => array('type'),
  391. ),
  392. );
  393. $schema['history'] = array(
  394. 'description' => 'A record of which {users} have read which {node}s.',
  395. 'fields' => array(
  396. 'uid' => array(
  397. 'description' => 'The {users}.uid that read the {node} nid.',
  398. 'type' => 'int',
  399. 'not null' => TRUE,
  400. 'default' => 0,
  401. ),
  402. 'nid' => array(
  403. 'description' => 'The {node}.nid that was read.',
  404. 'type' => 'int',
  405. 'not null' => TRUE,
  406. 'default' => 0,
  407. ),
  408. 'timestamp' => array(
  409. 'description' => 'The Unix timestamp at which the read occurred.',
  410. 'type' => 'int',
  411. 'not null' => TRUE,
  412. 'default' => 0,
  413. ),
  414. ),
  415. 'primary key' => array('uid', 'nid'),
  416. 'indexes' => array(
  417. 'nid' => array('nid'),
  418. ),
  419. );
  420. return $schema;
  421. }
  422. /**
  423. * Implements hook_install().
  424. */
  425. function node_install() {
  426. // Populate the node access table.
  427. db_insert('node_access')
  428. ->fields(array(
  429. 'nid' => 0,
  430. 'gid' => 0,
  431. 'realm' => 'all',
  432. 'grant_view' => 1,
  433. 'grant_update' => 0,
  434. 'grant_delete' => 0,
  435. ))
  436. ->execute();
  437. }
  438. /**
  439. * Implements hook_uninstall().
  440. */
  441. function node_uninstall() {
  442. // Delete node type variables.
  443. $types = db_query('SELECT type FROM {node_type}')->fetchCol();
  444. foreach ($types as $type) {
  445. db_delete('variable')
  446. ->condition(db_or()
  447. ->condition('name', 'node_preview_' . $type)
  448. ->condition('name', 'node_options_' . $type)
  449. ->condition('name', 'node_submitted_' . $type)
  450. ->condition('name', 'node_permissions_' . $type)
  451. ->condition('name', 'node_type_language_' . $type)
  452. )
  453. ->execute();
  454. }
  455. // Delete node search ranking variables.
  456. // @see node_ranking(), _node_rankings()
  457. variable_del('node_rank_relevance');
  458. variable_del('node_rank_sticky');
  459. variable_del('node_rank_promote');
  460. variable_del('node_rank_recent');
  461. // Delete remaining general module variables.
  462. variable_del('node_access_needs_rebuild');
  463. variable_del('node_admin_theme');
  464. variable_del('node_cron_last');
  465. variable_del('node_recent_block_count');
  466. variable_del('default_nodes_main');
  467. }
  468. /**
  469. * Fetches node types directly from the database.
  470. *
  471. * @ingroup update-api-7.x-to-8.x
  472. */
  473. function _update_7000_node_get_types() {
  474. $node_types = db_query('SELECT * FROM {node_type}')->fetchAllAssoc('type', PDO::FETCH_OBJ);
  475. // Create default settings for orphaned nodes.
  476. $all_types = db_query('SELECT DISTINCT type FROM {node}')->fetchCol();
  477. $extra_types = array_diff($all_types, array_keys($node_types));
  478. foreach ($extra_types as $type) {
  479. $type_object = new stdClass();
  480. $type_object->type = $type;
  481. // In Drupal 6, whether you have a body field or not is a flag in the node
  482. // type table. If it's enabled, nodes may or may not have an empty string
  483. // for the bodies. As we can't detect what this setting should be in
  484. // Drupal 7 without access to the Drupal 6 node type settings, we assume
  485. // the default, which is to enable the body field.
  486. $type_object->has_body = 1;
  487. $type_object->body_label = 'Body';
  488. $node_types[$type_object->type] = $type_object;
  489. }
  490. return $node_types;
  491. }
  492. /**
  493. * @addtogroup updates-7.x-to-8.x
  494. * @{
  495. */
  496. /**
  497. * Set 'node' as front page path if it implicitly was before.
  498. *
  499. * Node module became optional. The default front page path was changed to
  500. * 'user'. Since 'node' was the implicit default front page path previously and
  501. * may not have been explicitly configured as such, this update ensures that the
  502. * old implicit default is still the default.
  503. *
  504. * @see http://drupal.org/node/375397
  505. */
  506. function node_update_8000() {
  507. $front_page = variable_get('site_frontpage');
  508. if (!isset($front_page)) {
  509. variable_set('site_frontpage', 'node');
  510. }
  511. }
  512. /**
  513. * Rename node type language variable names.
  514. *
  515. * @see http://drupal.org/node/540294
  516. */
  517. function node_update_8001() {
  518. $types = db_query('SELECT type FROM {node_type}')->fetchCol();
  519. foreach ($types as $type) {
  520. $language = variable_get('language_content_type_' . $type);
  521. if (isset($language)) {
  522. variable_set('node_type_language_' . $type, $language);
  523. }
  524. variable_del('language_content_type_' . $type);
  525. }
  526. }
  527. /**
  528. * Rename node.language field to node.langcode.
  529. */
  530. function node_update_8002() {
  531. $spec = array(
  532. 'description' => 'The {language}.langcode of this node.',
  533. 'type' => 'varchar',
  534. 'length' => 12,
  535. 'not null' => TRUE,
  536. 'default' => '',
  537. );
  538. db_change_field('node', 'language', 'langcode', $spec);
  539. }
  540. /**
  541. * @} End of "addtogroup updates-7.x-to-8.x"
  542. * The next series of updates should start at 9000.
  543. */
Login or register to post comments