webform.install 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398
  1. <?php
  2. /**
  3. * @file
  4. * Webform module install/schema hooks.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function webform_schema() {
  10. $schema = array();
  11. $schema['webform'] = array(
  12. 'description' => 'Table for storing additional properties for webform nodes.',
  13. 'fields' => array(
  14. 'nid' => array(
  15. 'description' => 'The node identifier of a webform.',
  16. 'type' => 'int',
  17. 'unsigned' => TRUE,
  18. 'not null' => TRUE,
  19. ),
  20. 'next_serial' => array(
  21. 'description' => 'The serial number to give to the next submission to this webform.',
  22. 'type' => 'int',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. 'default' => 1,
  26. ),
  27. 'confirmation' => array(
  28. 'description' => 'The confirmation message or URL displayed to the user after submitting a form.',
  29. 'type' => 'text',
  30. 'not null' => TRUE,
  31. ),
  32. 'confirmation_format' => array(
  33. 'description' => 'The {filter_format}.format of the confirmation message.',
  34. 'type' => 'varchar',
  35. 'length' => 255,
  36. 'not null' => FALSE,
  37. ),
  38. 'redirect_url' => array(
  39. 'description' => 'The URL a user is redirected to after submitting a form.',
  40. 'type' => 'varchar',
  41. 'length' => 2048,
  42. 'default' => '<confirmation>',
  43. ),
  44. 'status' => array(
  45. 'description' => 'Boolean value of a webform for open (1) or closed (0).',
  46. 'type' => 'int',
  47. 'size' => 'tiny',
  48. 'not null' => TRUE,
  49. 'default' => 1,
  50. ),
  51. 'block' => array(
  52. 'description' => 'Boolean value for whether this form be available as a block.',
  53. 'type' => 'int',
  54. 'size' => 'tiny',
  55. 'not null' => TRUE,
  56. 'default' => 0,
  57. ),
  58. 'allow_draft' => array(
  59. 'description' => 'Boolean value for whether submissions to this form be saved as a draft.',
  60. 'type' => 'int',
  61. 'size' => 'tiny',
  62. 'not null' => TRUE,
  63. 'default' => 0,
  64. ),
  65. 'auto_save' => array(
  66. 'description' => 'Boolean value for whether submissions to this form should be auto-saved between pages.',
  67. 'type' => 'int',
  68. 'size' => 'tiny',
  69. 'not null' => TRUE,
  70. 'default' => 0,
  71. ),
  72. 'submit_notice' => array(
  73. 'description' => 'Boolean value for whether to show or hide the previous submissions notification.',
  74. 'type' => 'int',
  75. 'size' => 'tiny',
  76. 'not null' => TRUE,
  77. 'default' => 1,
  78. ),
  79. 'confidential' => array(
  80. 'description' => 'Boolean value for whether to anonymize submissions.',
  81. 'type' => 'int',
  82. 'size' => 'tiny',
  83. 'not null' => TRUE,
  84. 'default' => 0,
  85. ),
  86. 'submit_text' => array(
  87. 'description' => 'The title of the submit button on the form.',
  88. 'type' => 'varchar',
  89. 'length' => 255,
  90. ),
  91. 'submit_limit' => array(
  92. 'description' => 'The number of submissions a single user is allowed to submit within an interval. -1 is unlimited.',
  93. 'type' => 'int',
  94. 'size' => 'tiny',
  95. 'not null' => TRUE,
  96. 'default' => -1,
  97. ),
  98. 'submit_interval' => array(
  99. 'description' => 'The amount of time in seconds that must pass before a user can submit another submission within the set limit.',
  100. 'type' => 'int',
  101. 'not null' => TRUE,
  102. 'default' => -1,
  103. ),
  104. 'total_submit_limit' => array(
  105. 'description' => 'The total number of submissions allowed within an interval. -1 is unlimited.',
  106. 'type' => 'int',
  107. 'not null' => TRUE,
  108. 'default' => -1,
  109. ),
  110. 'total_submit_interval' => array(
  111. 'description' => 'The amount of time in seconds that must pass before another submission can be submitted within the set limit.',
  112. 'type' => 'int',
  113. 'not null' => TRUE,
  114. 'default' => -1,
  115. ),
  116. 'progressbar_bar' => array(
  117. 'description' => 'Boolean value indicating if the bar should be shown as part of the progress bar.',
  118. 'type' => 'int',
  119. 'size' => 'tiny',
  120. 'not null' => TRUE,
  121. 'default' => 0,
  122. ),
  123. 'progressbar_page_number' => array(
  124. 'description' => 'Boolean value indicating if the page number should be shown as part of the progress bar.',
  125. 'type' => 'int',
  126. 'size' => 'tiny',
  127. 'not null' => TRUE,
  128. 'default' => 0,
  129. ),
  130. 'progressbar_percent' => array(
  131. 'description' => 'Boolean value indicating if the percentage complete should be shown as part of the progress bar.',
  132. 'type' => 'int',
  133. 'size' => 'tiny',
  134. 'not null' => TRUE,
  135. 'default' => 0,
  136. ),
  137. 'progressbar_pagebreak_labels' => array(
  138. 'description' => 'Boolean value indicating if the pagebreak labels should be included as part of the progress bar.',
  139. 'type' => 'int',
  140. 'size' => 'tiny',
  141. 'not null' => TRUE,
  142. 'default' => 0,
  143. ),
  144. 'progressbar_include_confirmation' => array(
  145. 'description' => 'Boolean value indicating if the confirmation page should count as a page in the progress bar.',
  146. 'type' => 'int',
  147. 'size' => 'tiny',
  148. 'not null' => TRUE,
  149. 'default' => 0,
  150. ),
  151. 'progressbar_label_first' => array(
  152. 'description' => 'Label for the first page of the progress bar.',
  153. 'type' => 'varchar',
  154. 'length' => 255,
  155. ),
  156. 'progressbar_label_confirmation' => array(
  157. 'description' => 'Label for the last page of the progress bar.',
  158. 'type' => 'varchar',
  159. 'length' => 255,
  160. ),
  161. 'preview' => array(
  162. 'description' => 'Boolean value indicating if this form includes a page for previewing the submission.',
  163. 'type' => 'int',
  164. 'size' => 'tiny',
  165. 'not null' => TRUE,
  166. 'default' => 0,
  167. ),
  168. 'preview_next_button_label' => array(
  169. 'description' => 'The text for the button that will proceed to the preview page.',
  170. 'type' => 'varchar',
  171. 'length' => 255,
  172. ),
  173. 'preview_prev_button_label' => array(
  174. 'description' => 'The text for the button to go backwards from the preview page.',
  175. 'type' => 'varchar',
  176. 'length' => 255,
  177. ),
  178. 'preview_title' => array(
  179. 'description' => 'The title of the preview page, as used by the progress bar.',
  180. 'type' => 'varchar',
  181. 'length' => 255,
  182. ),
  183. 'preview_message' => array(
  184. 'description' => 'Text shown on the preview page of the form.',
  185. 'type' => 'text',
  186. 'not null' => TRUE,
  187. ),
  188. 'preview_message_format' => array(
  189. 'description' => 'The {filter_format}.format of the preview page message.',
  190. 'type' => 'varchar',
  191. 'length' => 255,
  192. ),
  193. 'preview_excluded_components' => array(
  194. 'description' => 'Comma-separated list of component IDs that should not be included in this form\'s confirmation page.',
  195. 'type' => 'text',
  196. 'not null' => TRUE,
  197. ),
  198. ),
  199. 'primary key' => array('nid'),
  200. );
  201. $schema['webform_component'] = array(
  202. 'description' => 'Stores information about components for webform nodes.',
  203. 'fields' => array(
  204. 'nid' => array(
  205. 'description' => 'The node identifier of a webform.',
  206. 'type' => 'int',
  207. 'unsigned' => TRUE,
  208. 'not null' => TRUE,
  209. 'default' => 0,
  210. ),
  211. 'cid' => array(
  212. 'description' => 'The identifier for this component within this node, starts at 0 for each node.',
  213. 'type' => 'int',
  214. 'size' => 'small',
  215. 'unsigned' => TRUE,
  216. 'not null' => TRUE,
  217. 'default' => 0,
  218. ),
  219. 'pid' => array(
  220. 'description' => 'If this component has a parent fieldset, the cid of that component.',
  221. 'type' => 'int',
  222. 'size' => 'small',
  223. 'unsigned' => TRUE,
  224. 'not null' => TRUE,
  225. 'default' => 0,
  226. ),
  227. 'form_key' => array(
  228. 'description' => 'When the form is displayed and processed, this key can be used to reference the results.',
  229. 'type' => 'varchar',
  230. 'length' => 128,
  231. ),
  232. 'name' => array(
  233. 'description' => 'The label for this component.',
  234. 'type' => 'text',
  235. 'not null' => TRUE,
  236. ),
  237. 'type' => array(
  238. 'description' => 'The field type of this component (textfield, select, hidden, etc.).',
  239. 'type' => 'varchar',
  240. 'length' => 16,
  241. ),
  242. 'value' => array(
  243. 'description' => 'The default value of the component when displayed to the end-user.',
  244. 'type' => 'text',
  245. 'not null' => TRUE,
  246. ),
  247. 'extra' => array(
  248. 'description' => 'Additional information unique to the display or processing of this component.',
  249. 'type' => 'text',
  250. 'not null' => TRUE,
  251. ),
  252. 'required' => array(
  253. 'description' => 'Boolean flag for if this component is required.',
  254. 'type' => 'int',
  255. 'size' => 'tiny',
  256. 'not null' => TRUE,
  257. 'default' => 0,
  258. ),
  259. 'weight' => array(
  260. 'description' => 'Determines the position of this component in the form.',
  261. 'type' => 'int',
  262. 'size' => 'small',
  263. 'not null' => TRUE,
  264. 'default' => 0,
  265. ),
  266. ),
  267. 'primary key' => array('nid', 'cid'),
  268. );
  269. $schema['webform_conditional'] = array(
  270. 'description' => 'Holds information about conditional logic.',
  271. 'fields' => array(
  272. 'nid' => array(
  273. 'description' => 'The node identifier of a webform.',
  274. 'type' => 'int',
  275. 'unsigned' => TRUE,
  276. 'not null' => TRUE,
  277. 'default' => 0,
  278. ),
  279. 'rgid' => array(
  280. 'description' => 'The rule group identifier for this group of rules.',
  281. 'type' => 'int',
  282. 'size' => 'small',
  283. 'unsigned' => TRUE,
  284. 'not null' => TRUE,
  285. 'default' => 0,
  286. ),
  287. 'andor' => array(
  288. 'description' => 'Whether to AND or OR the actions in this group. All actions within the same rgid should have the same andor value.',
  289. 'type' => 'varchar',
  290. 'length' => 128,
  291. ),
  292. 'weight' => array(
  293. 'description' => 'Determines the position of this conditional compared to others.',
  294. 'type' => 'int',
  295. 'size' => 'small',
  296. 'not null' => TRUE,
  297. 'default' => 0,
  298. ),
  299. ),
  300. 'primary key' => array('nid', 'rgid'),
  301. );
  302. $schema['webform_conditional_rules'] = array(
  303. 'description' => 'Holds information about conditional logic.',
  304. 'fields' => array(
  305. 'nid' => array(
  306. 'description' => 'The node identifier of a webform.',
  307. 'type' => 'int',
  308. 'unsigned' => TRUE,
  309. 'not null' => TRUE,
  310. 'default' => 0,
  311. ),
  312. 'rgid' => array(
  313. 'description' => 'The rule group identifier for this group of rules.',
  314. 'type' => 'int',
  315. 'size' => 'small',
  316. 'unsigned' => TRUE,
  317. 'not null' => TRUE,
  318. 'default' => 0,
  319. ),
  320. 'rid' => array(
  321. 'description' => 'The rule identifier for this conditional rule.',
  322. 'type' => 'int',
  323. 'size' => 'small',
  324. 'unsigned' => TRUE,
  325. 'not null' => TRUE,
  326. 'default' => 0,
  327. ),
  328. 'source_type' => array(
  329. 'description' => 'The type of source on which the conditional is based. Currently always "component". Indicates what type of ID the "source" column contains.',
  330. 'type' => 'varchar',
  331. 'length' => 128,
  332. ),
  333. 'source' => array(
  334. 'description' => 'The component ID being used in this condition.',
  335. 'type' => 'int',
  336. 'size' => 'small',
  337. 'unsigned' => TRUE,
  338. 'not null' => TRUE,
  339. 'default' => 0,
  340. ),
  341. 'operator' => array(
  342. 'description' => 'Which operator (equal, contains, starts with, etc.) should be used for this comparison between the source and value?',
  343. 'type' => 'varchar',
  344. 'length' => 128,
  345. ),
  346. 'value' => array(
  347. 'description' => 'The value to be compared with source.',
  348. 'type' => 'text',
  349. ),
  350. ),
  351. 'primary key' => array('nid', 'rgid', 'rid'),
  352. );
  353. $schema['webform_conditional_actions'] = array(
  354. 'description' => 'Holds information about conditional actions.',
  355. 'fields' => array(
  356. 'nid' => array(
  357. 'description' => 'The node identifier of a webform.',
  358. 'type' => 'int',
  359. 'unsigned' => TRUE,
  360. 'not null' => TRUE,
  361. 'default' => 0,
  362. ),
  363. 'rgid' => array(
  364. 'description' => 'The rule group identifier for this group of rules.',
  365. 'type' => 'int',
  366. 'size' => 'small',
  367. 'unsigned' => TRUE,
  368. 'not null' => TRUE,
  369. 'default' => 0,
  370. ),
  371. 'aid' => array(
  372. 'description' => 'The rule identifier for this conditional action.',
  373. 'type' => 'int',
  374. 'size' => 'small',
  375. 'unsigned' => TRUE,
  376. 'not null' => TRUE,
  377. 'default' => 0,
  378. ),
  379. 'target_type' => array(
  380. 'description' => 'The type of target to be affected. Currently always "component". Indicates what type of ID the "target" column contains.',
  381. 'type' => 'varchar',
  382. 'length' => 128,
  383. ),
  384. 'target' => array(
  385. 'description' => 'The ID of the target to be affected. Typically a component ID.',
  386. 'type' => 'varchar',
  387. 'length' => 128,
  388. ),
  389. 'invert' => array(
  390. 'description' => 'If inverted, execute when rule(s) are false.',
  391. 'type' => 'int',
  392. 'size' => 'small',
  393. 'unsigned' => TRUE,
  394. 'not null' => TRUE,
  395. 'default' => 0,
  396. ),
  397. 'action' => array(
  398. 'description' => 'The action to be performed on the target.',
  399. 'type' => 'varchar',
  400. 'length' => 128,
  401. ),
  402. 'argument' => array(
  403. 'description' => 'Optional argument for action.',
  404. 'type' => 'text',
  405. ),
  406. ),
  407. 'primary key' => array('nid', 'rgid', 'aid'),
  408. );
  409. $schema['webform_emails'] = array(
  410. 'description' => 'Holds information regarding e-mails that should be sent upon submitting a webform',
  411. 'fields' => array(
  412. 'nid' => array(
  413. 'description' => 'The node identifier of a webform.',
  414. 'type' => 'int',
  415. 'unsigned' => TRUE,
  416. 'not null' => TRUE,
  417. 'default' => 0,
  418. ),
  419. 'eid' => array(
  420. 'description' => 'The e-mail identifier for this row\'s settings.',
  421. 'type' => 'int',
  422. 'unsigned' => TRUE,
  423. 'size' => 'small',
  424. 'not null' => TRUE,
  425. 'default' => 0,
  426. ),
  427. 'email' => array(
  428. 'description' => 'The e-mail address that will be sent to upon submission. This may be an e-mail address, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  429. 'type' => 'text',
  430. 'not null' => FALSE,
  431. ),
  432. 'subject' => array(
  433. 'description' => 'The e-mail subject that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  434. 'type' => 'text',
  435. 'not null' => FALSE,
  436. ),
  437. 'from_name' => array(
  438. 'description' => 'The e-mail "from" name that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  439. 'type' => 'text',
  440. 'not null' => FALSE,
  441. ),
  442. 'from_address' => array(
  443. 'description' => 'The e-mail "from" e-mail address that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  444. 'type' => 'text',
  445. 'not null' => FALSE,
  446. ),
  447. 'template' => array(
  448. 'description' => 'A template that will be used for the sent e-mail. This may be a string or the special key "default", which will use the template provided by the theming layer.',
  449. 'type' => 'text',
  450. 'not null' => FALSE,
  451. ),
  452. 'excluded_components' => array(
  453. 'description' => 'A list of components that will not be included in the [submission:values] token. A list of CIDs separated by commas.',
  454. 'type' => 'text',
  455. 'not null' => TRUE,
  456. ),
  457. 'html' => array(
  458. 'description' => 'Determines if the e-mail will be sent in an HTML format. Requires Mime Mail module.',
  459. 'type' => 'int',
  460. 'unsigned' => TRUE,
  461. 'size' => 'tiny',
  462. 'not null' => TRUE,
  463. 'default' => 0,
  464. ),
  465. 'attachments' => array(
  466. 'description' => 'Determines if the e-mail will include file attachments. Requires Mime Mail module.',
  467. 'type' => 'int',
  468. 'unsigned' => TRUE,
  469. 'size' => 'tiny',
  470. 'not null' => TRUE,
  471. 'default' => 0,
  472. ),
  473. 'exclude_empty' => array(
  474. 'description' => 'Determines if the e-mail will include component with an empty value.',
  475. 'type' => 'int',
  476. 'unsigned' => TRUE,
  477. 'size' => 'tiny',
  478. 'not null' => TRUE,
  479. 'default' => 0,
  480. ),
  481. 'extra' => array(
  482. 'description' => 'A serialized array of additional options for the e-mail configuration, including value mapping for the TO and FROM addresses for select lists.',
  483. 'type' => 'text',
  484. 'not null' => TRUE,
  485. ),
  486. 'status' => array(
  487. 'description' => 'Whether this email is enabled.',
  488. 'type' => 'int',
  489. 'unsigned' => TRUE,
  490. 'size' => 'tiny',
  491. 'not null' => TRUE,
  492. 'default' => 1,
  493. ),
  494. ),
  495. 'primary key' => array('nid', 'eid'),
  496. );
  497. $schema['webform_roles'] = array(
  498. 'description' => 'Holds access information regarding which roles are allowed to submit which webform nodes. Does not prevent access to the webform node entirely, use the {node_access} table for that purpose.',
  499. 'fields' => array(
  500. 'nid' => array(
  501. 'description' => 'The node identifier of a webform.',
  502. 'type' => 'int',
  503. 'unsigned' => TRUE,
  504. 'not null' => TRUE,
  505. 'default' => 0,
  506. ),
  507. 'rid' => array(
  508. 'description' => 'The role identifier.',
  509. 'type' => 'int',
  510. 'unsigned' => TRUE,
  511. 'not null' => TRUE,
  512. 'default' => 0,
  513. ),
  514. ),
  515. 'primary key' => array('nid', 'rid'),
  516. );
  517. $schema['webform_submissions'] = array(
  518. 'description' => 'Holds general information about submissions outside of field values.',
  519. 'fields' => array(
  520. 'sid' => array(
  521. 'description' => 'The unique identifier for this submission.',
  522. 'type' => 'serial',
  523. 'unsigned' => TRUE,
  524. 'not null' => TRUE,
  525. ),
  526. 'nid' => array(
  527. 'description' => 'The node identifier of a webform.',
  528. 'type' => 'int',
  529. 'unsigned' => TRUE,
  530. 'not null' => TRUE,
  531. 'default' => 0,
  532. ),
  533. 'serial' => array(
  534. 'description' => 'The serial number of this submission.',
  535. 'type' => 'int',
  536. 'unsigned' => TRUE,
  537. 'not null' => TRUE,
  538. ),
  539. 'uid' => array(
  540. 'description' => 'The id of the user that completed this submission.',
  541. 'type' => 'int',
  542. 'unsigned' => TRUE,
  543. 'not null' => TRUE,
  544. 'default' => 0,
  545. ),
  546. 'is_draft' => array(
  547. 'description' => 'Is this a draft of the submission?',
  548. 'type' => 'int',
  549. 'size' => 'tiny',
  550. 'not null' => TRUE,
  551. 'default' => 0,
  552. ),
  553. 'highest_valid_page' => array(
  554. 'description' => 'For drafts, the highest validated page number.',
  555. 'type' => 'int',
  556. 'size' => 'small',
  557. 'not null' => TRUE,
  558. 'default' => 0,
  559. ),
  560. 'submitted' => array(
  561. 'description' => 'Timestamp when the form was first saved as draft or submitted.',
  562. 'type' => 'int',
  563. 'not null' => TRUE,
  564. 'default' => 0,
  565. ),
  566. 'completed' => array(
  567. 'description' => 'Timestamp when the form was submitted as complete (not draft).',
  568. 'type' => 'int',
  569. 'not null' => TRUE,
  570. 'default' => 0,
  571. ),
  572. 'modified' => array(
  573. 'description' => 'Timestamp when the form was last saved (complete or draft).',
  574. 'type' => 'int',
  575. 'not null' => TRUE,
  576. 'default' => 0,
  577. ),
  578. 'remote_addr' => array(
  579. 'description' => 'The IP address of the user that submitted the form.',
  580. 'type' => 'varchar',
  581. 'length' => 128,
  582. ),
  583. ),
  584. 'primary key' => array('sid'),
  585. 'unique keys' => array(
  586. 'sid_nid' => array('sid', 'nid'),
  587. 'nid_serial' => array('nid', 'serial'),
  588. ),
  589. 'indexes' => array(
  590. 'nid_uid_sid' => array('nid', 'uid', 'sid'),
  591. 'nid_sid' => array('nid', 'sid'),
  592. ),
  593. );
  594. $schema['webform_submitted_data'] = array(
  595. 'description' => 'Stores all submitted field data for webform submissions.',
  596. 'fields' => array(
  597. 'nid' => array(
  598. 'description' => 'The node identifier of a webform.',
  599. 'type' => 'int',
  600. 'unsigned' => TRUE,
  601. 'not null' => TRUE,
  602. 'default' => 0,
  603. ),
  604. 'sid' => array(
  605. 'description' => 'The unique identifier for this submission.',
  606. 'type' => 'int',
  607. 'unsigned' => TRUE,
  608. 'not null' => TRUE,
  609. 'default' => 0,
  610. ),
  611. 'cid' => array(
  612. 'description' => 'The identifier for this component within this node, starts at 0 for each node.',
  613. 'type' => 'int',
  614. 'size' => 'small',
  615. 'unsigned' => TRUE,
  616. 'not null' => TRUE,
  617. 'default' => 0,
  618. ),
  619. 'no' => array(
  620. 'description' => 'Usually this value is 0, but if a field has multiple values (such as a time or date), it may require multiple rows in the database.',
  621. 'type' => 'varchar',
  622. 'length' => 128,
  623. 'not null' => TRUE,
  624. 'default' => '0',
  625. ),
  626. 'data' => array(
  627. 'description' => 'The submitted value of this field, may be serialized for some components.',
  628. 'type' => 'text',
  629. 'size' => 'medium',
  630. 'not null' => TRUE,
  631. ),
  632. ),
  633. 'primary key' => array('nid', 'sid', 'cid', 'no'),
  634. 'indexes' => array(
  635. 'nid' => array('nid'),
  636. 'sid_nid' => array('sid', 'nid'),
  637. // For all but MS SQL Server databases, 64-character index is created on
  638. // the data column after the schema is installed.
  639. ),
  640. );
  641. $schema['webform_last_download'] = array(
  642. 'description' => 'Stores last submission number per user download.',
  643. 'fields' => array(
  644. 'nid' => array(
  645. 'description' => 'The node identifier of a webform.',
  646. 'type' => 'int',
  647. 'unsigned' => TRUE,
  648. 'not null' => TRUE,
  649. 'default' => 0,
  650. ),
  651. 'uid' => array(
  652. 'description' => 'The user identifier.',
  653. 'type' => 'int',
  654. 'unsigned' => TRUE,
  655. 'not null' => TRUE,
  656. 'default' => 0,
  657. ),
  658. 'sid' => array(
  659. 'description' => 'The last downloaded submission number.',
  660. 'type' => 'int',
  661. 'unsigned' => TRUE,
  662. 'not null' => TRUE,
  663. 'default' => 0,
  664. ),
  665. 'requested' => array(
  666. 'description' => 'Timestamp of last download request.',
  667. 'type' => 'int',
  668. 'unsigned' => TRUE,
  669. 'not null' => TRUE,
  670. 'default' => 0,
  671. ),
  672. ),
  673. 'primary key' => array('nid', 'uid'),
  674. );
  675. return $schema;
  676. }
  677. /**
  678. * Implements hook_requirements().
  679. */
  680. function webform_requirements($phase) {
  681. $requirements = array();
  682. $t = get_t();
  683. // Ensure cURL exists if SimpleTest hasn't checked it already.
  684. if (!class_exists('ZipArchive')) {
  685. $requirements['webform_zip'] = array(
  686. 'title' => $t('Zip archive support'),
  687. 'value' => $t('Missing'),
  688. 'severity' => REQUIREMENT_INFO,
  689. 'description' => $t('PHP does not have the zip archive extension available. Webform module requires zip support for exporting submissions to Microsoft Excel.'),
  690. );
  691. }
  692. // Though the .info file specifies PHP version as well, this will prevent
  693. // users from upgrading from 3.x if their PHP version is too old.
  694. if (version_compare(phpversion(), '5.3') < 0) {
  695. $requirements['webform_php'] = array(
  696. 'title' => $t('Webform PHP requirement'),
  697. 'value' => phpversion(),
  698. 'severity' => REQUIREMENT_ERROR,
  699. 'description' => $t('Webform requires PHP 5.3 or higher.'),
  700. );
  701. }
  702. // Ensure that views is enabled as it is a new .info requirement starting
  703. // with version 7.x-4.0rc1. On installation, the .info file is sufficient to
  704. // cause the dependencies to be installed. On update, update.php will
  705. // respect this hook_requirements implementation, but as of drush 6.3.0 and
  706. // drush 7.0.0, drush updatedb will not. See:
  707. // https://github.com/drush-ops/drush/issues/1427
  708. if ($phase != 'install' && !module_exists('views')) {
  709. $requirements['webform_views'] = array(
  710. 'title' => $t('Webform Views requirement'),
  711. 'value' => $t('Missing'),
  712. 'severity' => REQUIREMENT_ERROR,
  713. 'description' => $t('Webform requires Views, which is not installed and enabled.'),
  714. );
  715. }
  716. return $requirements;
  717. }
  718. /**
  719. * Implements hook_install().
  720. */
  721. function webform_install() {
  722. module_load_include('inc', 'node', 'content_types');
  723. db_update('system')
  724. ->condition('name', 'webform')
  725. ->condition('type', 'module')
  726. ->fields(array('weight' => -1))
  727. ->execute();
  728. // Optionally create the default webform type.
  729. if (variable_get('webform_install_create_content_type', TRUE)) {
  730. $webform_type = array(
  731. 'type' => 'webform',
  732. 'name' => st('Webform'),
  733. 'base' => 'node_content',
  734. 'description' => st('Create a new form or questionnaire accessible to users. Submission results and statistics are recorded and accessible to privileged users.'),
  735. 'custom' => TRUE,
  736. 'modified' => TRUE,
  737. 'locked' => FALSE,
  738. );
  739. $webform_type = node_type_set_defaults($webform_type);
  740. node_type_save($webform_type);
  741. // Enable webform components by default on Webform nodes.
  742. variable_set('webform_node_webform', TRUE);
  743. // Now that a webform node type has been created, reset the cache of the
  744. // node types that support webforms. This is needed for tests which will
  745. // create nodes in the same execution.
  746. drupal_static_reset('webform_node_types');
  747. if (variable_get('webform_install_add_body_field', FALSE)) {
  748. node_add_body_field($webform_type);
  749. }
  750. // Disable comments by default on Webform nodes.
  751. variable_set('comment_webform', '0');
  752. }
  753. else {
  754. variable_set('webform_node_types_primary', array());
  755. }
  756. // Note: MS SQL Server does not support size-limited indexes and the column
  757. // type (text) is too big to fit inside index size limits.
  758. if (!db_index_exists('webform_submitted_data', 'data') && db_driver() != 'sqlsrv') {
  759. db_add_index('webform_submitted_data', 'data', array(array('data', 64)));
  760. }
  761. }
  762. /**
  763. * Implements hook_uninstall().
  764. */
  765. function webform_uninstall() {
  766. // Unset webform variables.
  767. variable_del('webform_blocks');
  768. variable_del('webform_tracking_mode');
  769. variable_del('webform_allowed_tags');
  770. variable_del('webform_email_address_format');
  771. variable_del('webform_email_address_individual');
  772. variable_del('webform_default_from_name');
  773. variable_del('webform_default_from_address');
  774. variable_del('webform_default_subject');
  775. variable_del('webform_email_replyto');
  776. variable_del('webform_email_html_capable');
  777. variable_del('webform_default_format');
  778. variable_del('webform_format_override');
  779. variable_del('webform_email_select_max');
  780. variable_del('webform_fieldset_wrap');
  781. variable_del('webform_node_types_primary');
  782. variable_del('webform_date_type');
  783. variable_del('webform_export_format');
  784. variable_del('webform_csv_delimiter');
  785. variable_del('webform_csv_line_ending');
  786. variable_del('webform_export_wordwrap');
  787. variable_del('webform_excel_legacy_exporter');
  788. variable_del('webform_progressbar_style');
  789. variable_del('webform_progressbar_label_first');
  790. variable_del('webform_progressbar_label_confirmation');
  791. variable_del('webform_table');
  792. variable_del('webform_submission_access_control');
  793. variable_del('webform_token_access');
  794. variable_del('webform_update_batch_size');
  795. variable_del('webform_disabled_components');
  796. foreach (node_type_get_names() as $type => $name) {
  797. variable_del('webform_node_' . $type);
  798. }
  799. $component_list = array();
  800. $path = drupal_get_path('module', 'webform') . '/components';
  801. $files = file_scan_directory($path, '/^.*\.inc$/');
  802. foreach ($files as $filename => $file) {
  803. variable_del('webform_enable_' . $file->name, 1);
  804. }
  805. // Delete uploaded files.
  806. $filepath = file_build_uri('webform');
  807. file_unmanaged_delete_recursive($filepath);
  808. // Delete the content type "webform" if:
  809. // 1. there are no existing nodes of type webform and
  810. // 2. no additional fields have been defined for node type webform, beyond the
  811. // default body field.
  812. $query = new EntityFieldQuery();
  813. $results = $query->entityCondition('entity_type', 'node')
  814. ->entityCondition('bundle', 'webform')
  815. ->range(0, 1)
  816. ->execute();
  817. $instances = field_info_instances('node', 'webform');
  818. unset($instances['body']);
  819. if (!$results && !$instances) {
  820. node_type_delete('webform');
  821. drupal_flush_all_caches();
  822. }
  823. }
  824. /**
  825. * Implements hook_update_dependencies().
  826. */
  827. function webform_update_dependencies() {
  828. // Create the {filter_format} table before trying to use it.
  829. $dependencies['webform'][7301] = array(
  830. 'filter' => 7000,
  831. );
  832. // Create the {file_managed} table before trying to use it.
  833. $dependencies['webform'][7319] = array(
  834. 'system' => 7034,
  835. );
  836. // Create the {file_usage} table before trying to use it.
  837. $dependencies['webform'][7320] = array(
  838. 'system' => 7059,
  839. );
  840. if (module_exists('rules')) {
  841. // Ensure rules tables and fields exist before trying to use it.
  842. $dependencies['webform'][7420] = array(
  843. 'rules' => 7213,
  844. );
  845. }
  846. return $dependencies;
  847. }
  848. /**
  849. * Set the minimum upgrade version.
  850. *
  851. * Currently you cannot upgrade from 2.x in Drupal 6 to 3.x in Drupal 7. However
  852. * there are no database changes between the 3.x versions, so no update is
  853. * needed at all to move from 3.x in Drupal 6 to Drupal 7.
  854. */
  855. function webform_update_last_removed() {
  856. return 6313;
  857. }
  858. /**
  859. * Allow the confirmation format column to have a NULL value.
  860. */
  861. function webform_update_7301() {
  862. // These changes are modeled after user_update_7010().
  863. db_change_field('webform', 'confirmation_format', 'confirmation_format', array(
  864. 'description' => 'The {filter_format}.format of the confirmation message.',
  865. 'type' => 'int',
  866. 'unsigned' => TRUE,
  867. 'not null' => FALSE,
  868. ));
  869. db_update('webform')
  870. ->fields(array('confirmation_format' => NULL))
  871. ->condition('confirmation', '')
  872. ->condition('confirmation_format', 0)
  873. ->execute();
  874. $existing_formats = db_query("SELECT format FROM {filter_format}")->fetchCol();
  875. $default_format = variable_get('filter_default_format', 1);
  876. // Since Webform may be updated separately from Drupal core, not all format
  877. // names may be numbers when running this update.
  878. $numeric_formats = array();
  879. foreach ($existing_formats as $format_name) {
  880. if (is_numeric($format_name)) {
  881. $numeric_formats[] = (int) $format_name;
  882. }
  883. }
  884. $query = db_update('webform')
  885. ->fields(array('confirmation_format' => $default_format))
  886. ->isNotNull('confirmation_format');
  887. if (!empty($numeric_formats)) {
  888. $query->condition('confirmation_format', $numeric_formats, 'NOT IN');
  889. }
  890. $query->execute();
  891. }
  892. /**
  893. * Add columns for e-mail HTML and attachment settings.
  894. */
  895. function webform_update_7302() {
  896. if (!db_field_exists('webform_emails', 'html')) {
  897. db_add_field('webform_emails', 'html', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'default' => 0, 'not null' => TRUE));
  898. db_add_field('webform_emails', 'attachments', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'default' => 0, 'not null' => TRUE));
  899. }
  900. }
  901. /**
  902. * Set the default for the "submit_notice" column to 1.
  903. */
  904. function webform_update_7303() {
  905. db_change_field('webform', 'submit_notice', 'submit_notice', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1));
  906. }
  907. /**
  908. * Add field for block feature and redirection setting.
  909. */
  910. function webform_update_7304() {
  911. if (!db_field_exists('webform', 'block')) {
  912. db_add_field('webform', 'block', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
  913. db_change_field('webform', 'redirect_url', 'redirect_url', array('type' => 'varchar', 'length' => 255, 'default' => '<confirmation>'));
  914. db_update('webform')
  915. ->fields(array('redirect_url' => 'confirmation'))
  916. ->condition('redirect_url', '')
  917. ->execute();
  918. }
  919. }
  920. /**
  921. * Set additional_validate and additional_submit columns to allow NULL.
  922. */
  923. function webform_update_7305() {
  924. if (db_field_exists('webform', 'additional_validate')) {
  925. db_change_field('webform', 'additional_validate', 'additional_validate', array('type' => 'text', 'not null' => FALSE));
  926. db_change_field('webform', 'additional_submit', 'additional_submit', array('type' => 'text', 'not null' => FALSE));
  927. }
  928. }
  929. /**
  930. * Add column for webform status (open or closed).
  931. */
  932. function webform_update_7306() {
  933. if (!db_field_exists('webform', 'status')) {
  934. db_add_field('webform', 'status', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1));
  935. }
  936. }
  937. /**
  938. * Update the confirmation_format column for default text format changes.
  939. */
  940. function webform_update_7307() {
  941. // Update removed and moved to webform_update_7301().
  942. // See http://drupal.org/node/976102.
  943. }
  944. /**
  945. * Update the confirmation_format column to allow it to store strings.
  946. */
  947. function webform_update_7308() {
  948. db_change_field('webform', 'confirmation_format', 'confirmation_format', array(
  949. 'description' => 'The {filter_format}.format of the confirmation message.',
  950. 'type' => 'varchar',
  951. 'length' => 255,
  952. 'not null' => FALSE,
  953. ));
  954. }
  955. /**
  956. * Add the ability to auto-save as draft between pages.
  957. */
  958. function webform_update_7309() {
  959. if (!db_field_exists('webform', 'auto_save')) {
  960. db_add_field('webform', 'auto_save', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
  961. }
  962. }
  963. /**
  964. * Remove orphaned and unnecessary rows in the webform table.
  965. */
  966. function webform_update_7310() {
  967. $result = db_query("SELECT nid FROM {webform} WHERE
  968. nid NOT IN
  969. (SELECT DISTINCT(w1.nid) FROM {webform} w1 INNER JOIN {webform_component} wc ON w1.nid = wc.nid)
  970. AND nid NOT IN
  971. (SELECT w2.nid FROM {webform} w2 INNER JOIN {node} n ON w2.nid = n.nid WHERE n.type = 'webform')"
  972. );
  973. $empty_nids = array();
  974. foreach ($result as $row) {
  975. $empty_nids[] = $row->nid;
  976. }
  977. if (!empty($empty_nids)) {
  978. db_delete('webform')->condition('nid', $empty_nids, 'IN')->execute();
  979. }
  980. }
  981. /**
  982. * Add an index for nid_uid_sid to webform_submissions.
  983. */
  984. function webform_update_7311() {
  985. if (!db_index_exists('webform_submissions', 'nid_uid_sid')) {
  986. db_add_index('webform_submissions', 'nid_uid_sid', array('nid', 'uid', 'sid'));
  987. }
  988. }
  989. /**
  990. * Remove unused Webform variables.
  991. */
  992. function webform_update_7312() {
  993. variable_del('node_types');
  994. variable_del('components');
  995. }
  996. /**
  997. * Convert the Date component start and end year options to start and end date.
  998. */
  999. function webform_update_7313() {
  1000. $result = db_select('webform_component', 'wc', array('fetch' => PDO::FETCH_ASSOC))
  1001. ->fields('wc')
  1002. ->condition('type', 'date')
  1003. ->execute();
  1004. foreach ($result as $component) {
  1005. $component['extra'] = unserialize($component['extra']);
  1006. if (!isset($component['extra']['start_date']) && !isset($component['end_date'])) {
  1007. foreach (array('year_start' => 'start_date', 'year_end' => 'end_date') as $key => $replacement) {
  1008. $value = isset($component['extra'][$key]) ? trim($component['extra'][$key]) : '';
  1009. // Relative years.
  1010. if (preg_match('/[-+][ ]*[0-9]+/', $value)) {
  1011. $component['extra'][$replacement] = ($value == 1) ? ($value . ' year') : ($value . ' years');
  1012. }
  1013. // Absolute years.
  1014. elseif (is_numeric($value)) {
  1015. $component['extra'][$replacement] = 'Dec 31 ' . $value;
  1016. }
  1017. unset($component['extra'][$key]);
  1018. }
  1019. $component['extra'] = serialize($component['extra']);
  1020. drupal_write_record('webform_component', $component, array('nid', 'cid'));
  1021. }
  1022. }
  1023. }
  1024. /**
  1025. * Add webform_last_download table to store last downloaded sid per user.
  1026. */
  1027. function webform_update_7314() {
  1028. // Safety check to prevent recreating the webform_last_download table.
  1029. if (db_table_exists('webform_last_download')) {
  1030. return;
  1031. }
  1032. $schema['webform_last_download'] = array(
  1033. 'description' => 'Stores last submission number per user download.',
  1034. 'fields' => array(
  1035. 'nid' => array(
  1036. 'description' => 'The node identifier of a webform.',
  1037. 'type' => 'int',
  1038. 'unsigned' => TRUE,
  1039. 'not null' => TRUE,
  1040. 'default' => 0,
  1041. ),
  1042. 'uid' => array(
  1043. 'description' => 'The user identifier.',
  1044. 'type' => 'int',
  1045. 'unsigned' => TRUE,
  1046. 'not null' => TRUE,
  1047. 'default' => 0,
  1048. ),
  1049. 'sid' => array(
  1050. 'description' => 'The last downloaded submission number.',
  1051. 'type' => 'int',
  1052. 'unsigned' => TRUE,
  1053. 'not null' => TRUE,
  1054. 'default' => 0,
  1055. ),
  1056. ),
  1057. 'primary key' => array('nid', 'uid'),
  1058. );
  1059. db_create_table('webform_last_download', $schema['webform_last_download']);
  1060. }
  1061. /**
  1062. * Add column for timestamp of last requested CSV download.
  1063. */
  1064. function webform_update_7315() {
  1065. if (!db_field_exists('webform_last_download', 'requested')) {
  1066. db_add_field('webform_last_download', 'requested', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  1067. }
  1068. }
  1069. /**
  1070. * Add additional columns for total submission limit.
  1071. */
  1072. function webform_update_7316() {
  1073. if (!db_field_exists('webform', 'total_submit_limit')) {
  1074. db_add_field('webform', 'total_submit_limit', array('type' => 'int', 'not null' => TRUE, 'default' => -1));
  1075. }
  1076. if (!db_field_exists('webform', 'total_submit_interval')) {
  1077. db_add_field('webform', 'total_submit_interval', array('type' => 'int', 'not null' => TRUE, 'default' => -1));
  1078. }
  1079. }
  1080. /**
  1081. * Add an index for 'nid_sid' to webform_submissions.
  1082. */
  1083. function webform_update_7317() {
  1084. // Even though we already have an index 'nid_uid_sid', adding the index for
  1085. // 'nid_sid' saves us a tablesort on the node/x/webform-results page.
  1086. if (!db_index_exists('webform_submissions', 'nid_sid')) {
  1087. db_add_index('webform_submissions', 'nid_sid', array('nid', 'sid'));
  1088. }
  1089. }
  1090. /**
  1091. * Upgrade file components to support the new AJAX-upload element.
  1092. */
  1093. function webform_update_7318() {
  1094. $result = db_select('webform_component', 'wc', array('fetch' => PDO::FETCH_ASSOC))
  1095. ->fields('wc')
  1096. ->condition('type', 'file')
  1097. ->execute();
  1098. foreach ($result as $component) {
  1099. $component['extra'] = unserialize($component['extra']);
  1100. if (!isset($component['extra']['directory'])) {
  1101. $component['extra']['directory'] = $component['extra']['savelocation'];
  1102. $component['extra']['scheme'] = file_default_scheme();
  1103. $component['extra']['filtering']['size'] = $component['extra']['filtering']['size'] . ' KB';
  1104. unset($component['extra']['savelocation']);
  1105. $component['extra'] = serialize($component['extra']);
  1106. drupal_write_record('webform_component', $component, array('nid', 'cid'));
  1107. }
  1108. }
  1109. return t('File components updated to support AJAX uploading.');
  1110. }
  1111. /**
  1112. * Add file usage entries for all files uploaded through Webform.
  1113. */
  1114. function webform_update_7319(&$sandbox) {
  1115. if (!isset($sandbox['progress'])) {
  1116. // Initialize batch update information.
  1117. $sandbox['progress'] = 0;
  1118. $sandbox['last_fid_processed'] = -1;
  1119. $sandbox['max'] = db_select('file_managed')
  1120. ->condition('uri', '%' . db_like('://webform/') . '%', 'LIKE')
  1121. ->countQuery()
  1122. ->execute()
  1123. ->fetchField();
  1124. }
  1125. // Process all files attached to a given revision during the same batch.
  1126. $limit = webform_variable_get('webform_update_batch_size');
  1127. $files = db_select('file_managed', 'f')
  1128. ->fields('f')
  1129. ->condition('uri', '%' . db_like('://webform/') . '%', 'LIKE')
  1130. ->condition('fid', $sandbox['last_fid_processed'], '>')
  1131. ->orderBy('fid', 'ASC')
  1132. ->range(0, $limit)
  1133. ->execute()
  1134. ->fetchAllAssoc('fid', PDO::FETCH_ASSOC);
  1135. // Determine each submission with which a file is associated.
  1136. if (!empty($files)) {
  1137. foreach ($files as $fid => $file) {
  1138. $file = (object) $file;
  1139. $sids = db_query('SELECT wsd.sid FROM {webform_component} wc INNER JOIN {webform_submitted_data} wsd ON wc.nid = wsd.nid AND wc.type = :file WHERE data = :fid', array(':file' => 'file', ':fid' => $file->fid))->fetchAllAssoc('sid', PDO::FETCH_ASSOC);
  1140. foreach ($sids as $sid => $row) {
  1141. // We use a db_merge() instead of file_usage_add() to prevent problems
  1142. // in the event this update was run twice. No file provided by Webform
  1143. // should ever be in use more than once at this point.
  1144. db_merge('file_usage')
  1145. ->key(array(
  1146. 'fid' => $file->fid,
  1147. 'type' => 'submission',
  1148. 'module' => 'webform',
  1149. 'id' => $sid,
  1150. ))
  1151. ->fields(array(
  1152. 'count' => 1,
  1153. ))
  1154. ->execute();
  1155. }
  1156. // Update our progress information for the batch update.
  1157. $sandbox['progress']++;
  1158. $sandbox['last_fid_processed'] = $file->fid;
  1159. }
  1160. }
  1161. // If less than limit was processed, the update process is finished.
  1162. if (count($files) < $limit || $sandbox['progress'] == $sandbox['max']) {
  1163. $finished = TRUE;
  1164. }
  1165. // If there's no max value then there's nothing to update and we're finished.
  1166. if (empty($sandbox['max']) || isset($finished)) {
  1167. return t('Webform file entries created in the file_usage table.');
  1168. }
  1169. else {
  1170. // Indicate our current progress to the batch update system.
  1171. $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  1172. }
  1173. }
  1174. /**
  1175. * Mark files uploaded through Webform that report active usage permanent.
  1176. */
  1177. function webform_update_7320() {
  1178. db_query("UPDATE {file_managed} SET status = 1 WHERE fid IN (SELECT fid FROM {file_usage} WHERE module = :module_name)", array(':module_name' => 'webform'));
  1179. }
  1180. /**
  1181. * Rewrite token replacement system to use D7 tokens.
  1182. *
  1183. * If needed, please download and install the Token module from drupal.org.
  1184. * Otherwise some tokens will not be rendered.
  1185. */
  1186. function webform_update_7401(&$sandbox) {
  1187. // Define replacements.
  1188. $patterns = array(
  1189. '%username',
  1190. '%useremail',
  1191. '%uid',
  1192. '%date',
  1193. '%ip_address',
  1194. '%site',
  1195. '%nid',
  1196. '%title',
  1197. '%email_values',
  1198. '%submission_url',
  1199. '%sid',
  1200. '%server[REQUEST_URI]',
  1201. // Used to convert nested arrays of %value and %email.
  1202. '][',
  1203. );
  1204. $replacements = array(
  1205. '[current-user:name]',
  1206. '[current-user:mail]',
  1207. '[current-user:uid]',
  1208. '[submission:date:long]',
  1209. '[current-user:ip-address]',
  1210. '[site:name]',
  1211. '[node:nid]',
  1212. '[node:title]',
  1213. '[submission:values]',
  1214. '[submission:url]',
  1215. '[submission:sid]',
  1216. '[current-page:url]',
  1217. // Replace "][" with ":" for %value and %email.
  1218. ':',
  1219. );
  1220. $dpatterns = array(
  1221. '/%get\[([^\]]+)\]/m',
  1222. '/%email\[([^% \n\r\t]+)?\]/m',
  1223. '/%value\[([^% \n\r\t]+)?\]/m',
  1224. '/%profile\[([^\]]+)\]/m',
  1225. );
  1226. $dreplacements = array(
  1227. '[current-page:query:$1]',
  1228. '[submission:values:$1]',
  1229. '[submission:values:$1:nolabel]',
  1230. '[current-user:$1]',
  1231. );
  1232. $limit = webform_variable_get('webform_update_batch_size');
  1233. $processed_count = _webform_update_7401_batch($sandbox, $patterns, $replacements, $dpatterns, $dreplacements, $limit);
  1234. // If less than limit was processed, the update process is finished.
  1235. if ($processed_count < $limit || $sandbox['progress'] == $sandbox['max']) {
  1236. $finished = TRUE;
  1237. }
  1238. // If there's no max value then there's nothing to update and we're finished.
  1239. if (empty($sandbox['max']) || isset($finished)) {
  1240. $message = t('Your existing webforms have been upgraded to use the global Drupal 7 token system.');
  1241. if (!module_exists('token')) {
  1242. $message .= ' <strong>' . t('Please download and install the <a href="http://drupal.org/project/token" target="_blank">Token module</a>. Otherwise some tokens will not be rendered.') . '</strong>';
  1243. }
  1244. return $message;
  1245. }
  1246. else {
  1247. // Indicate our current progress to the batch update system.
  1248. $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  1249. }
  1250. }
  1251. /**
  1252. * Utility function to update all the locations that use tokens.
  1253. */
  1254. function _webform_update_7401_batch(&$sandbox, $patterns, $replacements, $dpatterns, $dreplacements, $limit) {
  1255. // Set up the initial batch process.
  1256. if (!isset($sandbox['progress'])) {
  1257. $sandbox['progress'] = 0;
  1258. $sandbox['last_nid_processed'] = -1;
  1259. $sandbox['max'] = db_select('webform')
  1260. ->countQuery()
  1261. ->execute()
  1262. ->fetchField();
  1263. // Update tokens in variables.
  1264. $variables = array(
  1265. 'webform_default_subject',
  1266. 'webform_default_from_name',
  1267. 'webform_default_from_address',
  1268. );
  1269. foreach ($variables as $variable) {
  1270. $value = variable_get($variable, NULL);
  1271. if ($value !== NULL) {
  1272. $value = str_replace($patterns, $replacements, $value);
  1273. $value = preg_replace($dpatterns, $dreplacements, $value);
  1274. variable_set($variable, $value);
  1275. }
  1276. }
  1277. }
  1278. $webforms = db_select('webform', 'w')
  1279. ->fields('w')
  1280. ->condition('nid', $sandbox['last_nid_processed'], '>')
  1281. ->orderBy('nid', 'ASC')
  1282. ->range(0, $limit)
  1283. ->execute()
  1284. ->fetchAllAssoc('nid', PDO::FETCH_ASSOC);
  1285. foreach ($webforms as $nid => $webform) {
  1286. // Update the webform record itself.
  1287. $original = $webform;
  1288. $parts = array(
  1289. 'confirmation',
  1290. 'redirect_url',
  1291. );
  1292. foreach ($parts as $part) {
  1293. $webform[$part] = str_replace($patterns, $replacements, $webform[$part]);
  1294. $webform[$part] = preg_replace($dpatterns, $dreplacements, $webform[$part]);
  1295. }
  1296. if ($webform != $original) {
  1297. drupal_write_record('webform', $webform, array('nid'));
  1298. }
  1299. // Update tokens in component configurations.
  1300. $result = db_select('webform_component', 'wc', array('fetch' => PDO::FETCH_ASSOC))
  1301. ->fields('wc')
  1302. ->condition('wc.nid', $nid)
  1303. ->execute();
  1304. foreach ($result as $component) {
  1305. $original_extra = $component['extra'];
  1306. $original_value = $component['value'];
  1307. $component['extra'] = unserialize($component['extra']);
  1308. if (isset($component['extra']['description'])) {
  1309. $description = str_replace($patterns, $replacements, $component['extra']['description']);
  1310. $description = preg_replace($dpatterns, $dreplacements, $description);
  1311. $component['extra']['description'] = $description;
  1312. }
  1313. $component['extra'] = serialize($component['extra']);
  1314. $value = str_replace($patterns, $replacements, $component['value']);
  1315. $value = preg_replace($dpatterns, $dreplacements, $value);
  1316. $component['value'] = $value;
  1317. if ($component['extra'] != $original_extra || $component['value'] != $original_value) {
  1318. drupal_write_record('webform_component', $component, array('nid', 'cid'));
  1319. }
  1320. }
  1321. // Update tokens in e-mail configurations.
  1322. $result = db_select('webform_emails', 'we', array('fetch' => PDO::FETCH_ASSOC))
  1323. ->fields('we')
  1324. ->condition('we.nid', $nid)
  1325. ->execute();
  1326. foreach ($result as $email) {
  1327. $parts = array(
  1328. 'template',
  1329. 'subject',
  1330. 'from_name',
  1331. );
  1332. $original = $email;
  1333. foreach ($parts as $part) {
  1334. $email[$part] = str_replace($patterns, $replacements, $email[$part]);
  1335. $email[$part] = preg_replace($dpatterns, $dreplacements, $email[$part]);
  1336. }
  1337. if ($email != $original) {
  1338. drupal_write_record('webform_emails', $email, array('nid', 'eid'));
  1339. }
  1340. }
  1341. // Update the last processed NID.
  1342. $sandbox['last_nid_processed'] = $nid;
  1343. $sandbox['progress']++;
  1344. }
  1345. return count($webforms);
  1346. }
  1347. /**
  1348. * Add the webform_conditional database table.
  1349. */
  1350. function webform_update_7402() {
  1351. // Sanity checks.
  1352. if (db_table_exists('webform_conditional')) {
  1353. // Both tables exist, so these are Webform-core provided tables.
  1354. if (db_table_exists('webform_conditional_rules')) {
  1355. return;
  1356. }
  1357. // Webform Conditional module was installed previously but not uninstalled.
  1358. else {
  1359. throw new DrupalUpdateException(t('The "Webform Conditional" module has previously been installed on your site. Either uninstall the module or drop the database table "webform_conditional".'));
  1360. }
  1361. }
  1362. $schema['webform_conditional'] = array(
  1363. 'description' => 'Holds information about conditional logic.',
  1364. 'fields' => array(
  1365. 'nid' => array(
  1366. 'description' => 'The node identifier of a webform.',
  1367. 'type' => 'int',
  1368. 'unsigned' => TRUE,
  1369. 'not null' => TRUE,
  1370. 'default' => 0,
  1371. ),
  1372. 'rgid' => array(
  1373. 'description' => 'The rule group identifier for this group of rules.',
  1374. 'type' => 'int',
  1375. 'size' => 'small',
  1376. 'unsigned' => TRUE,
  1377. 'not null' => TRUE,
  1378. 'default' => 0,
  1379. ),
  1380. 'andor' => array(
  1381. 'description' => 'Whether to AND or OR the actions in this group. All actions within the same crid should have the same andor value.',
  1382. 'type' => 'varchar',
  1383. 'length' => 128,
  1384. ),
  1385. 'action' => array(
  1386. 'description' => 'The action to be performed on the target. Typically "show" or "hide" for targets of type "component", and "send" for targets of type "email".',
  1387. 'type' => 'varchar',
  1388. 'length' => 128,
  1389. ),
  1390. 'target_type' => array(
  1391. 'description' => 'The type of target to be affected. Either "component" or "email". Indicates what type of ID the "target" column contains.',
  1392. 'type' => 'varchar',
  1393. 'length' => 128,
  1394. ),
  1395. 'target' => array(
  1396. 'description' => 'The ID of the target to be affected. Typically a component ID.',
  1397. 'type' => 'varchar',
  1398. 'length' => 128,
  1399. ),
  1400. 'weight' => array(
  1401. 'description' => 'Determines the position of this conditional compared to others.',
  1402. 'type' => 'int',
  1403. 'size' => 'small',
  1404. 'not null' => TRUE,
  1405. 'default' => 0,
  1406. ),
  1407. ),
  1408. 'primary key' => array('nid', 'rgid'),
  1409. );
  1410. $schema['webform_conditional_rules'] = array(
  1411. 'description' => 'Holds information about conditional logic.',
  1412. 'fields' => array(
  1413. 'nid' => array(
  1414. 'description' => 'The node identifier of a webform.',
  1415. 'type' => 'int',
  1416. 'unsigned' => TRUE,
  1417. 'not null' => TRUE,
  1418. 'default' => 0,
  1419. ),
  1420. 'rgid' => array(
  1421. 'description' => 'The rule group identifier for this group of rules.',
  1422. 'type' => 'int',
  1423. 'size' => 'small',
  1424. 'unsigned' => TRUE,
  1425. 'not null' => TRUE,
  1426. 'default' => 0,
  1427. ),
  1428. 'rid' => array(
  1429. 'description' => 'The rule identifier for this conditional rule.',
  1430. 'type' => 'int',
  1431. 'size' => 'small',
  1432. 'unsigned' => TRUE,
  1433. 'not null' => TRUE,
  1434. 'default' => 0,
  1435. ),
  1436. 'source_type' => array(
  1437. 'description' => 'The type of source on which the conditional is based. Currently always "component". Indicates what type of ID the "source" column contains.',
  1438. 'type' => 'varchar',
  1439. 'length' => 128,
  1440. ),
  1441. 'source' => array(
  1442. 'description' => 'The component ID being used in this condition.',
  1443. 'type' => 'int',
  1444. 'size' => 'small',
  1445. 'unsigned' => TRUE,
  1446. 'not null' => TRUE,
  1447. 'default' => 0,
  1448. ),
  1449. 'operator' => array(
  1450. 'description' => 'Which operator (equal, contains, starts with, etc.) should be used for this comparison between the source and value?',
  1451. 'type' => 'varchar',
  1452. 'length' => 128,
  1453. ),
  1454. 'value' => array(
  1455. 'description' => 'The value to be compared with source.',
  1456. 'type' => 'text',
  1457. ),
  1458. ),
  1459. 'primary key' => array('nid', 'rgid', 'rid'),
  1460. );
  1461. db_create_table('webform_conditional', $schema['webform_conditional']);
  1462. db_create_table('webform_conditional_rules', $schema['webform_conditional_rules']);
  1463. // Rebuild schema so that webform_update_7403() can use drupal_write_record().
  1464. if (db_table_exists('system') && db_field_exists('system', 'status')) {
  1465. drupal_get_schema(NULL, TRUE);
  1466. }
  1467. }
  1468. /**
  1469. * Convert per-component conditionals to new more flexible conditional system.
  1470. */
  1471. function webform_update_7403(&$sandbox) {
  1472. // Set up the initial batch process.
  1473. if (!isset($sandbox['progress'])) {
  1474. $sandbox['progress'] = 0;
  1475. $sandbox['last_nid_processed'] = -1;
  1476. $sandbox['converted_count'] = 0;
  1477. $sandbox['max'] = db_select('webform')
  1478. ->countQuery()
  1479. ->execute()
  1480. ->fetchField();
  1481. }
  1482. $limit = webform_variable_get('webform_update_batch_size');
  1483. $webforms = db_select('webform', 'w')
  1484. ->fields('w')
  1485. ->condition('nid', $sandbox['last_nid_processed'], '>')
  1486. ->orderBy('nid', 'ASC')
  1487. ->range(0, $limit)
  1488. ->execute()
  1489. ->fetchAllAssoc('nid', PDO::FETCH_ASSOC);
  1490. foreach ($webforms as $nid => $webform) {
  1491. // Update tokens in component configurations.
  1492. $result = db_select('webform_component', 'wc', array('fetch' => PDO::FETCH_ASSOC))
  1493. ->fields('wc')
  1494. ->condition('wc.nid', $nid)
  1495. ->execute();
  1496. $rgid = 0;
  1497. foreach ($result as $component) {
  1498. // For each component, check if it has conditional properties that need
  1499. // to be removed and/or migrated. Because these properties may be in any
  1500. // order, copy the original extra array for comparison.
  1501. $component['extra'] = unserialize($component['extra']);
  1502. $original_extra = $component['extra'];
  1503. // Remove conditional properties if present.
  1504. if (isset($component['extra']['conditional_component'])) {
  1505. unset($component['extra']['conditional_component']);
  1506. }
  1507. if (isset($component['extra']['conditional_operator'])) {
  1508. unset($component['extra']['conditional_operator']);
  1509. }
  1510. if (isset($component['extra']['conditional_values'])) {
  1511. unset($component['extra']['conditional_values']);
  1512. // If the component has conditional values specified, that indicates
  1513. // that this component was conditionally shown. Convert it to a new
  1514. // conditional with multiple rules if needed.
  1515. if (strlen(trim($original_extra['conditional_values'])) && !empty($original_extra['conditional_operator']) && !empty($original_extra['conditional_component'])) {
  1516. $conditional_values = explode("\n", $original_extra['conditional_values']);
  1517. $rules = array();
  1518. $rule = array(
  1519. 'nid' => $nid,
  1520. 'rgid' => $rgid,
  1521. 'rid' => NULL,
  1522. 'source_type' => 'component',
  1523. 'source' => $original_extra['conditional_component'],
  1524. 'operator' => 'equal',
  1525. 'value' => NULL,
  1526. );
  1527. foreach ($conditional_values as $value) {
  1528. $value = trim($value);
  1529. if ($value) {
  1530. $new_rule = $rule;
  1531. $new_rule['rid'] = count($rules);
  1532. $new_rule['value'] = $value;
  1533. $rules[] = $new_rule;
  1534. }
  1535. }
  1536. if (count($rules)) {
  1537. $conditional = array(
  1538. 'nid' => $nid,
  1539. 'rgid' => $rgid,
  1540. 'andor' => 'or',
  1541. 'action' => ($original_extra['conditional_operator'] === '=') ? 'show' : 'hide',
  1542. 'target_type' => 'component',
  1543. 'target' => $component['cid'],
  1544. 'weight' => 0,
  1545. );
  1546. // Cannot use drupal_write_record for webform_conditional because
  1547. // the current schema has fewer fields than the schema in use during
  1548. // this hook_update_N function.
  1549. db_insert('webform_conditional')
  1550. ->fields($conditional)
  1551. ->execute();
  1552. foreach ($rules as $rule) {
  1553. drupal_write_record('webform_conditional_rules', $rule);
  1554. }
  1555. $sandbox['converted_count']++;
  1556. $rgid++;
  1557. }
  1558. }
  1559. }
  1560. // Update the component with the conditional properties removed.
  1561. if ($component['extra'] != $original_extra) {
  1562. $component['extra'] = serialize($component['extra']);
  1563. drupal_write_record('webform_component', $component, array('nid', 'cid'));
  1564. }
  1565. }
  1566. // Update the last processed NID.
  1567. $sandbox['last_nid_processed'] = $nid;
  1568. $sandbox['progress']++;
  1569. }
  1570. // If less than limit was processed, the update process is finished.
  1571. if (count($webforms) < $limit || $sandbox['progress'] == $sandbox['max']) {
  1572. $finished = TRUE;
  1573. }
  1574. // If there's no max value then there's nothing to update and we're finished.
  1575. if (empty($sandbox['max']) || isset($finished)) {
  1576. return t('@count webforms using conditionals updated to the new conditional system.', array('@count' => $sandbox['converted_count']));
  1577. }
  1578. else {
  1579. // Indicate our current progress to the batch update system.
  1580. $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  1581. }
  1582. }
  1583. /**
  1584. * Remove files left over from deleted submissions.
  1585. *
  1586. * Such files are now deleted automatically.
  1587. */
  1588. function webform_update_7404() {
  1589. module_load_include('inc', 'webform', 'components/file');
  1590. $fids = db_query('SELECT fid FROM {file_usage} WHERE module = \'webform\' AND type = \'submission\' AND NOT id IN(SELECT sid FROM {webform_submissions})')->fetchCol();
  1591. foreach ($fids as $fid) {
  1592. _webform_delete_file(NULL, array($fid));
  1593. }
  1594. }
  1595. /**
  1596. * Add an "extra" column to the e-mail table for for non-queryable options.
  1597. */
  1598. function webform_update_7405() {
  1599. $schema = array(
  1600. 'description' => 'A serialized array of additional options for the e-mail configuration, including excluded components and value mapping for the TO and FROM addresses for select lists.',
  1601. 'type' => 'text',
  1602. 'not null' => TRUE,
  1603. 'initial' => '',
  1604. );
  1605. if (!db_field_exists('webform_emails', 'extra')) {
  1606. db_add_field('webform_emails', 'extra', $schema);
  1607. }
  1608. }
  1609. /**
  1610. * Convert the "webform_use_cookies" setting to "webform_tracking_mode".
  1611. */
  1612. function webform_update_7406() {
  1613. // Previously, we only had "strict" and "ip_address" checking. Using cookies
  1614. // meant cookies in addition to IP address.
  1615. $use_cookies = variable_get('webform_use_cookies');
  1616. if (isset($use_cookies)) {
  1617. variable_set('webform_tracking_mode', $use_cookies ? 'strict' : 'ip_address');
  1618. variable_del('webform_use_cookies');
  1619. }
  1620. }
  1621. /**
  1622. * Remove orphaned conditional rules.
  1623. */
  1624. function webform_update_7407() {
  1625. // Delete entire conditions for deleted components that were the target.
  1626. // This query is complicated by database compatibility since we're joining two
  1627. // non-matching columns. See http://drupal.org/node/2026891.
  1628. $result = db_query("SELECT rg.* FROM {webform_conditional} rg LEFT JOIN {webform_component} c ON rg.nid = c.nid AND rg.target_type = 'component' AND rg.target = RTRIM(CAST(c.cid AS CHAR(10))) WHERE c.cid IS NULL");
  1629. foreach ($result as $row) {
  1630. db_delete('webform_conditional')
  1631. ->condition('nid', $row->nid)
  1632. ->condition('rgid', $row->rgid)
  1633. ->execute();
  1634. db_delete('webform_conditional_rules')
  1635. ->condition('nid', $row->nid)
  1636. ->condition('rgid', $row->rgid)
  1637. ->execute();
  1638. }
  1639. // Delete conditional rules for deleted components that were the source.
  1640. $result = db_query("SELECT r.* FROM {webform_conditional_rules} r LEFT JOIN {webform_component} c ON r.nid = c.nid AND r.source_type = 'component' AND r.source = c.cid WHERE c.cid IS NULL");
  1641. foreach ($result as $row) {
  1642. db_delete('webform_conditional_rules')
  1643. ->condition('nid', $row->nid)
  1644. ->condition('rgid', $row->rgid)
  1645. ->condition('rid', $row->rid)
  1646. ->execute();
  1647. }
  1648. // Delete any conditions that no longer have any rules left in them.
  1649. $result = db_query("SELECT rg.* FROM {webform_conditional} rg LEFT JOIN {webform_conditional_rules} r ON rg.nid = r.nid AND rg.rgid = r.rgid WHERE r.rgid IS NULL");
  1650. foreach ($result as $row) {
  1651. db_delete('webform_conditional')
  1652. ->condition('nid', $row->nid)
  1653. ->condition('rgid', $row->rgid)
  1654. ->execute();
  1655. }
  1656. }
  1657. /**
  1658. * Rename the "mandatory" column to "required".
  1659. */
  1660. function webform_update_7408() {
  1661. $spec = array(
  1662. 'description' => 'Boolean flag for if this component is required.',
  1663. 'type' => 'int',
  1664. 'size' => 'tiny',
  1665. 'not null' => TRUE,
  1666. 'default' => 0,
  1667. );
  1668. if (!db_field_exists('webform_component', 'required')) {
  1669. db_change_field('webform_component', 'mandatory', 'required', $spec);
  1670. }
  1671. }
  1672. /**
  1673. * Add progress bar columns to the webform table.
  1674. */
  1675. function webform_update_7409() {
  1676. if (!db_field_exists('webform', 'progressbar_bar')) {
  1677. $int_schema = array(
  1678. 'type' => 'int',
  1679. 'size' => 'tiny',
  1680. 'not null' => TRUE,
  1681. 'default' => 0,
  1682. );
  1683. $varchar_schema = array(
  1684. 'type' => 'varchar',
  1685. 'length' => 255,
  1686. );
  1687. $int_schema['description'] = 'Boolean value indicating if the bar should be shown as part of the progress bar.';
  1688. db_add_field('webform', 'progressbar_bar', $int_schema);
  1689. $int_schema['description'] = 'Boolean value indicating if the page number should be shown as part of the progress bar.';
  1690. db_add_field('webform', 'progressbar_page_number', $int_schema);
  1691. $int_schema['description'] = 'Boolean value indicating if the percentage complete should be shown as part of the progress bar.';
  1692. db_add_field('webform', 'progressbar_percent', $int_schema);
  1693. $int_schema['description'] = 'Boolean value indicating if the pagebreak labels should be included as part of the progress bar.';
  1694. db_add_field('webform', 'progressbar_pagebreak_labels', $int_schema);
  1695. $int_schema['description'] = 'Boolean value indicating if the confirmation page should count as a page in the progress bar.';
  1696. db_add_field('webform', 'progressbar_include_confirmation', $int_schema);
  1697. $varchar_schema['description'] = 'Label for the first page of the progress bar.';
  1698. db_add_field('webform', 'progressbar_label_first', $varchar_schema);
  1699. $varchar_schema['description'] = 'Label for the last page of the progress bar.';
  1700. db_add_field('webform', 'progressbar_label_confirmation', $varchar_schema);
  1701. return t('New webform columns added.');
  1702. }
  1703. }
  1704. /**
  1705. * Remove the "teaser" column from the "webform" table.
  1706. */
  1707. function webform_update_7410() {
  1708. if (db_field_exists('webform', 'teaser')) {
  1709. db_drop_field('webform', 'teaser');
  1710. return t('Removed "teaser" column. All forms that had the "Show complete form in teaser" option disabled will now show forms in their teasers. Use view modes to hide the form if desired.');
  1711. }
  1712. }
  1713. /**
  1714. * Remove [submission:values:x] token use of :nolabel and add :withlabel.
  1715. */
  1716. function webform_update_7411(&$sandbox) {
  1717. // Define replacements.
  1718. $patterns = array();
  1719. $replacements = array();
  1720. $dpatterns = array(
  1721. '/\[submission:values(:(?!nolabel)[a-z_]+)+\]/m',
  1722. '/\[submission:values(:([a-z_:]+))?:nolabel\]/m',
  1723. );
  1724. $dreplacements = array(
  1725. '[submission:values$1:withlabel]',
  1726. '[submission:values$1]',
  1727. );
  1728. $limit = webform_variable_get('webform_update_batch_size');
  1729. $processed_count = _webform_update_7401_batch($sandbox, $patterns, $replacements, $dpatterns, $dreplacements, $limit);
  1730. // If less than limit was processed, the update process is finished.
  1731. if ($processed_count < $limit || $sandbox['progress'] == $sandbox['max']) {
  1732. $finished = TRUE;
  1733. }
  1734. // If there's no max value then there's nothing to update and we're finished.
  1735. if (empty($sandbox['max']) || isset($finished)) {
  1736. return t('Replaced tokens using [submission:values:x] with [submission:values:x:withlabel].');
  1737. }
  1738. else {
  1739. // Indicate our current progress to the batch update system.
  1740. $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  1741. }
  1742. }
  1743. /**
  1744. * Split webform_node_types as content type specific.
  1745. */
  1746. function webform_update_7412() {
  1747. $types = variable_get('webform_node_types', array('webform'));
  1748. foreach ($types as $type) {
  1749. variable_set('webform_node_' . $type, TRUE);
  1750. }
  1751. variable_del('webform_node_types');
  1752. }
  1753. /**
  1754. * Add preview page columns to the webform table.
  1755. */
  1756. function webform_update_7413() {
  1757. if (!db_field_exists('webform', 'preview')) {
  1758. $int_schema = array(
  1759. 'type' => 'int',
  1760. 'size' => 'tiny',
  1761. 'not null' => TRUE,
  1762. 'default' => 0,
  1763. );
  1764. $varchar_schema = array(
  1765. 'type' => 'varchar',
  1766. 'length' => 255,
  1767. );
  1768. $text_schema = array(
  1769. 'type' => 'text',
  1770. 'not null' => TRUE,
  1771. 'initial' => '',
  1772. );
  1773. $int_schema['description'] = 'Boolean value indicating if this form includes a page for previewing the submission.';
  1774. db_add_field('webform', 'preview', $int_schema);
  1775. $varchar_schema['description'] = 'The text for the button that will proceed to the preview page.';
  1776. db_add_field('webform', 'preview_next_button_label', $varchar_schema);
  1777. $varchar_schema['description'] = 'The text for the button to go backwards from the preview page.';
  1778. db_add_field('webform', 'preview_prev_button_label', $varchar_schema);
  1779. $varchar_schema['description'] = 'The title of the preview page, as used by the progress bar.';
  1780. db_add_field('webform', 'preview_title', $varchar_schema);
  1781. $text_schema['description'] = 'Text shown on the preview page of the form.';
  1782. db_add_field('webform', 'preview_message', $text_schema);
  1783. $varchar_schema['description'] = 'The {filter_format}.format of the preview page message.';
  1784. db_add_field('webform', 'preview_message_format', $varchar_schema);
  1785. $text_schema['description'] = 'Comma-separated list of component IDs that should not be included in this form\'s confirmation page.';
  1786. db_add_field('webform', 'preview_excluded_components', $text_schema);
  1787. return t('New webform columns added.');
  1788. }
  1789. }
  1790. /**
  1791. * Change email subject, from_name and from_address fields to type 'TEXT'.
  1792. */
  1793. function webform_update_7414() {
  1794. $schema = array(
  1795. 'subject' => array(
  1796. 'description' => 'The e-mail subject that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  1797. 'type' => 'text',
  1798. 'not null' => FALSE,
  1799. ),
  1800. 'from_name' => array(
  1801. 'description' => 'The e-mail "from" name that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  1802. 'type' => 'text',
  1803. 'not null' => FALSE,
  1804. ),
  1805. 'from_address' => array(
  1806. 'description' => 'The e-mail "from" e-mail address that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
  1807. 'type' => 'text',
  1808. 'not null' => FALSE,
  1809. ),
  1810. );
  1811. db_change_field('webform_emails', 'subject', 'subject', $schema['subject']);
  1812. db_change_field('webform_emails', 'from_name', 'from_name', $schema['from_name']);
  1813. db_change_field('webform_emails', 'from_address', 'from_address', $schema['from_address']);
  1814. return t('Custom email columns successfully changed.');
  1815. }
  1816. /**
  1817. * Increase length of webform.redirect_url.
  1818. */
  1819. function webform_update_7415() {
  1820. $spec = array(
  1821. 'description' => 'The URL a user is redirected to after submitting a form.',
  1822. 'type' => 'varchar',
  1823. 'length' => 2048,
  1824. 'default' => '<confirmation>',
  1825. );
  1826. db_change_field('webform', 'redirect_url', 'redirect_url', $spec);
  1827. }
  1828. /**
  1829. * Add columns for serial numbered submissions. Add serial numbers to existing submissions.
  1830. */
  1831. function webform_update_7416() {
  1832. // SQL database implementations vary in how DDL statements are handled within
  1833. // transactions. Since this update routine should be run in maintenance mode
  1834. // without concurrent transactions, no DDL statements are executed within a
  1835. // transaction.
  1836. // Add next_serial column to webform.
  1837. $spec = array(
  1838. 'description' => 'The serial number to give to the next submission to this webform.',
  1839. 'type' => 'int',
  1840. 'unsigned' => TRUE,
  1841. 'not null' => TRUE,
  1842. 'default' => 1,
  1843. );
  1844. if (!db_field_exists('webform', 'next_serial')) {
  1845. db_add_field('webform', 'next_serial', $spec);
  1846. }
  1847. // Add serial column to webform_submissions.
  1848. $spec = array(
  1849. 'description' => 'The serial number of this submission.',
  1850. 'type' => 'int',
  1851. 'unsigned' => TRUE,
  1852. );
  1853. if (!db_field_exists('webform_submissions', 'serial')) {
  1854. db_add_field('webform_submissions', 'serial', $spec);
  1855. }
  1856. // Begin a transaction for updating the serial numbers. The transaction will
  1857. // commit when $transaction is unset or goes out-of-scope.
  1858. $transaction = db_transaction();
  1859. // Delete stray entries from the Webform tables before adding serial numbers.
  1860. db_query("DELETE FROM {webform_submissions} WHERE nid NOT IN (SELECT nid FROM {webform})");
  1861. db_query("DELETE FROM {webform_submitted_data} WHERE nid NOT IN (SELECT nid FROM {webform})");
  1862. // Add serial numbers to all submissions.
  1863. // Repeat for every Webform.
  1864. $nids = db_select('webform', 'w')
  1865. ->fields('w', array('nid'))
  1866. ->execute();
  1867. while ($nid = $nids->fetchColumn()) {
  1868. $serial = 1;
  1869. // Repeat for every submission in this Webform.
  1870. $sids = db_select('webform_submissions', 'ws')
  1871. ->forUpdate()
  1872. ->fields('ws', array('sid'))
  1873. ->condition('nid', $nid)
  1874. ->orderBy('sid')
  1875. ->execute();
  1876. while ($sid = $sids->fetchColumn()) {
  1877. // Set the serial number.
  1878. db_update('webform_submissions')
  1879. ->fields(array('serial' => $serial))
  1880. ->condition('nid', $nid)
  1881. ->condition('sid', $sid)
  1882. ->execute();
  1883. $serial++;
  1884. }
  1885. // Set the next serial number.
  1886. db_update('webform')
  1887. ->fields(array('next_serial' => $serial))
  1888. ->condition('nid', $nid)
  1889. ->execute();
  1890. }
  1891. // Commit the transaction.
  1892. unset($transaction);
  1893. // Now that every submission has a serial number, make serial numbers required.
  1894. $spec['not null'] = TRUE;
  1895. $keys = array();
  1896. // Create a unique index if it does not already exist.
  1897. if (!db_index_exists('webform_submissions', 'nid_serial')) {
  1898. $keys = array(
  1899. 'unique keys' => array(
  1900. 'nid_serial' => array('nid', 'serial'),
  1901. ),
  1902. );
  1903. }
  1904. db_change_field('webform_submissions', 'serial', 'serial', $spec, $keys);
  1905. return t('Columns for serial numbered submissions successfully added. Serial numbers added to existing submissions.');
  1906. }
  1907. /**
  1908. * Change webform_component.name to text to allow for longer labels.
  1909. */
  1910. function webform_update_7417() {
  1911. // This update function was introduced in 7.x-4.0rc1, which was the first
  1912. // release to require views. While the views requirement was added to the
  1913. // .info file, and while subsequently hook_requirements() added a check for
  1914. // views, it is possible to arrive at this update function via drush updatedb
  1915. // without views enabled.
  1916. $result = NULL;
  1917. if (!module_exists('views')) {
  1918. if (module_enable(array('views'))) {
  1919. $result = t('The Views module was automatically enabled.');
  1920. }
  1921. else {
  1922. throw new DrupalUpdateException(t('UPDATE ERROR: The Views module must be downloaded and enabled before Webform updates can proceed.'));
  1923. }
  1924. }
  1925. db_change_field('webform_component', 'name', 'name', array('type' => 'text', 'not null' => TRUE));
  1926. return $result;
  1927. }
  1928. /**
  1929. * Upgrade the "extra" column in the e-mail table.
  1930. *
  1931. * Make the column consistent with a new webform installation.
  1932. *
  1933. * In version 7.x-4.0-rc6 and earlier, the extra field was added with 'not null'
  1934. * FALSE, cause the schema module to report in mismatch. While functionally this
  1935. * causes no problem, this update removes the schema module's warning.
  1936. */
  1937. function webform_update_7418() {
  1938. // While there should never be any NULL values in the extra field, change them
  1939. // to '' to be safe.
  1940. db_update('webform_emails')
  1941. ->fields(array('extra' => ''))
  1942. ->isNull('extra')
  1943. ->execute();
  1944. // Pass a complete field specification to db_change_field for cross-database
  1945. // compatiblity.
  1946. $spec = array(
  1947. 'description' => 'A serialized array of additional options for the e-mail configuration, including excluded components and value mapping for the TO and FROM addresses for select lists.',
  1948. 'type' => 'text',
  1949. 'not null' => TRUE,
  1950. );
  1951. db_change_field('webform_emails', 'extra', 'extra', $spec);
  1952. }
  1953. /**
  1954. * Add an index on submitted data.
  1955. */
  1956. function webform_update_7419() {
  1957. // Note: MS SQL Server does not support size-limited indexes and the column
  1958. // type (text) is too big to fit inside index size limits.
  1959. if (!db_index_exists('webform_submitted_data', 'data') && db_driver() != 'sqlsrv') {
  1960. db_add_index('webform_submitted_data', 'data', array(array('data', 64)));
  1961. }
  1962. }
  1963. /**
  1964. * Extend access to the WEBFORM tab to anyone who can access the node's EDIT tab.
  1965. */
  1966. function webform_update_7420() {
  1967. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('edit webform components'));
  1968. }
  1969. /**
  1970. * Set the administrator option for an HTML-capable mail system to the current automatically-detected option.
  1971. */
  1972. function webform_update_7421() {
  1973. $capable = array_reduce(array('mandrill', 'mimemail', 'htmlmail'),
  1974. function ($carry, $module) {
  1975. return $carry || module_exists($module);
  1976. },
  1977. FALSE);
  1978. variable_set('webform_email_html_capable', $capable);
  1979. return $capable
  1980. ? t('An HTML-capable module is installed. The option to send HTML e-mail is enabled.')
  1981. : t('No commonly-known HTML capable module is installed. The option to send HTML e-mail is disabled.');
  1982. }
  1983. /**
  1984. * Remove the administrator option "Include webform forms in search index" and rely on the Search Index view mode instead.
  1985. */
  1986. function webform_update_7422() {
  1987. variable_del('webform_search_index');
  1988. return module_exists('search')
  1989. ? t('Webform forms will now be included in the search index only if the Webform "field" is displayed in the "Search index" view mode.')
  1990. : NULL;
  1991. }
  1992. /**
  1993. * Convert conditionals to be able to support multiple actions per conditional.
  1994. *
  1995. * Backup your database before proceeding. WARNING: Sites with many, many
  1996. * conditionals should execute this update via drush to avoid a PHP timeout.
  1997. */
  1998. function webform_update_7423() {
  1999. // Create webform_condtional_actions table.
  2000. // The table might already exist if this update previously timed-out.
  2001. if (!db_table_exists('webform_conditional_actions')) {
  2002. $schema['webform_conditional_actions'] = array(
  2003. 'description' => 'Holds information about conditional actions.',
  2004. 'fields' => array(
  2005. 'nid' => array(
  2006. 'description' => 'The node identifier of a webform.',
  2007. 'type' => 'int',
  2008. 'unsigned' => TRUE,
  2009. 'not null' => TRUE,
  2010. 'default' => 0,
  2011. ),
  2012. 'rgid' => array(
  2013. 'description' => 'The rule group identifier for this group of rules.',
  2014. 'type' => 'int',
  2015. 'size' => 'small',
  2016. 'unsigned' => TRUE,
  2017. 'not null' => TRUE,
  2018. 'default' => 0,
  2019. ),
  2020. 'aid' => array(
  2021. 'description' => 'The rule identifier for this conditional action.',
  2022. 'type' => 'int',
  2023. 'size' => 'small',
  2024. 'unsigned' => TRUE,
  2025. 'not null' => TRUE,
  2026. 'default' => 0,
  2027. ),
  2028. 'target_type' => array(
  2029. 'description' => 'The type of target to be affected. Currently always "component". Indicates what type of ID the "target" column contains.',
  2030. 'type' => 'varchar',
  2031. 'length' => 128,
  2032. ),
  2033. 'target' => array(
  2034. 'description' => 'The ID of the target to be affected. Typically a component ID.',
  2035. 'type' => 'varchar',
  2036. 'length' => 128,
  2037. ),
  2038. 'invert' => array(
  2039. 'description' => 'If inverted, execute when rule(s) are false.',
  2040. 'type' => 'int',
  2041. 'size' => 'small',
  2042. 'unsigned' => TRUE,
  2043. 'not null' => TRUE,
  2044. 'default' => 0,
  2045. ),
  2046. 'action' => array(
  2047. 'description' => 'The action to be performed on the target.',
  2048. 'type' => 'varchar',
  2049. 'length' => 128,
  2050. ),
  2051. 'argument' => array(
  2052. 'description' => 'Optional argument for action.',
  2053. 'type' => 'text',
  2054. ),
  2055. ),
  2056. 'primary key' => array('nid', 'rgid', 'aid'),
  2057. );
  2058. db_create_table('webform_conditional_actions', $schema['webform_conditional_actions']);
  2059. }
  2060. // In a site with many, many conditionals, the db_insert may timeout. Start a
  2061. // transaction to ensure atomic action.
  2062. $transaction = db_transaction();
  2063. // Copy target information from existing webform_conditional table to new
  2064. // webfrom_condtional_actions table.
  2065. $select = db_select('webform_conditional', 'c')
  2066. ->fields('c', array('nid', 'rgid', 'action', 'target_type', 'target'))
  2067. ->orderBy('nid')->orderBy('rgid');
  2068. $select->addExpression("''", 'argument');
  2069. db_insert('webform_conditional_actions')
  2070. ->from($select)
  2071. ->execute();
  2072. // Commit the insert.
  2073. unset($transaction);
  2074. // Remove unneeded columns from webform_conditional.
  2075. foreach (array('action', 'target_type', 'target') as $fieldname) {
  2076. if (db_field_exists('webform_conditional', $fieldname)) {
  2077. db_drop_field('webform_conditional', $fieldname);
  2078. }
  2079. }
  2080. // Rebuild the registry because this point release contains a new class:
  2081. // WebformConditionals.
  2082. registry_rebuild();
  2083. return t('Webform database tables were successfully adjusted to allow more than one action for each conditional.');
  2084. }
  2085. /**
  2086. * Convert conditional actions of "hide" to "isn't shown".
  2087. */
  2088. function webform_update_7424() {
  2089. $count = db_update('webform_conditional_actions')
  2090. ->fields(array('action' => 'show', 'invert' => 1))
  2091. ->condition('action', 'hide')
  2092. ->execute();
  2093. return format_plural($count,
  2094. '1 "hide" conditional converted to "isn\'t" shown.',
  2095. '@count conditionals converted to "isn\'t" shown.');
  2096. }
  2097. /**
  2098. * Add "exclude empty" option to emails.
  2099. */
  2100. function webform_update_7425() {
  2101. // Add next_serial column to webform.
  2102. $spec = array(
  2103. 'description' => 'Determines if the e-mail will include component with an empty value.',
  2104. 'type' => 'int',
  2105. 'unsigned' => TRUE,
  2106. 'size' => 'tiny',
  2107. 'not null' => TRUE,
  2108. 'default' => 0,
  2109. );
  2110. if (!db_field_exists('webform_emails', 'exclude_empty')) {
  2111. db_add_field('webform_emails', 'exclude_empty', $spec);
  2112. }
  2113. // Clear the views cache since this release use the webform_analysis view.
  2114. cache_clear_all('*', 'cache_views', TRUE);
  2115. return t('Webform e-mails were sucessfully updated to add the option to exclude empty components.');
  2116. }
  2117. /**
  2118. * Add configuration to continue sending individual e-mails to multiple recipients.
  2119. */
  2120. function webform_update_7426() {
  2121. variable_set('webform_email_address_individual', 1);
  2122. }
  2123. /**
  2124. * Add database columns for submission completed and modified timestamps.
  2125. *
  2126. * Sites with many submissions may wish to use drush to execute this update.
  2127. */
  2128. function webform_update_7427() {
  2129. // Create new timestamp columns.
  2130. $specs = array(
  2131. 'completed' => array(
  2132. 'description' => 'Timestamp when the form was submitted as complete (not draft).',
  2133. 'type' => 'int',
  2134. 'not null' => TRUE,
  2135. 'default' => 0,
  2136. ),
  2137. 'modified' => array(
  2138. 'description' => 'Timestamp when the form was last saved (complete or draft).',
  2139. 'type' => 'int',
  2140. 'not null' => TRUE,
  2141. 'default' => 0,
  2142. ),
  2143. );
  2144. foreach ($specs as $field_name => $spec) {
  2145. if (!db_field_exists('webform_submissions', $field_name)) {
  2146. db_add_field('webform_submissions', $field_name, $spec);
  2147. }
  2148. }
  2149. // In a site with many submissions, the db_update may timeout. Start a
  2150. // transaction to ensure atomic action.
  2151. $transaction = db_transaction();
  2152. // Copy submitted to completed for non-draft submissions.
  2153. db_update('webform_submissions')
  2154. ->expression('completed', 'submitted')
  2155. ->condition('is_draft', 0)
  2156. ->execute();
  2157. // Commit the update.
  2158. unset($transaction);
  2159. // Start another transaction.
  2160. $transaction = db_transaction();
  2161. db_update('webform_submissions')
  2162. ->expression('modified', 'submitted')
  2163. ->execute();
  2164. // Commit the update.
  2165. unset($transaction);
  2166. // Clear the views cache since to see the completed and modified views fields.
  2167. cache_clear_all('*', 'cache_views', TRUE);
  2168. return t('Webform submissions were updated with completed and modified timestamps.');
  2169. }
  2170. /**
  2171. * Add a "confidential" option to webforms.
  2172. */
  2173. function webform_update_7428() {
  2174. // Add confidential column to webform.
  2175. if (!db_field_exists('webform', 'confidential')) {
  2176. $spec = array(
  2177. 'description' => 'Boolean value for whether to anonymize submissions.',
  2178. 'type' => 'int',
  2179. 'size' => 'tiny',
  2180. 'not null' => TRUE,
  2181. 'default' => 0,
  2182. );
  2183. db_add_field('webform', 'confidential', $spec);
  2184. }
  2185. return t('Webforms may now be configured to anonymize confidential submissions.');
  2186. }
  2187. /**
  2188. * Add column highest_valid_page to webform_submissions table.
  2189. *
  2190. * Add a column to the submission table to store the page on which to resume a
  2191. * draft. Sites with many, many submissions may wish to execute this update with
  2192. * 'drush updatedb'.
  2193. */
  2194. function webform_update_7429() {
  2195. // Add highest_valid_page column to webform_submissions.
  2196. if (!db_field_exists('webform_submissions', 'highest_valid_page')) {
  2197. $spec = array(
  2198. 'description' => 'For drafts, the highest validated page number.',
  2199. 'type' => 'int',
  2200. 'size' => 'small',
  2201. 'not null' => TRUE,
  2202. 'default' => 0,
  2203. );
  2204. db_add_field('webform_submissions', 'highest_valid_page', $spec);
  2205. }
  2206. return t('Webforms will now resume draft submissions on the page where the submitter left off.');
  2207. }
  2208. /**
  2209. * Add a column to the emails table to allow disabling.
  2210. */
  2211. function webform_update_7430() {
  2212. // Add status column to webform_emails.
  2213. if (!db_field_exists('webform_emails', 'status')) {
  2214. $spec = array(
  2215. 'description' => 'Whether this email is enabled.',
  2216. 'type' => 'int',
  2217. 'unsigned' => TRUE,
  2218. 'size' => 'tiny',
  2219. 'not null' => TRUE,
  2220. 'default' => 1,
  2221. );
  2222. db_add_field('webform_emails', 'status', $spec);
  2223. }
  2224. return t('Webform emails may now be disabled.');
  2225. }
  2226. /**
  2227. * Preserve progress bar as not active for one-page webforms.
  2228. */
  2229. function webform_update_7431() {
  2230. // Get a list of all Webforms containing a pagebreak.
  2231. $multipage_webform_nids = db_select('webform_component');
  2232. $multipage_webform_nids->distinct();
  2233. $multipage_webform_nids->addField('webform_component', 'nid');
  2234. $multipage_webform_nids->condition('type', 'pagebreak');
  2235. // Remove confirmation page from the progress bar for single-page Webforms.
  2236. $updated_count = db_update('webform')
  2237. ->fields(array('progressbar_include_confirmation' => 0))
  2238. ->condition('preview', 0)
  2239. ->condition('nid', $multipage_webform_nids, 'NOT IN')
  2240. ->execute();
  2241. return t("Disabled progress bar for @count single-page webforms.", array('@count' => $updated_count));
  2242. }