wine.install.inc 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. <?php
  2. /**
  3. * @file
  4. * Set up for the wine (advanced) example.
  5. */
  6. function migrate_example_wine_schema() {
  7. $schema['migrate_example_wine_account'] = migrate_example_wine_schema_account();
  8. $schema['migrate_example_wine_account_updates'] = migrate_example_wine_schema_account_updates();
  9. $schema['migrate_example_wine_categories'] = migrate_example_wine_schema_categories();
  10. $schema['migrate_example_wine_vintages'] = migrate_example_wine_schema_vintages();
  11. $schema['migrate_example_wine_variety_updates'] = migrate_example_wine_schema_variety_updates();
  12. $schema['migrate_example_wine'] = migrate_example_wine_schema_wine();
  13. $schema['migrate_example_wine_updates'] = migrate_example_wine_schema_updates();
  14. $schema['migrate_example_wine_producer'] = migrate_example_wine_schema_producer();
  15. $schema['migrate_example_wine_category_wine'] = migrate_example_wine_schema_category_wine();
  16. $schema['migrate_example_wine_category_producer'] = migrate_example_wine_schema_category_producer();
  17. $schema['migrate_example_wine_comment'] = migrate_example_wine_schema_comment();
  18. $schema['migrate_example_wine_comment_updates'] = migrate_example_wine_schema_comment_updates();
  19. $schema['migrate_example_wine_files'] = migrate_example_wine_schema_files();
  20. $schema['migrate_example_wine_blobs'] = migrate_example_wine_schema_blobs();
  21. $schema['migrate_example_wine_table_source'] = migrate_example_wine_schema_table_source();
  22. $schema['migrate_example_wine_table_dest'] = migrate_example_wine_schema_table_dest();
  23. return $schema;
  24. }
  25. function migrate_example_wine_install() {
  26. migrate_example_wine_content_types();
  27. migrate_example_wine_categories();
  28. migrate_example_wine_fields();
  29. // Populate our tables.
  30. migrate_example_wine_data_account();
  31. migrate_example_wine_data_account_updates();
  32. migrate_example_wine_data_categories();
  33. migrate_example_wine_data_vintages();
  34. migrate_example_wine_data_variety_updates();
  35. migrate_example_wine_data_wine();
  36. migrate_example_wine_data_updates();
  37. migrate_example_wine_data_producer();
  38. migrate_example_wine_data_category_wine();
  39. migrate_example_wine_data_category_producer();
  40. migrate_example_wine_data_comment();
  41. migrate_example_wine_data_comment_updates();
  42. migrate_example_wine_data_files();
  43. migrate_example_wine_data_blobs();
  44. migrate_example_wine_data_table_source();
  45. }
  46. function migrate_example_wine_uninstall() {
  47. migrate_example_wine_content_type_delete();
  48. if ($vids = taxonomy_vocabulary_load_multiple(array(), array('machine_name' => 'migrate_example_wine_varieties'))) {
  49. // Grab key of the first returned vocabulary.
  50. taxonomy_vocabulary_delete(key($vids));
  51. }
  52. if ($vids = taxonomy_vocabulary_load_multiple(array(), array('machine_name' => 'migrate_example_wine_regions'))) {
  53. // Grab key of the first returned vocabulary.
  54. taxonomy_vocabulary_delete(key($vids));
  55. }
  56. if ($vids = taxonomy_vocabulary_load_multiple(array(), array('machine_name' => 'migrate_example_wine_best_with'))) {
  57. // Grab key of the first returned vocabulary.
  58. taxonomy_vocabulary_delete(key($vids));
  59. }
  60. }
  61. function migrate_example_wine_disable() {
  62. MigrationBase::deregisterMigration('WinePrep');
  63. Migration::deregisterMigration('WineFileCopy');
  64. Migration::deregisterMigration('WineFileBlob');
  65. Migration::deregisterMigration('WineRegion');
  66. Migration::deregisterMigration('WineUser');
  67. Migration::deregisterMigration('WineVariety');
  68. Migration::deregisterMigration('WineBestWith');
  69. Migration::deregisterMigration('WineProducer');
  70. Migration::deregisterMigration('WineProducerXML');
  71. Migration::deregisterMigration('WineProducerXMLPull');
  72. Migration::deregisterMigration('WineProducerMultiXML');
  73. Migration::deregisterMigration('WineWine');
  74. Migration::deregisterMigration('WineComment');
  75. MigrationBase::deregisterMigration('WineFinish');
  76. Migration::deregisterMigration('WineUpdates');
  77. Migration::deregisterMigration('WineUserUpdates');
  78. Migration::deregisterMigration('WineVarietyUpdates');
  79. Migration::deregisterMigration('WineCommentUpdates');
  80. Migration::deregisterMigration('WineRole');
  81. Migration::deregisterMigration('WineTable');
  82. }
  83. function migrate_example_wine_schema_wine() {
  84. return array(
  85. 'description' => 'Wines of the world',
  86. 'fields' => array(
  87. 'wineid' => array(
  88. 'type' => 'int',
  89. 'unsigned' => TRUE,
  90. 'not null' => TRUE,
  91. 'description' => 'Wine ID',
  92. ),
  93. 'name' => array(
  94. 'type' => 'varchar',
  95. 'length' => 255,
  96. 'not null' => TRUE,
  97. ),
  98. 'body' => array(
  99. 'type' => 'varchar',
  100. 'length' => 255,
  101. 'not null' => FALSE,
  102. 'description' => 'Full description of the wine.',
  103. ),
  104. 'excerpt' => array(
  105. 'type' => 'varchar',
  106. 'length' => 255,
  107. 'not null' => FALSE,
  108. 'description' => 'Abstract for this wine.',
  109. ),
  110. 'accountid' => array(
  111. 'type' => 'int',
  112. 'unsigned' => TRUE,
  113. 'not null' => FALSE,
  114. 'description' => 'ID of the author.',
  115. ),
  116. 'posted' => array(
  117. 'type' => 'int',
  118. 'unsigned' => TRUE,
  119. 'not null' => TRUE,
  120. 'description' => 'Original creation date',
  121. ),
  122. 'last_changed' => array(
  123. 'type' => 'int',
  124. 'unsigned' => TRUE,
  125. 'not null' => TRUE,
  126. 'description' => 'Last change date',
  127. ),
  128. 'variety' => array(
  129. 'type' => 'int',
  130. 'unsigned' => TRUE,
  131. 'not null' => TRUE,
  132. 'description' => 'Wine variety',
  133. ),
  134. 'region' => array(
  135. 'type' => 'int',
  136. 'unsigned' => TRUE,
  137. 'not null' => TRUE,
  138. 'description' => 'Wine region',
  139. ),
  140. 'rating' => array(
  141. 'type' => 'int',
  142. 'unsigned' => TRUE,
  143. 'not null' => FALSE,
  144. 'description' => 'Rating (100-point scale)',
  145. ),
  146. ),
  147. 'primary key' => array('wineid'),
  148. );
  149. }
  150. function migrate_example_wine_schema_updates() {
  151. return array(
  152. 'description' => 'Updated wine ratings',
  153. 'fields' => array(
  154. 'wineid' => array(
  155. 'type' => 'int',
  156. 'unsigned' => TRUE,
  157. 'not null' => TRUE,
  158. 'description' => 'Wine ID',
  159. ),
  160. 'rating' => array(
  161. 'type' => 'int',
  162. 'unsigned' => TRUE,
  163. 'not null' => FALSE,
  164. 'description' => 'Rating (100-point scale)',
  165. ),
  166. ),
  167. 'primary key' => array('wineid'),
  168. );
  169. }
  170. function migrate_example_wine_schema_producer() {
  171. return array(
  172. 'description' => 'Wine producers of the world',
  173. 'fields' => array(
  174. 'producerid' => array(
  175. 'type' => 'int',
  176. 'unsigned' => TRUE,
  177. 'not null' => TRUE,
  178. 'description' => 'Producer ID',
  179. ),
  180. 'name' => array(
  181. 'type' => 'varchar',
  182. 'length' => 255,
  183. 'not null' => TRUE,
  184. ),
  185. 'body' => array(
  186. 'type' => 'varchar',
  187. 'length' => 255,
  188. 'not null' => FALSE,
  189. 'description' => 'Full description of the producer.',
  190. ),
  191. 'excerpt' => array(
  192. 'type' => 'varchar',
  193. 'length' => 255,
  194. 'not null' => FALSE,
  195. 'description' => 'Abstract for this producer.',
  196. ),
  197. 'accountid' => array(
  198. 'type' => 'int',
  199. 'unsigned' => TRUE,
  200. 'not null' => FALSE,
  201. 'description' => 'Account ID of the author.',
  202. ),
  203. ),
  204. 'primary key' => array('producerid'),
  205. );
  206. }
  207. function migrate_example_wine_schema_categories() {
  208. return array(
  209. 'description' => 'Categories',
  210. 'fields' => array(
  211. 'categoryid' => array(
  212. 'type' => 'int',
  213. 'not null' => TRUE,
  214. 'unsigned' => TRUE,
  215. 'description' => 'Category ID',
  216. ),
  217. 'type' => array(
  218. 'type' => 'varchar',
  219. 'length' => 255,
  220. 'not null' => TRUE,
  221. 'description' => 'Type of category: variety, region, best_with',
  222. ),
  223. 'name' => array(
  224. 'type' => 'varchar',
  225. 'length' => 255,
  226. 'not null' => TRUE,
  227. ),
  228. 'details' => array(
  229. 'type' => 'varchar',
  230. 'length' => 255,
  231. 'not null' => FALSE,
  232. ),
  233. 'category_parent' => array(
  234. 'type' => 'int',
  235. 'unsigned' => TRUE,
  236. 'not null' => FALSE,
  237. 'description' => 'Parent category, if any',
  238. ),
  239. 'ordering' => array(
  240. 'type' => 'int',
  241. 'unsigned' => FALSE,
  242. 'not null' => FALSE,
  243. 'description' => 'Order in which to display categories',
  244. ),
  245. ),
  246. 'primary key' => array('categoryid'),
  247. );
  248. }
  249. function migrate_example_wine_schema_vintages() {
  250. return array(
  251. 'description' => 'Wine vintages',
  252. 'fields' => array(
  253. 'wineid' => array(
  254. 'type' => 'int',
  255. 'not null' => TRUE,
  256. 'description' => 'Wine ID',
  257. ),
  258. 'vintage' => array(
  259. 'type' => 'int',
  260. 'unsigned' => TRUE,
  261. 'not null' => TRUE,
  262. 'description' => 'Vintage (year)',
  263. ),
  264. ),
  265. 'primary key' => array('wineid', 'vintage'),
  266. );
  267. }
  268. function migrate_example_wine_schema_variety_updates() {
  269. return array(
  270. 'description' => 'Variety updates',
  271. 'fields' => array(
  272. 'categoryid' => array(
  273. 'type' => 'int',
  274. 'not null' => TRUE,
  275. 'unsigned' => TRUE,
  276. 'description' => 'Category ID',
  277. ),
  278. 'details' => array(
  279. 'type' => 'varchar',
  280. 'length' => 255,
  281. 'not null' => FALSE,
  282. ),
  283. ),
  284. 'primary key' => array('categoryid'),
  285. );
  286. }
  287. function migrate_example_wine_schema_category_wine() {
  288. return array(
  289. 'description' => 'Wine category assignments',
  290. 'fields' => array(
  291. 'wineid' => array(
  292. 'type' => 'int',
  293. 'not null' => TRUE,
  294. 'description' => 'Wine ID',
  295. ),
  296. 'categoryid' => array(
  297. 'type' => 'int',
  298. 'unsigned' => TRUE,
  299. 'not null' => TRUE,
  300. 'description' => 'Category ID',
  301. ),
  302. ),
  303. 'primary key' => array('categoryid', 'wineid'),
  304. );
  305. }
  306. function migrate_example_wine_schema_category_producer() {
  307. return array(
  308. 'description' => 'Producer category assignments',
  309. 'fields' => array(
  310. 'producerid' => array(
  311. 'type' => 'int',
  312. 'not null' => TRUE,
  313. 'description' => 'Producer ID',
  314. ),
  315. 'categoryid' => array(
  316. 'type' => 'int',
  317. 'unsigned' => TRUE,
  318. 'not null' => TRUE,
  319. 'description' => 'Category ID',
  320. ),
  321. ),
  322. 'primary key' => array('categoryid', 'producerid'),
  323. );
  324. }
  325. function migrate_example_wine_schema_comment() {
  326. return array(
  327. 'description' => 'Wine comments',
  328. 'fields' => array(
  329. 'commentid' => array(
  330. 'type' => 'int',
  331. 'unsigned' => TRUE,
  332. 'not null' => TRUE,
  333. 'description' => 'Comment ID',
  334. ),
  335. 'wineid' => array(
  336. 'type' => 'int',
  337. 'unsigned' => TRUE,
  338. 'not null' => TRUE,
  339. 'description' => 'Wine ID that is being commented upon',
  340. ),
  341. 'comment_parent' => array(
  342. 'type' => 'int',
  343. 'unsigned' => TRUE,
  344. 'not null' => FALSE,
  345. 'description' => 'Parent comment ID in case of comment replies.',
  346. ),
  347. 'subject' => array(
  348. 'type' => 'varchar',
  349. 'length' => 255,
  350. 'not null' => FALSE,
  351. 'description' => 'Comment subject',
  352. ),
  353. 'body' => array(
  354. 'type' => 'varchar',
  355. 'length' => 255,
  356. 'not null' => FALSE,
  357. 'description' => 'Comment body',
  358. ),
  359. 'name' => array(
  360. 'type' => 'varchar',
  361. 'length' => 255,
  362. 'not null' => FALSE,
  363. 'description' => 'Comment name (if anon)',
  364. ),
  365. 'mail' => array(
  366. 'type' => 'varchar',
  367. 'length' => 255,
  368. 'not null' => FALSE,
  369. 'description' => 'Comment email (if anon)',
  370. ),
  371. 'accountid' => array(
  372. 'type' => 'int',
  373. 'unsigned' => TRUE,
  374. 'not null' => FALSE,
  375. 'description' => 'Account ID (if any).',
  376. ),
  377. 'commenthost' => array(
  378. 'type' => 'varchar',
  379. 'length' => 255,
  380. 'not null' => FALSE,
  381. 'description' => 'IP/domain of host posted from',
  382. ),
  383. 'userpage' => array(
  384. 'type' => 'varchar',
  385. 'length' => 255,
  386. 'not null' => FALSE,
  387. 'description' => 'User homepage',
  388. ),
  389. 'posted' => array(
  390. 'type' => 'int',
  391. 'unsigned' => TRUE,
  392. 'not null' => TRUE,
  393. 'description' => 'Date comment posted',
  394. ),
  395. 'lastchanged' => array(
  396. 'type' => 'int',
  397. 'unsigned' => TRUE,
  398. 'not null' => TRUE,
  399. 'description' => 'Date comment last changed',
  400. ),
  401. ),
  402. 'primary key' => array('commentid'),
  403. );
  404. }
  405. function migrate_example_wine_schema_comment_updates() {
  406. return array(
  407. 'description' => 'Wine comment updates',
  408. 'fields' => array(
  409. 'commentid' => array(
  410. 'type' => 'int',
  411. 'unsigned' => TRUE,
  412. 'not null' => TRUE,
  413. 'description' => 'Comment ID',
  414. ),
  415. 'subject' => array(
  416. 'type' => 'varchar',
  417. 'length' => 255,
  418. 'not null' => FALSE,
  419. 'description' => 'Comment subject',
  420. ),
  421. ),
  422. 'primary key' => array('commentid'),
  423. );
  424. }
  425. function migrate_example_wine_schema_account() {
  426. return array(
  427. 'description' => 'Wine accounts.',
  428. 'fields' => array(
  429. 'accountid' => array(
  430. 'type' => 'serial',
  431. 'not null' => TRUE,
  432. 'description' => 'Account ID',
  433. ),
  434. 'status' => array(
  435. 'type' => 'int',
  436. 'not null' => TRUE,
  437. 'description' => 'Blocked_Allowed',
  438. ),
  439. 'posted' => array(
  440. 'type' => 'varchar',
  441. 'length' => 255,
  442. 'not null' => TRUE,
  443. 'description' => 'Registration date',
  444. ),
  445. 'last_access' => array(
  446. 'type' => 'varchar',
  447. 'length' => 255,
  448. 'not null' => TRUE,
  449. 'description' => 'Last access date',
  450. ),
  451. 'last_login' => array(
  452. 'type' => 'varchar',
  453. 'length' => 255,
  454. 'not null' => TRUE,
  455. 'description' => 'Last login date',
  456. ),
  457. 'name' => array(
  458. 'type' => 'varchar',
  459. 'length' => 255,
  460. 'not null' => FALSE,
  461. 'description' => 'Account name (for login)',
  462. ),
  463. 'sex' => array(
  464. 'type' => 'char',
  465. 'length' => 1,
  466. 'not null' => FALSE,
  467. 'description' => 'Gender',
  468. ),
  469. 'password' => array(
  470. 'type' => 'varchar',
  471. 'length' => 255,
  472. 'not null' => FALSE,
  473. 'description' => 'Account password (raw)',
  474. ),
  475. 'mail' => array(
  476. 'type' => 'varchar',
  477. 'length' => 255,
  478. 'not null' => FALSE,
  479. 'description' => 'Account email',
  480. ),
  481. 'original_mail' => array(
  482. 'type' => 'varchar',
  483. 'length' => 255,
  484. 'not null' => FALSE,
  485. 'description' => 'Original account email',
  486. ),
  487. 'sig' => array(
  488. 'type' => 'varchar',
  489. 'length' => 255,
  490. 'not null' => TRUE,
  491. 'description' => 'Signature for comments',
  492. ),
  493. 'imageid' => array(
  494. 'type' => 'int',
  495. 'unsigned' => TRUE,
  496. 'not null' => FALSE,
  497. 'description' => 'Image ID',
  498. ),
  499. 'positions' => array(
  500. 'type' => 'varchar',
  501. 'length' => 255,
  502. 'not null' => FALSE,
  503. 'description' => 'Positions held',
  504. ),
  505. ),
  506. 'primary key' => array('accountid'),
  507. );
  508. }
  509. function migrate_example_wine_schema_account_updates() {
  510. return array(
  511. 'description' => 'Wine account updates',
  512. 'fields' => array(
  513. 'accountid' => array(
  514. 'type' => 'serial',
  515. 'not null' => TRUE,
  516. 'description' => 'Account ID',
  517. ),
  518. 'sex' => array(
  519. 'type' => 'char',
  520. 'length' => 1,
  521. 'not null' => FALSE,
  522. 'description' => 'Gender',
  523. ),
  524. ),
  525. 'primary key' => array('accountid'),
  526. );
  527. }
  528. function migrate_example_wine_schema_blobs() {
  529. return array(
  530. 'description' => 'Wine blobs to be migrated to file entities',
  531. 'fields' => array(
  532. 'imageid' => array(
  533. 'type' => 'int',
  534. 'unsigned' => TRUE,
  535. 'not null' => TRUE,
  536. 'description' => 'Image ID',
  537. ),
  538. 'imageblob' => array(
  539. 'type' => 'blob',
  540. 'size' => 'normal',
  541. 'description' => 'binary image data',
  542. ),
  543. ),
  544. 'primary key' => array('imageid'),
  545. );
  546. }
  547. function migrate_example_wine_schema_files() {
  548. return array(
  549. 'description' => 'Wine and account files',
  550. 'fields' => array(
  551. 'imageid' => array(
  552. 'type' => 'int',
  553. 'unsigned' => TRUE,
  554. 'not null' => TRUE,
  555. 'description' => 'Image ID',
  556. ),
  557. 'url' => array(
  558. 'type' => 'varchar',
  559. 'length' => 255,
  560. 'not null' => TRUE,
  561. 'description' => 'Image URL',
  562. ),
  563. 'image_alt' => array(
  564. 'type' => 'varchar',
  565. 'length' => 255,
  566. 'not null' => FALSE,
  567. 'description' => 'Image alt',
  568. ),
  569. 'image_title' => array(
  570. 'type' => 'varchar',
  571. 'length' => 255,
  572. 'not null' => FALSE,
  573. 'description' => 'Image title',
  574. ),
  575. 'wineid' => array(
  576. 'type' => 'int',
  577. 'unsigned' => TRUE,
  578. 'not null' => FALSE,
  579. 'description' => 'Wine node this is associated with',
  580. ),
  581. ),
  582. 'primary key' => array('imageid'),
  583. );
  584. }
  585. function migrate_example_wine_schema_table_source() {
  586. return array(
  587. 'description' => 'Source data to go into a custom Drupal table',
  588. 'fields' => array(
  589. 'fooid' => array(
  590. 'type' => 'int',
  591. 'unsigned' => TRUE,
  592. 'not null' => TRUE,
  593. 'description' => 'Primary key',
  594. ),
  595. 'field1' => array(
  596. 'type' => 'varchar',
  597. 'length' => 255,
  598. 'not null' => TRUE,
  599. 'description' => 'First field',
  600. ),
  601. 'field2' => array(
  602. 'type' => 'int',
  603. 'unsigned' => TRUE,
  604. 'not null' => TRUE,
  605. 'description' => 'Second field',
  606. ),
  607. ),
  608. 'primary key' => array('fooid'),
  609. );
  610. }
  611. function migrate_example_wine_schema_table_dest() {
  612. return array(
  613. 'description' => 'Custom Drupal table to receive source data directly',
  614. 'fields' => array(
  615. 'recordid' => array(
  616. 'type' => 'serial',
  617. 'unsigned' => TRUE,
  618. 'not null' => TRUE,
  619. 'description' => 'Primary key',
  620. ),
  621. 'drupal_text' => array(
  622. 'type' => 'varchar',
  623. 'length' => 255,
  624. 'not null' => TRUE,
  625. 'description' => 'First field',
  626. ),
  627. 'drupal_int' => array(
  628. 'type' => 'int',
  629. 'unsigned' => TRUE,
  630. 'not null' => TRUE,
  631. 'description' => 'Second field',
  632. ),
  633. ),
  634. 'primary key' => array('recordid'),
  635. );
  636. }
  637. function migrate_example_wine_content_types() {
  638. // This code based on from standard.profile.
  639. // Insert default user-defined node types into the database.
  640. $types = array();
  641. $types[] = array(
  642. 'type' => 'migrate_example_wine',
  643. 'name' => st('Wine'),
  644. 'base' => 'node_content',
  645. 'description' => st("Wine is what we drink."),
  646. 'custom' => 1,
  647. 'modified' => 1,
  648. 'locked' => 1,
  649. );
  650. $types[] = array(
  651. 'type' => 'migrate_example_producer',
  652. 'name' => st('Wine Producer'),
  653. 'base' => 'node_content',
  654. 'description' => st("Wineries, vineyards, and large producers"),
  655. 'custom' => 1,
  656. 'modified' => 1,
  657. 'locked' => 1,
  658. );
  659. foreach ($types as $type) {
  660. $type = node_type_set_defaults($type);
  661. node_type_save($type);
  662. node_add_body_field($type);
  663. }
  664. }
  665. function migrate_example_wine_categories() {
  666. // Create vocabularies for variety, region, and "best with"
  667. $description = st('Wine varieties');
  668. $help = st('Select the variety of this wine');
  669. $vocabulary = (object) array(
  670. 'name' => 'Migrate Example Wine Varieties',
  671. 'description' => $description,
  672. 'machine_name' => 'migrate_example_wine_varieties',
  673. 'help' => $help,
  674. );
  675. taxonomy_vocabulary_save($vocabulary);
  676. if (!field_info_field('migrate_example_wine_varieties')) {
  677. $field = array(
  678. 'field_name' => $vocabulary->machine_name,
  679. 'type' => 'taxonomy_term_reference',
  680. 'cardinality' => 1,
  681. 'settings' => array(
  682. 'allowed_values' => array(
  683. array(
  684. 'vocabulary' => $vocabulary->machine_name,
  685. 'vid' => $vocabulary->vid,
  686. 'parent' => 0,
  687. ),
  688. ),
  689. ),
  690. );
  691. field_create_field($field);
  692. }
  693. if (!field_info_instance('node', 'migrate_example_wine_varieties', 'migrate_example_wine')) {
  694. $instance = array(
  695. 'field_name' => $vocabulary->machine_name,
  696. 'entity_type' => 'node',
  697. 'label' => $vocabulary->name,
  698. 'bundle' => 'migrate_example_wine',
  699. 'description' => $vocabulary->help,
  700. 'widget' => array(
  701. 'type' => 'taxonomy_autocomplete',
  702. ),
  703. );
  704. field_create_instance($instance);
  705. }
  706. $description = st('Wine regions');
  707. $help = st('Select the region this wine comes from');
  708. $vocabulary = (object) array(
  709. 'name' => 'Migrate Example Wine Regions',
  710. 'description' => $description,
  711. 'machine_name' => 'migrate_example_wine_regions',
  712. 'help' => $help,
  713. );
  714. taxonomy_vocabulary_save($vocabulary);
  715. if (!field_info_field('migrate_example_wine_regions')) {
  716. $field = array(
  717. 'field_name' => $vocabulary->machine_name,
  718. 'type' => 'taxonomy_term_reference',
  719. 'cardinality' => 1,
  720. 'settings' => array(
  721. 'allowed_values' => array(
  722. array(
  723. 'vocabulary' => $vocabulary->machine_name,
  724. 'vid' => $vocabulary->vid,
  725. 'parent' => 0,
  726. ),
  727. ),
  728. ),
  729. );
  730. field_create_field($field);
  731. }
  732. if (!field_info_instance('node', 'migrate_example_wine_regions', 'migrate_example_wine')) {
  733. $instance = array(
  734. 'field_name' => $vocabulary->machine_name,
  735. 'entity_type' => 'node',
  736. 'label' => $vocabulary->name,
  737. 'bundle' => 'migrate_example_wine',
  738. 'description' => $vocabulary->help,
  739. 'widget' => array(
  740. 'type' => 'taxonomy_autocomplete',
  741. ),
  742. );
  743. field_create_instance($instance);
  744. }
  745. if (!field_info_instance('node', 'migrate_example_wine_regions', 'migrate_example_producer')) {
  746. $instance = array(
  747. 'field_name' => $vocabulary->machine_name,
  748. 'entity_type' => 'node',
  749. 'label' => $vocabulary->name,
  750. 'bundle' => 'migrate_example_producer',
  751. 'description' => $vocabulary->help,
  752. 'widget' => array(
  753. 'type' => 'taxonomy_autocomplete',
  754. ),
  755. );
  756. field_create_instance($instance);
  757. }
  758. $description = st('Foods the wine goes best with');
  759. $help = st('Enter any foods this wine may be paired with, separated by commas');
  760. $vocabulary = (object) array(
  761. 'name' => 'Migrate Example Wine Best With',
  762. 'description' => $description,
  763. 'machine_name' => 'migrate_example_wine_best_with',
  764. 'help' => $help,
  765. );
  766. taxonomy_vocabulary_save($vocabulary);
  767. if (!field_info_field('migrate_example_wine_best_with')) {
  768. $field = array(
  769. 'field_name' => $vocabulary->machine_name,
  770. 'type' => 'taxonomy_term_reference',
  771. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  772. 'settings' => array(
  773. 'allowed_values' => array(
  774. array(
  775. 'vocabulary' => $vocabulary->machine_name,
  776. 'vid' => $vocabulary->vid,
  777. 'parent' => 0,
  778. ),
  779. ),
  780. ),
  781. );
  782. field_create_field($field);
  783. }
  784. if (!field_info_instance('node', 'migrate_example_wine_best_with', 'migrate_example_wine')) {
  785. $instance = array(
  786. 'field_name' => $vocabulary->machine_name,
  787. 'entity_type' => 'node',
  788. 'label' => $vocabulary->name,
  789. 'bundle' => 'migrate_example_wine',
  790. 'description' => $vocabulary->help,
  791. 'widget' => array(
  792. 'type' => 'taxonomy_autocomplete',
  793. ),
  794. );
  795. field_create_instance($instance);
  796. }
  797. }
  798. // Create an image field named "Migrate Example Image", enabled for the 'wine' content type.
  799. function migrate_example_wine_fields() {
  800. if (!field_info_field('field_migrate_example_image')) {
  801. $field = array(
  802. 'field_name' => 'field_migrate_example_image',
  803. 'type' => 'image',
  804. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  805. 'translatable' => TRUE,
  806. 'indexes' => array('fid' => array('fid')),
  807. 'settings' => array(
  808. 'uri_scheme' => 'public',
  809. 'default_image' => FALSE,
  810. ),
  811. );
  812. field_create_field($field);
  813. }
  814. if (!field_info_instance('node', 'field_migrate_example_image', 'migrate_example_wine')) {
  815. $instance = array(
  816. 'field_name' => 'field_migrate_example_image',
  817. 'entity_type' => 'node',
  818. 'label' => 'Image',
  819. 'bundle' => 'migrate_example_wine',
  820. 'description' => 'Upload an image to go with this wine.',
  821. 'settings' => array(
  822. 'file_directory' => 'field/migrate_example/image',
  823. 'file_extensions' => 'png gif jpg jpeg',
  824. 'max_filesize' => '',
  825. 'max_resolution' => '',
  826. 'min_resolution' => '',
  827. 'alt_field' => TRUE,
  828. 'title_field' => '',
  829. ),
  830. 'widget' => array(
  831. 'type' => 'image_image',
  832. 'settings' => array(
  833. 'progress_indicator' => 'throbber',
  834. 'preview_image_style' => 'thumbnail',
  835. ),
  836. 'weight' => -1,
  837. ),
  838. 'display' => array(
  839. 'full' => array(
  840. 'label' => 'hidden',
  841. 'type' => 'image__large',
  842. 'settings' => array(),
  843. 'weight' => -1,
  844. ),
  845. 'teaser' => array(
  846. 'label' => 'hidden',
  847. 'type' => 'image_link_content__medium',
  848. 'settings' => array(),
  849. 'weight' => -1,
  850. ),
  851. 'rss' => array(
  852. 'label' => 'hidden',
  853. 'type' => 'image__large',
  854. 'settings' => array(),
  855. 'weight' => -1,
  856. ),
  857. 'search_index' => array(
  858. 'label' => 'hidden',
  859. 'type' => 'image__large',
  860. 'settings' => array(),
  861. 'weight' => -1,
  862. ),
  863. 'search_results' => array(
  864. 'label' => 'hidden',
  865. 'type' => 'image__large',
  866. 'settings' => array(),
  867. 'weight' => -1,
  868. ),
  869. ),
  870. );
  871. field_create_instance($instance);
  872. }
  873. if (!field_info_field('field_migrate_example_wine_ratin')) {
  874. $field = array(
  875. 'field_name' => 'field_migrate_example_wine_ratin',
  876. 'type' => 'number_decimal',
  877. 'cardinality' => 1,
  878. 'translatable' => TRUE,
  879. );
  880. field_create_field($field);
  881. }
  882. if (!field_info_instance('node', 'field_migrate_example_wine_ratin', 'migrate_example_wine')) {
  883. $instance = array(
  884. 'field_name' => 'field_migrate_example_wine_ratin',
  885. 'entity_type' => 'node',
  886. 'label' => 'Rating',
  887. 'bundle' => 'migrate_example_wine',
  888. 'description' => 'Rating on a 1-100 scale',
  889. 'settings' => array(
  890. 'scale' => 0,
  891. ),
  892. 'widget' => array(
  893. 'type' => 'number',
  894. 'weight' => -1,
  895. ),
  896. );
  897. field_create_instance($instance);
  898. }
  899. if (!field_info_field('field_migrate_example_top_vintag')) {
  900. $field = array(
  901. 'field_name' => 'field_migrate_example_top_vintag',
  902. 'type' => 'number_integer',
  903. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  904. 'translatable' => TRUE,
  905. );
  906. field_create_field($field);
  907. }
  908. if (!field_info_instance('node', 'field_migrate_example_top_vintag', 'migrate_example_wine')) {
  909. $instance = array(
  910. 'field_name' => 'field_migrate_example_top_vintag',
  911. 'entity_type' => 'node',
  912. 'label' => 'Recommended vintages',
  913. 'bundle' => 'migrate_example_wine',
  914. 'description' => '',
  915. 'settings' => array(
  916. 'scale' => 0,
  917. ),
  918. 'widget' => array(
  919. 'type' => 'number',
  920. 'weight' => -1,
  921. ),
  922. );
  923. field_create_instance($instance);
  924. }
  925. }
  926. function migrate_example_wine_content_type_delete() {
  927. $bundle = 'migrate_example_wine';
  928. $field_names = array('migrate_example_wine_varieties',
  929. 'migrate_example_wine_regions', 'migrate_example_wine_best_with',
  930. 'field_migrate_example_image');
  931. foreach ($field_names as $field_name) {
  932. $instance = field_info_instance('node', $field_name, $bundle);
  933. field_delete_instance($instance);
  934. field_delete_field($field_name);
  935. }
  936. node_type_delete($bundle);
  937. $bundle = 'migrate_example_producer';
  938. $field_names = array('migrate_example_wine_regions');
  939. foreach ($field_names as $field_name) {
  940. $instance = field_info_instance('node', $field_name, $bundle);
  941. field_delete_instance($instance);
  942. field_delete_field($field_name);
  943. }
  944. node_type_delete($bundle);
  945. }
  946. function migrate_example_wine_data_wine() {
  947. $fields = array('wineid', 'name', 'body', 'excerpt', 'accountid',
  948. 'posted', 'last_changed', 'variety', 'region', 'rating');
  949. $query = db_insert('migrate_example_wine')
  950. ->fields($fields);
  951. $data = array(
  952. array(1, 'Montes Classic Cabernet Sauvignon', 'Intense ruby-red color', 'Great!', 9,
  953. strtotime('2010-01-02 03:04:05'), strtotime('2010-03-04 05:06:07'), 25, 17, 95),
  954. array(2, 'Archeo Ruggero di Tasso Nero d\'Avola', 'Lots of berry character', 'Pair with red sauced dishes', 3,
  955. strtotime('2010-09-03 18:23:58'), strtotime('2010-09-03 18:23:58'), 26, 2, 85),
  956. );
  957. foreach ($data as $row) {
  958. $query->values(array_combine($fields, $row));
  959. }
  960. $query->execute();
  961. }
  962. function migrate_example_wine_data_updates() {
  963. $fields = array('wineid', 'rating');
  964. $query = db_insert('migrate_example_wine_updates')
  965. ->fields($fields);
  966. $data = array(
  967. array(1, 93),
  968. array(2, NULL),
  969. );
  970. foreach ($data as $row) {
  971. $query->values(array_combine($fields, $row));
  972. }
  973. $query->execute();
  974. }
  975. function migrate_example_wine_data_producer() {
  976. $fields = array('producerid', 'name', 'body', 'excerpt', 'accountid');
  977. $query = db_insert('migrate_example_wine_producer')
  978. ->fields($fields);
  979. $data = array(
  980. array(1, 'Montes', 'Fine Chilean winery', 'Great!', 9),
  981. array(2, 'Archeo', 'Sicilia!', NULL, 3),
  982. );
  983. foreach ($data as $row) {
  984. $query->values(array_combine($fields, $row));
  985. }
  986. $query->execute();
  987. }
  988. function migrate_example_wine_data_account() {
  989. $fields = array('accountid', 'status', 'posted', 'last_access', 'last_login',
  990. 'name', 'sex', 'password', 'mail', 'original_mail', 'sig', 'imageid', 'positions');
  991. $query = db_insert('migrate_example_wine_account')
  992. ->fields($fields);
  993. $data = array(
  994. array(1, 1, '2010-03-30 10:31:05', '2010-04-30 18:25:24', '2010-04-30 14:01:02',
  995. 'darren', 'M', 'dpass', 'ddarren@example.com', 'darren@example.com',
  996. 'All about the Australians', NULL, '5'),
  997. array(3, 0, '2007-03-15 10:31:05', '2007-06-10 04:11:38', '2007-06-10 04:11:38',
  998. 'emily', 'F', 'insecure', 'emily@example.com', 'emily@example.com',
  999. 'Sommelier to the stars', NULL, '18'),
  1000. array(9, 1, '2004-02-29 10:31:05', '2004-02-29 10:31:05', '2004-02-29 10:31:05',
  1001. 'fonzie', NULL, 'bike', 'thefonz@example.com', 'arthur@example.com',
  1002. 'Aaay!', 1, '5,18'),
  1003. );
  1004. foreach ($data as $row) {
  1005. $query->values(array_combine($fields, $row));
  1006. }
  1007. $query->execute();
  1008. }
  1009. function migrate_example_wine_data_account_updates() {
  1010. $fields = array('accountid', 'sex');
  1011. $query = db_insert('migrate_example_wine_account_updates')
  1012. ->fields($fields);
  1013. $data = array(
  1014. array(1, NULL),
  1015. array(3, 'M'),
  1016. array(9, 'F'),
  1017. );
  1018. foreach ($data as $row) {
  1019. $query->values(array_combine($fields, $row));
  1020. }
  1021. $query->execute();
  1022. }
  1023. function migrate_example_wine_data_comment() {
  1024. $fields = array('commentid', 'wineid', 'comment_parent', 'subject', 'body',
  1025. 'name', 'mail', 'accountid', 'commenthost', 'userpage', 'posted', 'lastchanged');
  1026. $query = db_insert('migrate_example_wine_comment')
  1027. ->fields($fields);
  1028. $data = array(
  1029. array(1, 1, NULL, 'im first', 'Tasty', 'grace', 'grace@example.com', 0,
  1030. '123.456.78.9', 'http:://grace.example.com/',
  1031. strtotime('2010-01-02 03:04:05'), strtotime('2010-04-05 06:07:08')),
  1032. array(2, 1, NULL, 'im second', 'Delicious', 'horace', 'horace@example.com', 0,
  1033. 'example.com', NULL,
  1034. strtotime('2010-02-02 03:04:05'), strtotime('2010-05-05 06:07:08')),
  1035. array(3, 1, NULL, 'im parent', 'Don\'t care for it', 'irene', 'irene@example.com', 0,
  1036. '254.0.2.5', 'http:://www.example.com/irene',
  1037. strtotime('2010-03-02 03:04:05'), strtotime('2010-03-02 03:04:05')),
  1038. array(4, 1, 3, 'im child', 'But it\'s so good!', 'emily', NULL, 3,
  1039. '58.29.126.1', 'http:://www.wine.com/',
  1040. strtotime('2010-01-02 03:04:05'), strtotime('2010-01-02 03:04:05')),
  1041. array(5, 1, 4, 'im grandchild', 'Right on, Emily!', 'thefonz@example.com', NULL, 9,
  1042. '123.456.78.9', NULL,
  1043. strtotime('2010-06-02 03:04:05'), strtotime('2010-06-02 03:04:05')),
  1044. );
  1045. foreach ($data as $row) {
  1046. $query->values(array_combine($fields, $row));
  1047. }
  1048. $query->execute();
  1049. }
  1050. function migrate_example_wine_data_comment_updates() {
  1051. $fields = array('commentid', 'subject');
  1052. $query = db_insert('migrate_example_wine_comment_updates')
  1053. ->fields($fields);
  1054. $data = array(
  1055. array(1, 'I am first'),
  1056. array(2, 'I am second'),
  1057. array(3, 'I am parent'),
  1058. array(4, ''),
  1059. array(5, 'I am Spartacus'),
  1060. );
  1061. foreach ($data as $row) {
  1062. $query->values(array_combine($fields, $row));
  1063. }
  1064. $query->execute();
  1065. }
  1066. function migrate_example_wine_data_categories() {
  1067. $fields = array('categoryid', 'type', 'name', 'category_parent', 'details', 'ordering');
  1068. $query = db_insert('migrate_example_wine_categories')
  1069. ->fields($fields);
  1070. $data = array(
  1071. array(1, 'variety', 'White wine', NULL, 'White wines are generally simpler and sweeter than red', 3),
  1072. array(3, 'variety', 'Red wine', NULL, 'Red wines are generally more complex and "dry" than white', 1),
  1073. array(8, 'variety', 'Riesling', 1, 'Associated with Germany', 2),
  1074. array(9, 'variety', 'Chardonnay', 1, 'One of the most popular whites', 1),
  1075. array(13, 'variety', 'Merlot', 3, 'Very drinkable', 4),
  1076. array(14, 'variety', 'Syrah', 3, 'A.k.a. shiraz', -3),
  1077. array(25, 'variety', 'Cabernet Sauvignon', 3, 'A basic', -5),
  1078. array(26, 'variety', "Nero d'Avola", 3, 'Sicilian specialty', 2),
  1079. array(2, 'region', 'Italy', NULL, 'Largest producer of wine', 5),
  1080. array(11, 'region', 'Tuscany', 2, NULL, 2),
  1081. array(18, 'region', 'Chianti', 11, NULL, -1),
  1082. array(19, 'region', 'Elba', 11, NULL, 5),
  1083. array(4, 'region', 'France', NULL, 'C\'est bon', 6),
  1084. array(5, 'region', 'Bordeaux', 4, NULL, 1),
  1085. array(6, 'region', 'Barsac', 5, NULL, 3),
  1086. array(7, 'region', 'Pomerol', 5, NULL, 2),
  1087. array(16, 'region', 'Chile', NULL, NULL, 3),
  1088. array(17, 'region', 'Colchagua Valley', 16, NULL, 1),
  1089. array(20, 'region', 'California', NULL, NULL, 5),
  1090. array(21, 'region', 'Redwood Valley', 20, NULL, 1),
  1091. array(10, 'best_with', 'Beef', NULL, NULL, 5),
  1092. array(12, 'best_with', 'Pork', NULL, NULL, -3),
  1093. array(15, 'best_with', 'Chicken', NULL, NULL, -5),
  1094. );
  1095. foreach ($data as $row) {
  1096. $query->values(array_combine($fields, $row));
  1097. }
  1098. $query->execute();
  1099. }
  1100. function migrate_example_wine_data_vintages() {
  1101. $fields = array('wineid', 'vintage');
  1102. $query = db_insert('migrate_example_wine_vintages')
  1103. ->fields($fields);
  1104. $data = array(
  1105. array(1, 2006),
  1106. array(1, 2007),
  1107. array(2, 2001),
  1108. );
  1109. foreach ($data as $row) {
  1110. $query->values(array_combine($fields, $row));
  1111. }
  1112. $query->execute();
  1113. }
  1114. function migrate_example_wine_data_variety_updates() {
  1115. $fields = array('categoryid', 'details');
  1116. $query = db_insert('migrate_example_wine_variety_updates')
  1117. ->fields($fields);
  1118. $data = array(
  1119. array(1, 'White wines are simpler and sweeter than red'),
  1120. array(3, 'Red wines are generally more complex and dry than white'),
  1121. array(8, 'Usually associated with Germany'),
  1122. array(9, NULL),
  1123. array(13, 'Common, very drinakable'),
  1124. array(14, 'AKA Shiraz'),
  1125. array(25, 'Basic'),
  1126. array(26, 'A specialty of Sicily'),
  1127. );
  1128. foreach ($data as $row) {
  1129. $query->values(array_combine($fields, $row));
  1130. }
  1131. $query->execute();
  1132. }
  1133. function migrate_example_wine_data_category_wine() {
  1134. $fields = array('wineid', 'categoryid');
  1135. $query = db_insert('migrate_example_wine_category_wine')
  1136. ->fields($fields);
  1137. $data = array(
  1138. array(1, 12),
  1139. array(1, 15),
  1140. array(2, 10),
  1141. );
  1142. foreach ($data as $row) {
  1143. $query->values(array_combine($fields, $row));
  1144. }
  1145. $query->execute();
  1146. }
  1147. function migrate_example_wine_data_category_producer() {
  1148. $fields = array('producerid', 'categoryid');
  1149. $query = db_insert('migrate_example_wine_category_producer')
  1150. ->fields($fields);
  1151. $data = array(
  1152. array(1, 17),
  1153. );
  1154. foreach ($data as $row) {
  1155. $query->values(array_combine($fields, $row));
  1156. }
  1157. $query->execute();
  1158. }
  1159. function migrate_example_wine_data_files() {
  1160. $fields = array('imageid', 'url', 'image_alt', 'image_title', 'wineid');
  1161. $query = db_insert('migrate_example_wine_files')
  1162. ->fields($fields);
  1163. $data = array(
  1164. array(1, 'http://drupal.org/sites/all/modules/drupalorg/drupalorg/images/association-individual.png', NULL, NULL, NULL),
  1165. array(2, 'http://cyrve.com/files/penguin.jpeg', 'Penguin alt', 'Penguin title', 1),
  1166. array(3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2),
  1167. array(4, 'http://cyrve.com/files/boutisse_0.jpeg', 'Boutisse alt', 'Boutisse title', 2),
  1168. );
  1169. foreach ($data as $row) {
  1170. $query->values(array_combine($fields, $row));
  1171. }
  1172. $query->execute();
  1173. }
  1174. function migrate_example_wine_data_blobs() {
  1175. $blob = file_get_contents('misc/druplicon.png');
  1176. $fields = array('imageid', 'imageblob');
  1177. $query = db_insert('migrate_example_wine_blobs')
  1178. ->fields($fields);
  1179. $data = array(
  1180. array(1, $blob),
  1181. );
  1182. foreach ($data as $row) {
  1183. $query->values(array_combine($fields, $row));
  1184. }
  1185. $query->execute();
  1186. }
  1187. function migrate_example_wine_data_table_source() {
  1188. $fields = array('fooid', 'field1', 'field2');
  1189. $query = db_insert('migrate_example_wine_table_source')
  1190. ->fields($fields);
  1191. $data = array(
  1192. array(3, 'Some sample data', 58),
  1193. array(15, 'Whatever', 2),
  1194. array(646, 'More sample data', 34989),
  1195. );
  1196. foreach ($data as $row) {
  1197. $query->values(array_combine($fields, $row));
  1198. }
  1199. $query->execute();
  1200. }