feeds.install 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <?php
  2. /**
  3. * @file
  4. * Schema definitions install/update/uninstall hooks.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function feeds_schema() {
  10. $schema = array();
  11. $schema['feeds_importer'] = array(
  12. 'description' => 'Configuration of feeds objects.',
  13. 'export' => array(
  14. 'key' => 'id',
  15. 'identifier' => 'feeds_importer',
  16. 'default hook' => 'feeds_importer_default', // Function hook name.
  17. 'api' => array(
  18. 'owner' => 'feeds',
  19. 'api' => 'feeds_importer_default', // Base name for api include files.
  20. 'minimum_version' => 1,
  21. 'current_version' => 1,
  22. ),
  23. ),
  24. 'fields' => array(
  25. 'id' => array(
  26. 'type' => 'varchar',
  27. 'length' => 128,
  28. 'not null' => TRUE,
  29. 'default' => '',
  30. 'description' => 'Id of the fields object.',
  31. ),
  32. 'config' => array(
  33. 'type' => 'blob',
  34. 'size' => 'big',
  35. 'not null' => FALSE,
  36. 'description' => 'Configuration of the feeds object.',
  37. 'serialize' => TRUE,
  38. ),
  39. ),
  40. 'primary key' => array('id'),
  41. );
  42. $schema['feeds_source'] = array(
  43. 'description' => 'Source definitions for feeds.',
  44. 'fields' => array(
  45. 'id' => array(
  46. 'type' => 'varchar',
  47. 'length' => 128,
  48. 'not null' => TRUE,
  49. 'default' => '',
  50. 'description' => 'Id of the feed configuration.',
  51. ),
  52. 'feed_nid' => array(
  53. 'type' => 'int',
  54. 'not null' => TRUE,
  55. 'default' => 0,
  56. 'unsigned' => TRUE,
  57. 'description' => 'Node nid if this particular source is attached to a feed node.',
  58. ),
  59. 'config' => array(
  60. 'type' => 'blob',
  61. 'size' => 'big',
  62. 'not null' => FALSE,
  63. 'description' => 'Configuration of the source.',
  64. 'serialize' => TRUE,
  65. ),
  66. 'source' => array(
  67. 'type' => 'text',
  68. 'not null' => TRUE,
  69. 'description' => 'Main source resource identifier. E. g. a path or a URL.',
  70. ),
  71. 'state' => array(
  72. 'type' => 'blob',
  73. 'size' => 'big',
  74. 'not null' => FALSE,
  75. 'description' => 'State of import or clearing batches.',
  76. 'serialize' => TRUE,
  77. ),
  78. 'fetcher_result' => array(
  79. 'type' => 'blob',
  80. 'size' => 'big',
  81. 'not null' => FALSE,
  82. 'description' => 'Cache for fetcher result.',
  83. 'serialize' => TRUE,
  84. ),
  85. 'imported' => array(
  86. 'type' => 'int',
  87. 'not null' => TRUE,
  88. 'default' => 0,
  89. 'unsigned' => TRUE,
  90. 'description' => 'Timestamp when this source was imported last.',
  91. ),
  92. ),
  93. 'primary key' => array('id', 'feed_nid'),
  94. 'indexes' => array(
  95. 'id' => array('id'),
  96. 'feed_nid' => array('feed_nid'),
  97. 'id_source' => array('id', array('source', 128)),
  98. ),
  99. );
  100. $schema['feeds_item'] = array(
  101. 'description' => 'Tracks items such as nodes, terms, users.',
  102. 'fields' => array(
  103. 'entity_type' => array(
  104. 'type' => 'varchar',
  105. 'length' => 32,
  106. 'not null' => TRUE,
  107. 'default' => '',
  108. 'description' => 'The entity type.',
  109. ),
  110. 'entity_id' => array(
  111. 'type' => 'int',
  112. 'unsigned' => TRUE,
  113. 'not null' => TRUE,
  114. 'description' => 'The imported entity\'s serial id.',
  115. ),
  116. 'id' => array(
  117. 'type' => 'varchar',
  118. 'length' => 128,
  119. 'not null' => TRUE,
  120. 'default' => '',
  121. 'description' => 'The id of the importer that created this item.',
  122. ),
  123. 'feed_nid' => array(
  124. 'type' => 'int',
  125. 'unsigned' => TRUE,
  126. 'not null' => TRUE,
  127. 'description' => 'Node id of the source, if available.',
  128. ),
  129. 'imported' => array(
  130. 'type' => 'int',
  131. 'not null' => TRUE,
  132. 'default' => 0,
  133. 'description' => 'Import date of the feed item, as a Unix timestamp.',
  134. ),
  135. 'url' => array(
  136. 'type' => 'text',
  137. 'not null' => TRUE,
  138. 'description' => 'Link to the feed item.',
  139. ),
  140. 'guid' => array(
  141. 'type' => 'text',
  142. 'not null' => TRUE,
  143. 'description' => 'Unique identifier for the feed item.'
  144. ),
  145. 'hash' => array(
  146. 'type' => 'varchar',
  147. 'length' => 32, // The length of an MD5 hash.
  148. 'not null' => TRUE,
  149. 'default' => '',
  150. 'description' => 'The hash of the source item.',
  151. ),
  152. ),
  153. 'primary key' => array('entity_type', 'entity_id'),
  154. 'indexes' => array(
  155. 'id' => array('id'),
  156. 'feed_nid' => array('feed_nid'),
  157. 'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
  158. 'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
  159. 'global_lookup_url' => array('entity_type', array('url', 128)),
  160. 'global_lookup_guid' => array('entity_type', array('guid', 128)),
  161. 'imported' => array('imported'),
  162. ),
  163. );
  164. $schema['feeds_push_subscriptions'] = array(
  165. 'description' => 'PubSubHubbub subscriptions.',
  166. 'fields' => array(
  167. 'domain' => array(
  168. 'type' => 'varchar',
  169. 'length' => 128,
  170. 'not null' => TRUE,
  171. 'default' => '',
  172. 'description' => 'Domain of the subscriber. Corresponds to an importer id.',
  173. ),
  174. 'subscriber_id' => array(
  175. 'type' => 'int',
  176. 'not null' => TRUE,
  177. 'default' => 0,
  178. 'unsigned' => TRUE,
  179. 'description' => 'ID of the subscriber. Corresponds to a feed nid.',
  180. ),
  181. 'timestamp' => array(
  182. 'type' => 'int',
  183. 'unsigned' => FALSE,
  184. 'default' => 0,
  185. 'not null' => TRUE,
  186. 'description' => 'Created timestamp.',
  187. ),
  188. 'hub' => array(
  189. 'type' => 'text',
  190. 'not null' => TRUE,
  191. 'description' => 'The URL of the hub endpoint of this subscription.',
  192. ),
  193. 'topic' => array(
  194. 'type' => 'text',
  195. 'not null' => TRUE,
  196. 'description' => 'The topic URL (feed URL) of this subscription.',
  197. ),
  198. 'secret' => array(
  199. 'type' => 'varchar',
  200. 'length' => 128,
  201. 'not null' => TRUE,
  202. 'default' => '',
  203. 'description' => 'Shared secret for message authentication.',
  204. ),
  205. 'status' => array(
  206. 'type' => 'varchar',
  207. 'length' => 64,
  208. 'not null' => TRUE,
  209. 'default' => '',
  210. 'description' => 'Status of subscription.',
  211. ),
  212. 'post_fields' => array(
  213. 'type' => 'text',
  214. 'not null' => FALSE,
  215. 'description' => 'Fields posted.',
  216. 'serialize' => TRUE,
  217. ),
  218. ),
  219. 'primary key' => array('domain', 'subscriber_id'),
  220. 'indexes' => array(
  221. 'timestamp' => array('timestamp'),
  222. ),
  223. );
  224. $schema['feeds_log'] = array(
  225. 'description' => 'Table that contains logs of feeds events.',
  226. 'fields' => array(
  227. 'flid' => array(
  228. 'type' => 'serial',
  229. 'not null' => TRUE,
  230. 'description' => 'Primary Key: Unique feeds event ID.',
  231. ),
  232. 'id' => array(
  233. 'type' => 'varchar',
  234. 'length' => 128,
  235. 'not null' => TRUE,
  236. 'default' => '',
  237. 'description' => 'The id of the importer that logged the event.',
  238. ),
  239. 'feed_nid' => array(
  240. 'type' => 'int',
  241. 'unsigned' => TRUE,
  242. 'not null' => TRUE,
  243. 'description' => 'Node id of the source, if available.',
  244. ),
  245. 'log_time' => array(
  246. 'type' => 'int',
  247. 'not null' => TRUE,
  248. 'default' => 0,
  249. 'description' => 'Unix timestamp of when event occurred.',
  250. ),
  251. 'request_time' => array(
  252. 'type' => 'int',
  253. 'not null' => TRUE,
  254. 'default' => 0,
  255. 'description' => 'Unix timestamp of the request when the event occurred.',
  256. ),
  257. 'type' => array(
  258. 'type' => 'varchar',
  259. 'length' => 64,
  260. 'not null' => TRUE,
  261. 'default' => '',
  262. 'description' => 'Type of log message, for example "feeds_import"."',
  263. ),
  264. 'message' => array(
  265. 'type' => 'text',
  266. 'not null' => TRUE,
  267. 'size' => 'big',
  268. 'description' => 'Text of log message to be passed into the t() function.',
  269. ),
  270. 'variables' => array(
  271. 'type' => 'blob',
  272. 'not null' => TRUE,
  273. 'size' => 'big',
  274. 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
  275. ),
  276. 'severity' => array(
  277. 'type' => 'int',
  278. 'unsigned' => TRUE,
  279. 'not null' => TRUE,
  280. 'default' => 0,
  281. 'size' => 'tiny',
  282. 'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
  283. ),
  284. ),
  285. 'primary key' => array('flid'),
  286. 'indexes' => array(
  287. 'id' => array('id'),
  288. 'id_feed_nid' => array('id', 'feed_nid'),
  289. 'request_time' => array('request_time'),
  290. 'log_time' => array('log_time'),
  291. 'type' => array('type'),
  292. ),
  293. );
  294. return $schema;
  295. }
  296. /**
  297. * Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
  298. * result.
  299. */
  300. function feeds_update_7100() {
  301. $spec = array(
  302. 'type' => 'text',
  303. 'size' => 'big',
  304. 'not null' => FALSE,
  305. 'description' => 'State of import or clearing batches.',
  306. 'serialize' => TRUE,
  307. );
  308. db_change_field('feeds_source', 'batch', 'state', $spec);
  309. $spec = array(
  310. 'type' => 'text',
  311. 'size' => 'big',
  312. 'not null' => FALSE,
  313. 'description' => 'Cache for fetcher result.',
  314. 'serialize' => TRUE,
  315. );
  316. db_add_field('feeds_source', 'fetcher_result', $spec);
  317. }
  318. /**
  319. * Add imported timestamp to feeds_source table.
  320. */
  321. function feeds_update_7201() {
  322. $spec = array(
  323. 'type' => 'int',
  324. 'not null' => TRUE,
  325. 'default' => 0,
  326. 'unsigned' => TRUE,
  327. 'description' => 'Timestamp when this source was imported last.',
  328. );
  329. db_add_field('feeds_source', 'imported', $spec);
  330. }
  331. /**
  332. * Create a single feeds_item table tracking all imports.
  333. */
  334. function feeds_update_7202() {
  335. $spec = array(
  336. 'description' => 'Tracks items such as nodes, terms, users.',
  337. 'fields' => array(
  338. 'entity_type' => array(
  339. 'type' => 'varchar',
  340. 'length' => 32,
  341. 'not null' => TRUE,
  342. 'default' => '',
  343. 'description' => 'The entity type.',
  344. ),
  345. 'entity_id' => array(
  346. 'type' => 'int',
  347. 'unsigned' => TRUE,
  348. 'not null' => TRUE,
  349. 'description' => 'The imported entity\'s serial id.',
  350. ),
  351. 'id' => array(
  352. 'type' => 'varchar',
  353. 'length' => 128,
  354. 'not null' => TRUE,
  355. 'default' => '',
  356. 'description' => 'The id of the importer that created this item.',
  357. ),
  358. 'feed_nid' => array(
  359. 'type' => 'int',
  360. 'unsigned' => TRUE,
  361. 'not null' => TRUE,
  362. 'description' => 'Node id of the source, if available.',
  363. ),
  364. 'imported' => array(
  365. 'type' => 'int',
  366. 'not null' => TRUE,
  367. 'default' => 0,
  368. 'description' => 'Import date of the feed item, as a Unix timestamp.',
  369. ),
  370. 'url' => array(
  371. 'type' => 'text',
  372. 'not null' => TRUE,
  373. 'description' => 'Link to the feed item.',
  374. ),
  375. 'guid' => array(
  376. 'type' => 'text',
  377. 'not null' => TRUE,
  378. 'description' => 'Unique identifier for the feed item.'
  379. ),
  380. 'hash' => array(
  381. 'type' => 'varchar',
  382. 'length' => 32, // The length of an MD5 hash.
  383. 'not null' => TRUE,
  384. 'default' => '',
  385. 'description' => 'The hash of the source item.',
  386. ),
  387. ),
  388. 'primary key' => array('entity_type', 'entity_id'),
  389. 'indexes' => array(
  390. 'id' => array('id'),
  391. 'feed_nid' => array('feed_nid'),
  392. 'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
  393. 'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
  394. 'imported' => array('imported'),
  395. ),
  396. );
  397. db_create_table('feeds_item', $spec);
  398. // Copy all existing values from old tables and drop them.
  399. $insert = "INSERT INTO {feeds_item} (entity_type, entity_id, id, feed_nid, imported, url, guid, hash)";
  400. db_query($insert . " SELECT 'node', nid, id, feed_nid, imported, url, guid, hash FROM {feeds_node_item}");
  401. db_query($insert . " SELECT 'taxonomy_term', tid, id, feed_nid, 0, '', '', '' FROM {feeds_term_item}");
  402. db_drop_table('feeds_node_item');
  403. db_drop_table('feeds_term_item');
  404. }
  405. /**
  406. * Add feeds_log table.
  407. */
  408. function feeds_update_7203() {
  409. $schema = array(
  410. 'description' => 'Table that contains logs of feeds events.',
  411. 'fields' => array(
  412. 'flid' => array(
  413. 'type' => 'serial',
  414. 'not null' => TRUE,
  415. 'description' => 'Primary Key: Unique feeds event ID.',
  416. ),
  417. 'id' => array(
  418. 'type' => 'varchar',
  419. 'length' => 128,
  420. 'not null' => TRUE,
  421. 'default' => '',
  422. 'description' => 'The id of the importer that logged the event.',
  423. ),
  424. 'feed_nid' => array(
  425. 'type' => 'int',
  426. 'unsigned' => TRUE,
  427. 'not null' => TRUE,
  428. 'description' => 'Node id of the source, if available.',
  429. ),
  430. 'log_time' => array(
  431. 'type' => 'int',
  432. 'not null' => TRUE,
  433. 'default' => 0,
  434. 'description' => 'Unix timestamp of when event occurred.',
  435. ),
  436. 'request_time' => array(
  437. 'type' => 'int',
  438. 'not null' => TRUE,
  439. 'default' => 0,
  440. 'description' => 'Unix timestamp of the request when the event occurred.',
  441. ),
  442. 'type' => array(
  443. 'type' => 'varchar',
  444. 'length' => 64,
  445. 'not null' => TRUE,
  446. 'default' => '',
  447. 'description' => 'Type of log message, for example "feeds_import"."',
  448. ),
  449. 'message' => array(
  450. 'type' => 'text',
  451. 'not null' => TRUE,
  452. 'size' => 'big',
  453. 'description' => 'Text of log message to be passed into the t() function.',
  454. ),
  455. 'variables' => array(
  456. 'type' => 'blob',
  457. 'not null' => TRUE,
  458. 'size' => 'big',
  459. 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
  460. ),
  461. 'severity' => array(
  462. 'type' => 'int',
  463. 'unsigned' => TRUE,
  464. 'not null' => TRUE,
  465. 'default' => 0,
  466. 'size' => 'tiny',
  467. 'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
  468. ),
  469. ),
  470. 'primary key' => array('flid'),
  471. 'indexes' => array(
  472. 'id' => array('id'),
  473. 'id_feed_nid' => array('id', 'feed_nid'),
  474. 'request_time' => array('request_time'),
  475. 'log_time' => array('log_time'),
  476. 'type' => array('type'),
  477. ),
  478. );
  479. db_create_table('feeds_log', $schema);
  480. }
  481. /**
  482. * Add index for looking up by entity_type + url/ guid to feeds_item table.
  483. */
  484. function feeds_update_7204() {
  485. db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
  486. db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
  487. }
  488. /**
  489. * Shorten {feeds_item}.entity_type to 32 chars and shorten relevant indexes.
  490. */
  491. function feeds_update_7205() {
  492. db_drop_primary_key('feeds_item');
  493. db_drop_index('feeds_item', 'lookup_url');
  494. db_drop_index('feeds_item', 'lookup_guid');
  495. db_drop_index('feeds_item', 'global_lookup_url');
  496. db_drop_index('feeds_item', 'global_lookup_guid');
  497. db_change_field('feeds_item', 'entity_type', 'entity_type', array(
  498. 'type' => 'varchar',
  499. 'length' => 32,
  500. 'not null' => TRUE,
  501. 'default' => '',
  502. 'description' => 'The entity type.',
  503. ));
  504. db_add_primary_key('feeds_item', array('entity_type', 'entity_id'));
  505. db_add_index('feeds_item', 'lookup_url', array('entity_type', 'id', 'feed_nid', array('url', 128)));
  506. db_add_index('feeds_item', 'lookup_guid', array('entity_type', 'id', 'feed_nid', array('guid', 128)));
  507. db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
  508. db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
  509. }
  510. /**
  511. * Change state and fetcher_result fields from text to blob.
  512. */
  513. function feeds_update_7206() {
  514. db_change_field('feeds_source', 'state', 'state', array(
  515. 'type' => 'blob',
  516. 'size' => 'big',
  517. 'not null' => FALSE,
  518. 'description' => 'State of import or clearing batches.',
  519. 'serialize' => TRUE,
  520. ));
  521. db_change_field('feeds_source', 'fetcher_result', 'fetcher_result', array(
  522. 'type' => 'blob',
  523. 'size' => 'big',
  524. 'not null' => FALSE,
  525. 'description' => 'Cache for fetcher result.',
  526. 'serialize' => TRUE,
  527. ));
  528. }
  529. /**
  530. * Change config fields from text to big blobs.
  531. */
  532. function feeds_update_7207() {
  533. db_change_field('feeds_importer', 'config', 'config', array(
  534. 'type' => 'blob',
  535. 'size' => 'big',
  536. 'not null' => FALSE,
  537. 'description' => 'Configuration of the feeds object.',
  538. 'serialize' => TRUE,
  539. ));
  540. db_change_field('feeds_source', 'config', 'config', array(
  541. 'type' => 'blob',
  542. 'size' => 'big',
  543. 'not null' => FALSE,
  544. 'description' => 'Configuration of the feeds object.',
  545. 'serialize' => TRUE,
  546. ));
  547. }