mollom.install 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. <?php
  2. /**
  3. * @file
  4. * Install and uninstall functions as well as schema definition for the Mollom module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. *
  9. * @param $check
  10. * (optional) Boolean whether to re-check the module's installation and
  11. * configuration status. Defaults to TRUE, as this argument is not passed for
  12. * hook_requirements() by default. Passing FALSE allows other run-time code
  13. * to re-generate requirements error messages to be displayed on other pages
  14. * than the site's system status report page.
  15. *
  16. * @see mollom_init()
  17. * @see mollom_admin_settings()
  18. * @see _mollom_status()
  19. */
  20. function mollom_requirements($phase = 'runtime', $check = TRUE) {
  21. $requirements = array();
  22. if ($phase == 'runtime') {
  23. $status = _mollom_status($check);
  24. $requirements['mollom'] = array(
  25. 'title' => t('Mollom API keys'),
  26. 'value' => t('Valid (public key: @publicKey)', array(
  27. '@publicKey' => variable_get('mollom_public_key', ''),
  28. )),
  29. );
  30. // Immediately return if everything is in order.
  31. if ($status['isVerified']) {
  32. return $requirements;
  33. }
  34. // If not, something is wrong; prepare the requirements entry and set
  35. // defaults for any yet unknown edge-cases.
  36. $requirements['mollom']['severity'] = REQUIREMENT_ERROR;
  37. // Append a link to the settings page to the error message on all pages,
  38. // except on the settings page itself. These error messages also need to be
  39. // shown on the settings page, since Mollom API keys can be entered later.
  40. $admin_message = '';
  41. if ($_GET['q'] != 'admin/config/content/mollom/settings') {
  42. $admin_message = t('Visit the <a href="@settings-url">Mollom settings page</a> to configure your keys.', array(
  43. '@settings-url' => url('admin/config/content/mollom/settings'),
  44. ));
  45. }
  46. // Generate an appropriate error message:
  47. // If testing mode is enabled, then the Testing API is most likely down,
  48. // since the testing client implementation automatically tries to recover
  49. // from stale/outdated API keys.
  50. if (variable_get('mollom_testing_mode', 0)) {
  51. $requirements['mollom']['value'] = t('Testing API not available');
  52. $requirements['mollom']['description'] = t('The Mollom Testing API is not available currently.');
  53. }
  54. // Missing API keys.
  55. elseif (!$status['isConfigured']) {
  56. $requirements['mollom']['value'] = t('Not configured');
  57. $requirements['mollom']['description'] = t('The Mollom API keys are not configured yet. !admin-message', array(
  58. '!admin-message' => $admin_message,
  59. ));
  60. }
  61. // Bad request: Invalid client system time: Too large offset from UTC.
  62. elseif ($status['response'] === Mollom::REQUEST_ERROR) {
  63. $requirements['mollom']['value'] = t('Client error');
  64. $requirements['mollom']['description'] = t('The server time of this site is incorrect. The time of the operating system is not synchronized with the Coordinated Universal Time (UTC), which prevents a successful authentication with Mollom. The maximum allowed offset is @minutes minutes. Please consult your hosting provider or server operator to correct the server time.', array(
  65. '@minutes' => Mollom::TIME_OFFSET_MAX / 60,
  66. ));
  67. }
  68. // Invalid API keys.
  69. elseif ($status['response'] === Mollom::AUTH_ERROR) {
  70. $requirements['mollom']['value'] = t('Invalid');
  71. $requirements['mollom']['description'] = t('The configured Mollom API keys are invalid. !admin-message', array(
  72. '!admin-message' => $admin_message,
  73. ));
  74. }
  75. // Communication error.
  76. elseif ($status['response'] === Mollom::NETWORK_ERROR) {
  77. $requirements['mollom']['value'] = t('Network error');
  78. $requirements['mollom']['description'] = t('The Mollom servers could not be contacted. Please make sure that your web server can make outgoing HTTP requests.');
  79. }
  80. // Server error.
  81. elseif ($status['response'] === Mollom::RESPONSE_ERROR) {
  82. $requirements['mollom']['value'] = t('Service error');
  83. $requirements['mollom']['description'] = t('The Mollom API keys could not be verified. Please try again later.');
  84. }
  85. // 404, etc.
  86. else {
  87. $requirements['mollom']['value'] = t('Unknown error');
  88. $requirements['mollom']['description'] = t('The Mollom servers could be contacted, but Mollom API keys could not be verified.');
  89. }
  90. }
  91. return $requirements;
  92. }
  93. /**
  94. * Implements hook_schema().
  95. */
  96. function mollom_schema() {
  97. $schema['mollom'] = array(
  98. 'description' => 'Stores Mollom responses for content.',
  99. 'fields' => array(
  100. 'entity' => array(
  101. 'description' => 'Entity type of the content.',
  102. 'type' => 'varchar',
  103. 'length' => 32,
  104. 'not null' => TRUE,
  105. 'default' => '',
  106. ),
  107. 'id' => array(
  108. 'description' => 'Unique entity ID of the content.',
  109. 'type' => 'varchar',
  110. 'length' => 36,
  111. 'not null' => TRUE,
  112. 'default' => '',
  113. ),
  114. 'content_id' => array(
  115. 'description' => 'Content ID returned by Mollom.',
  116. 'type' => 'varchar',
  117. 'length' => 128,
  118. 'not null' => TRUE,
  119. 'default' => '',
  120. ),
  121. 'captcha_id' => array(
  122. 'description' => 'CAPTCHA ID returned by Mollom.',
  123. 'type' => 'varchar',
  124. 'length' => 128,
  125. 'not null' => TRUE,
  126. 'default' => '',
  127. ),
  128. 'form_id' => array(
  129. 'description' => 'The form_id of the form being protected.',
  130. 'type' => 'varchar',
  131. 'length' => 255,
  132. 'not null' => TRUE,
  133. 'default' => '',
  134. ),
  135. 'changed' => array(
  136. 'description' => 'Unix timestamp when the data was changed.',
  137. 'type' => 'int',
  138. 'not null' => TRUE,
  139. 'default' => 0,
  140. ),
  141. 'moderate' => array(
  142. 'description' => 'Whether the content needs to be moderated.',
  143. 'type' => 'int',
  144. 'size' => 'tiny',
  145. 'not null' => TRUE,
  146. 'default' => 0,
  147. ),
  148. // Server response columns are NULL by default, because any default value
  149. // would have an unintended meaning. Also, values are stored in individual
  150. // columns, so as to be able to join and filter/sort on these values for
  151. // improved content moderation.
  152. 'spam_score' => array(
  153. 'description' => 'Text analysis spam check result.',
  154. 'type' => 'float',
  155. 'size' => 'tiny',
  156. 'not null' => FALSE,
  157. ),
  158. 'spam_classification' => array(
  159. 'description' => 'Text analysis final spam classification result.',
  160. 'type' => 'varchar',
  161. 'length' => 16,
  162. 'not null' => FALSE,
  163. ),
  164. 'solved' => array(
  165. 'description' => 'Whether a CAPTCHA has been solved (1) or not (0).',
  166. 'type' => 'int',
  167. 'size' => 'tiny',
  168. 'not null' => FALSE,
  169. ),
  170. 'quality_score' => array(
  171. 'description' => 'Text analysis quality check result.',
  172. 'type' => 'float',
  173. 'size' => 'tiny',
  174. 'not null' => FALSE,
  175. ),
  176. 'profanity_score' => array(
  177. 'description' => 'Text analysis profanity check result.',
  178. 'type' => 'float',
  179. 'size' => 'tiny',
  180. 'not null' => FALSE,
  181. ),
  182. 'reason' => array(
  183. 'description' => 'A special reason for why a post was blocked.',
  184. 'type' => 'varchar',
  185. 'length' => 255,
  186. 'not null' => TRUE,
  187. 'default' => '',
  188. ),
  189. 'languages' => array(
  190. 'description' => 'Text analysis language check result.',
  191. 'type' => 'varchar',
  192. 'length' => 255,
  193. 'not null' => TRUE,
  194. 'default' => '',
  195. ),
  196. 'flags_spam' => array(
  197. 'description' => 'Count of spam feedback reports.',
  198. 'type' => 'int',
  199. 'size' => 'medium',
  200. 'not null' => TRUE,
  201. 'default' => 0,
  202. ),
  203. 'flags_ham' => array(
  204. 'description' => 'Count of ham feedback reports.',
  205. 'type' => 'int',
  206. 'size' => 'medium',
  207. 'not null' => TRUE,
  208. 'default' => 0,
  209. ),
  210. 'flags_profanity' => array(
  211. 'description' => 'Count of profanity feedback reports.',
  212. 'type' => 'int',
  213. 'size' => 'medium',
  214. 'not null' => TRUE,
  215. 'default' => 0,
  216. ),
  217. 'flags_quality' => array(
  218. 'description' => 'Count of low quality feedback reports.',
  219. 'type' => 'int',
  220. 'size' => 'medium',
  221. 'not null' => TRUE,
  222. 'default' => 0,
  223. ),
  224. 'flags_unwanted' => array(
  225. 'description' => 'Count of unwanted feedback reports.',
  226. 'type' => 'int',
  227. 'size' => 'medium',
  228. 'not null' => TRUE,
  229. 'default' => 0,
  230. ),
  231. ),
  232. 'indexes' => array(
  233. 'content_id' => array('content_id'),
  234. 'captcha_id' => array('captcha_id'),
  235. ),
  236. 'primary key' => array('entity', 'id'),
  237. 'foreign keys' => array(
  238. 'mollom_form_id' => array(
  239. 'table' => 'mollom_form',
  240. 'columns' => array(
  241. 'form_id' => 'form_id',
  242. ),
  243. ),
  244. ),
  245. );
  246. $schema['mollom_form'] = array(
  247. 'description' => 'Stores configuration of forms protected by Mollom.',
  248. 'fields' => array(
  249. 'form_id' => array(
  250. 'description' => 'The protected form ID.',
  251. 'type' => 'varchar',
  252. 'length' => 255,
  253. 'not null' => TRUE,
  254. 'default' => '',
  255. ),
  256. // Optional entity type and bundle columns are required for protected
  257. // entity forms, in order to determine whether report options should
  258. // appear on a delete confirmation form. Column lengths are copied from
  259. // {field_config_instance}.
  260. // @see field_schema()
  261. 'entity' => array(
  262. 'description' => 'Optional: Entity type of the form.',
  263. 'type' => 'varchar',
  264. 'length' => 32,
  265. 'not null' => FALSE,
  266. ),
  267. 'bundle' => array(
  268. 'description' => 'Optional: Entity bundle of the form.',
  269. 'type' => 'varchar',
  270. 'length' => 128,
  271. 'not null' => FALSE,
  272. ),
  273. 'mode' => array(
  274. 'description' => 'Protection mode for the form.',
  275. 'type' => 'int',
  276. 'size' => 'tiny',
  277. 'not null' => TRUE,
  278. 'default' => 0,
  279. ),
  280. 'checks' => array(
  281. 'description' => 'Text analyis checks to perform.',
  282. 'type' => 'text',
  283. 'not null' => FALSE,
  284. 'serialize' => TRUE,
  285. ),
  286. 'unsure' => array(
  287. 'description' => 'Action to perform when text analysis is unsure.',
  288. 'type' => 'varchar',
  289. 'length' => 24,
  290. 'not null' => TRUE,
  291. 'default' => 'captcha',
  292. ),
  293. 'discard' => array(
  294. 'description' => 'Whether to discard (1) or retain (0) bad posts.',
  295. 'type' => 'int',
  296. 'size' => 'tiny',
  297. 'not null' => TRUE,
  298. 'default' => 1,
  299. ),
  300. 'moderation' => array(
  301. 'description' => 'Whether to integrate with Mollom moderation - DEPRECATED',
  302. 'type' => 'int',
  303. 'size' => 'tiny',
  304. 'not null' => TRUE,
  305. 'default' => 0,
  306. ),
  307. 'enabled_fields' => array(
  308. 'description' => 'Form elements to analyze.',
  309. 'type' => 'text',
  310. 'not null' => FALSE,
  311. 'serialize' => TRUE,
  312. ),
  313. 'strictness' => array(
  314. 'description' => 'Strictness of text analysis checks.',
  315. 'type' => 'varchar',
  316. 'length' => 8,
  317. 'not null' => TRUE,
  318. 'default' => 'normal',
  319. ),
  320. 'module' => array(
  321. 'description' => 'Module name owning the form.',
  322. 'type' => 'varchar',
  323. 'length' => 255,
  324. 'not null' => TRUE,
  325. 'default' => '',
  326. ),
  327. ),
  328. 'primary key' => array('form_id'),
  329. );
  330. return $schema;
  331. }
  332. /**
  333. * Implements hook_install().
  334. */
  335. function mollom_install() {
  336. // Point the user to Mollom's settings page after installation.
  337. $requirements = mollom_requirements('runtime', FALSE);
  338. drupal_set_message($requirements['mollom']['description'], 'warning');
  339. }
  340. /**
  341. * Implements hook_uninstall().
  342. */
  343. function mollom_uninstall() {
  344. db_delete('variable')->condition('name', db_like('mollom_') . '%', 'LIKE')->execute();
  345. cache_clear_all('mollom', 'cache', TRUE);
  346. }
  347. /**
  348. * An update function to add the language field.
  349. */
  350. function mollom_update_1() {
  351. db_add_field('mollom', 'languages', array(
  352. 'description' => 'Text analysis language check result.',
  353. 'type' => 'varchar',
  354. 'length' => 255,
  355. 'not null' => TRUE,
  356. 'default' => '',
  357. ));
  358. }
  359. /**
  360. * Create the cache_mollom table.
  361. */
  362. function mollom_update_2() {
  363. $schema = drupal_get_schema_unprocessed('system', 'cache');
  364. db_create_table('cache_mollom', $schema);
  365. }
  366. /**
  367. * Upgrade form protection storage.
  368. */
  369. function mollom_update_3() {
  370. // Load hook_mollom_form_info() implementations for mollom_form_list().
  371. foreach (module_list(FALSE, FALSE) as $module) {
  372. drupal_load('module', $module);
  373. }
  374. drupal_load('module', 'mollom');
  375. foreach (mollom_form_list() as $form_id => $info) {
  376. $name = 'mollom_' . $form_id;
  377. $mode = variable_get($name, NULL);
  378. // $mode was stored as 1; convert to MOLLOM_MODE_ANALYSIS.
  379. if (isset($mode)) {
  380. variable_set($name, 2);
  381. }
  382. }
  383. }
  384. /**
  385. * Add a reputation field to the mollom table.
  386. */
  387. function mollom_update_4() {
  388. // Unused. Removed in mollom_update_7005().
  389. }
  390. /**
  391. * Add the {mollom_form} table.
  392. */
  393. function mollom_update_6105() {
  394. if (db_table_exists('mollom_form')) {
  395. return;
  396. }
  397. $schema = array(
  398. 'fields' => array(
  399. 'form_id' => array(
  400. 'description' => 'The protected form ID.',
  401. 'type' => 'varchar',
  402. 'length' => 255,
  403. 'not null' => TRUE,
  404. 'default' => '',
  405. ),
  406. 'mode' => array(
  407. 'description' => 'Protection mode for the form.',
  408. 'type' => 'int',
  409. 'size' => 'tiny',
  410. 'not null' => TRUE,
  411. 'default' => 0,
  412. ),
  413. 'enabled_fields' => array(
  414. 'description' => 'Form elements to analyze.',
  415. 'type' => 'text',
  416. 'serialize' => TRUE,
  417. ),
  418. 'module' => array(
  419. 'description' => 'Module name owning the form.',
  420. 'type' => 'varchar',
  421. 'length' => 255,
  422. 'not null' => TRUE,
  423. 'default' => '',
  424. ),
  425. ),
  426. 'primary key' => array('form_id'),
  427. );
  428. db_create_table('mollom_form', $schema);
  429. // Migrate form configuration for enabled, supported modules.
  430. foreach (module_list(FALSE, FALSE) as $module) {
  431. drupal_load('module', $module);
  432. }
  433. drupal_load('module', 'mollom');
  434. $form_list = mollom_form_list();
  435. $result = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'mollom_%%' AND name NOT IN ('mollom_servers', 'mollom_fallback', 'mollom_public_key', 'mollom_private_key')");
  436. foreach ($result as $row) {
  437. $form_id = substr($row->name, 7);
  438. $mode = unserialize($row->value);
  439. if (!empty($mode) && isset($form_list[$form_id])) {
  440. $info = $form_list[$form_id];
  441. $info += mollom_form_info($form_id, $info['module']);
  442. if ($mode == MOLLOM_MODE_ANALYSIS && isset($info['elements']) && is_array($info['elements'])) {
  443. $info['enabled_fields'] = array_keys($info['elements']);
  444. }
  445. else {
  446. $info['enabled_fields'] = array();
  447. }
  448. db_insert('mollom_form')
  449. ->fields(array(
  450. 'form_id' => $form_id,
  451. 'mode' => $mode,
  452. 'enabled_fields' => serialize($info['enabled_fields']),
  453. 'module' => $info['module'],
  454. ))
  455. ->execute();
  456. }
  457. variable_del($row->name);
  458. }
  459. }
  460. /**
  461. * Add the {mollom}.form_id column.
  462. */
  463. function mollom_update_6106() {
  464. if (db_field_exists('mollom', 'entity')) {
  465. return;
  466. }
  467. // Add the 'entity' column.
  468. db_add_field('mollom', 'entity', array(
  469. 'description' => 'Entity type of the content.',
  470. 'type' => 'varchar',
  471. 'length' => 32,
  472. 'not null' => TRUE,
  473. 'default' => '',
  474. ));
  475. // Change the primary key to prevent duplicate key errors in the following
  476. // data conversions.
  477. db_drop_primary_key('mollom');
  478. db_add_primary_key('mollom', array('entity', 'did'));
  479. // Migrate existing node data.
  480. db_update('mollom')
  481. ->fields(array('entity' => 'node'))
  482. ->condition('did', 'node-%', 'LIKE')
  483. ->execute();
  484. db_update('mollom')
  485. ->expression('did', 'SUBSTR(did, 6)')
  486. ->condition('entity', 'node')
  487. ->execute();
  488. // Migrate existing comment data.
  489. db_update('mollom')
  490. ->fields(array('entity' => 'comment'))
  491. ->condition('did', 'comment-%', 'LIKE')
  492. ->execute();
  493. db_update('mollom')
  494. ->expression('did', 'SUBSTR(did, 9)')
  495. ->condition('entity', 'comment')
  496. ->execute();
  497. // Decrease the size of the 'did' column.
  498. // @todo We do not change the type to 'int' here to still support named
  499. // identifiers. Reconsider this.
  500. db_change_field('mollom', 'did', 'did', array(
  501. 'description' => 'Unique entity ID of the content.',
  502. 'type' => 'varchar',
  503. 'length' => 32,
  504. 'not null' => TRUE,
  505. 'default' => '',
  506. ));
  507. }
  508. /**
  509. * Disable the privacy policy link for existing sites by default.
  510. */
  511. function mollom_update_6107() {
  512. variable_set('mollom_privacy_link', 0);
  513. }
  514. /**
  515. * Rename 'post with no checking' permission to 'bypass mollom protection'.
  516. */
  517. function mollom_update_6108() {
  518. db_update('role_permission')
  519. ->fields(array('permission' => 'bypass mollom protection'))
  520. ->condition('permission', 'post with no checking')
  521. ->execute();
  522. }
  523. /**
  524. * Rename 'fields' column to 'enabled_fields'; previously introduced in mollom_update_6105().
  525. *
  526. * 'fields' is a reserved keyword in MySQL.
  527. */
  528. function mollom_update_6109() {
  529. if (db_field_exists('mollom_form', 'fields')) {
  530. db_change_field('mollom_form', 'fields', 'enabled_fields', array(
  531. 'description' => 'Form elements to analyze.',
  532. 'type' => 'text',
  533. 'serialize' => TRUE,
  534. ));
  535. }
  536. }
  537. /**
  538. * Automatically update the new 'mollom_status' variable.
  539. *
  540. * _mollom_status() was introduced in 6.x-1.11 to prevent Mollom from
  541. * interfering with forms when it is incorrectly configured. Sites updating from
  542. * previous versions should be correctly configured, so we just invoke it here.
  543. */
  544. function mollom_update_6110() {
  545. drupal_load('module', 'mollom');
  546. _mollom_status(TRUE);
  547. }
  548. /**
  549. * Fix enabled_fields array for CAPTCHA-only protected forms.
  550. *
  551. * mollom_update_6105() incorrectly stored enabled_fields values for forms
  552. * protected by CAPTCHAs only.
  553. */
  554. function mollom_update_6111() {
  555. db_update('mollom_form')
  556. ->fields(array(
  557. 'enabled_fields' => serialize(array()),
  558. ))
  559. ->condition('mode', 1)
  560. ->execute();
  561. }
  562. /**
  563. * Migrate form configuration for changed form ids in Drupal 7.
  564. */
  565. function mollom_update_7000() {
  566. // 'user_register' became 'user_register_form'.
  567. db_update('mollom_form')
  568. ->fields(array('form_id' => 'user_register_form'))
  569. ->condition('form_id', 'user_register')
  570. ->execute();
  571. // 'contact_mail_page' became 'contact_site_form'.
  572. db_update('mollom_form')
  573. ->fields(array('form_id' => 'contact_site_form'))
  574. ->condition('form_id', 'contact_mail_page')
  575. ->execute();
  576. // 'contact_mail_user' became 'contact_personal_form'.
  577. db_update('mollom_form')
  578. ->fields(array('form_id' => 'contact_personal_form'))
  579. ->condition('form_id', 'contact_mail_user')
  580. ->execute();
  581. }
  582. /**
  583. * Remove the {cache_mollom} table.
  584. */
  585. function mollom_update_7001() {
  586. db_drop_table('cache_mollom');
  587. }
  588. /**
  589. * Add {mollom}.changed column to auto-flush expired entries.
  590. */
  591. function mollom_update_7002() {
  592. if (!db_field_exists('mollom', 'changed')) {
  593. db_add_field('mollom', 'changed', array(
  594. 'description' => 'Unix timestamp when the data was changed.',
  595. 'type' => 'int',
  596. 'not null' => TRUE,
  597. 'default' => 0,
  598. ));
  599. }
  600. }
  601. /**
  602. * Add {mollom_form}.data to store the individual form configuration.
  603. */
  604. function mollom_update_7003() {
  605. // Removed in mollom_update_7004().
  606. }
  607. /**
  608. * Replace {mollom_form}.data with {mollom_form}.checks.
  609. */
  610. function mollom_update_7004() {
  611. // Add {mollom_form}.checks.
  612. if (!db_field_exists('mollom_form', 'checks')) {
  613. db_add_field('mollom_form', 'checks', array(
  614. 'description' => 'Text analyis checks to perform.',
  615. 'type' => 'text',
  616. 'not null' => FALSE,
  617. 'serialize' => TRUE,
  618. ));
  619. // Default all checks to 'spam', including CAPTCHA-only rows, so spam
  620. // checking is enabled by default when switching the protection mode.
  621. db_update('mollom_form')
  622. ->fields(array(
  623. 'checks' => serialize(array('spam')),
  624. ))
  625. ->execute();
  626. }
  627. // Migrate {mollom_form}.data to {mollom_form}.checks.
  628. if (db_field_exists('mollom_form', 'data')) {
  629. // Add profanity checking flag where enabled.
  630. db_update('mollom_form')
  631. ->fields(array(
  632. 'checks' => serialize(array('spam', 'profanity'))
  633. ))
  634. ->condition('data', serialize(array('profanity' => '1')))
  635. ->execute();
  636. // Remove {mollom_form}.data.
  637. db_drop_field('mollom_form', 'data');
  638. }
  639. }
  640. /**
  641. * Clean up and complete server response columns in {mollom}.
  642. */
  643. function mollom_update_7005() {
  644. // Remove 'reputation' column introduced in mollom_update_4(); unused.
  645. if (db_field_exists('mollom', 'reputation')) {
  646. db_drop_field('mollom', 'reputation');
  647. }
  648. // Change {mollom}.quality from varchar into float.
  649. // Since some data rows are using an empty string to denote no 'quality'
  650. // value, we need to insert a temporary value that is converted to NULL
  651. // afterwards.
  652. // When upgrading from 6.x-2.x, this is {mollom}.qualityScore {mollom}.quality_score already.
  653. if (db_field_exists('mollom', 'quality')) {
  654. db_update('mollom')
  655. ->fields(array('quality' => 9))
  656. ->condition('quality', '')
  657. ->execute();
  658. db_change_field('mollom', 'quality', 'quality', array(
  659. 'description' => 'Text analysis quality check result.',
  660. 'type' => 'float',
  661. 'size' => 'tiny',
  662. 'not null' => FALSE,
  663. ));
  664. db_update('mollom')
  665. ->fields(array('quality' => NULL))
  666. ->condition('quality', 9)
  667. ->execute();
  668. }
  669. // Add {mollom}.spam.
  670. // When upgrading from 6.x-2.x, this is {mollom}.spamScore or {mollom}.spam_score already.
  671. if (!db_field_exists('mollom', 'spam') && !db_field_exists('mollom', 'spamScore') && !db_field_exists('mollom', 'spam_score')) {
  672. db_add_field('mollom', 'spam', array(
  673. 'description' => 'Text analysis spam check result.',
  674. 'type' => 'int',
  675. 'size' => 'tiny',
  676. 'not null' => FALSE,
  677. ));
  678. // Fill {mollom}.spam with approximate values based on {mollom}.quality.
  679. // Note that this is just to have some values. 'quality' and 'spam' are
  680. // completely unrelated otherwise.
  681. // MOLLOM_ANALYSIS_SPAM (2)
  682. if (db_field_exists('mollom', 'quality')) {
  683. $quality = 'quality';
  684. } else {
  685. $quality = 'quality_score';
  686. }
  687. db_update('mollom')
  688. ->fields(array('spam' => 2))
  689. ->condition($quality, 0.5, '<')
  690. ->execute();
  691. // MOLLOM_ANALYSIS_UNSURE (3)
  692. db_update('mollom')
  693. ->fields(array('spam' => 3))
  694. ->condition($quality, 0.5, '=')
  695. ->execute();
  696. // MOLLOM_ANALYSIS_HAM (1)
  697. db_update('mollom')
  698. ->fields(array('spam' => 1))
  699. ->condition($quality, 0.5, '>')
  700. ->execute();
  701. }
  702. // Add {mollom}.profanity.
  703. // When upgrading from 6.x-2.x, this is {mollom}.profanityScore or {mollom}.profanity_score already.
  704. if (!db_field_exists('mollom', 'profanity') && !db_field_exists('mollom', 'profanityScore') && !db_field_exists('mollom', 'profanity_score')) {
  705. db_add_field('mollom', 'profanity', array(
  706. 'description' => 'Text analysis profanity check result.',
  707. 'type' => 'float',
  708. 'size' => 'tiny',
  709. 'not null' => FALSE,
  710. ));
  711. }
  712. }
  713. /**
  714. * Update for changed comment form IDs.
  715. *
  716. * The comment form will be protected for all node types, since it is not
  717. * possible to determine, on which nodes or node types comments are actually
  718. * enabled.
  719. */
  720. function mollom_update_7006() {
  721. // Skip this update in case comment_form is not protected.
  722. $mollom_form = db_query('SELECT * FROM {mollom_form} WHERE form_id = :form_id', array(':form_id' => 'comment_form'))->fetchAssoc();
  723. if (!$mollom_form) {
  724. return;
  725. }
  726. // Retrieve available node types.
  727. $types = db_query('SELECT type FROM {node_type}');
  728. // Check first for manually performed updates or re-configuration.
  729. $form_ids = array();
  730. foreach ($types as $type) {
  731. $form_ids["comment_node_{$type->type}_form"] = $type->type;
  732. }
  733. if ($form_ids) {
  734. $existing = db_query('SELECT form_id FROM {mollom_form} WHERE form_id IN (:form_ids)', array(':form_ids' => array_keys($form_ids)));
  735. foreach ($existing as $row) {
  736. unset($form_ids[$row->form_id]);
  737. }
  738. }
  739. // 'comment' (body) field is now a 'comment_body' Field API field.
  740. $enabled_fields = unserialize($mollom_form['enabled_fields']);
  741. if (is_array($enabled_fields) && ($i = array_search('comment', $enabled_fields))) {
  742. $enabled_fields[$i] = 'comment_body';
  743. $mollom_form['enabled_fields'] = serialize($enabled_fields);
  744. }
  745. // Duplicate comment_form row into comment_node_TYPE_form rows by
  746. // inserting settings for any remaining node types.
  747. foreach ($form_ids as $form_id => $type) {
  748. $mollom_form['form_id'] = $form_id;
  749. db_insert('mollom_form')
  750. ->fields($mollom_form)
  751. ->execute();
  752. }
  753. // Delete the obselete row.
  754. db_delete('mollom_form')
  755. ->condition('form_id', 'comment_form')
  756. ->execute();
  757. }
  758. /**
  759. * Add {mollom}.form_id column to look up the originating form_id for an entity.
  760. */
  761. function mollom_update_7007() {
  762. // All Mollom data record modifications have been removed from this update,
  763. // since mollom_update_7200() truncates the {mollom} table either way.
  764. if (!db_field_exists('mollom', 'form_id')) {
  765. db_add_field('mollom', 'form_id', array(
  766. 'description' => 'The form_id of the form being protected.',
  767. 'type' => 'varchar',
  768. 'length' => 255,
  769. 'not null' => TRUE,
  770. 'default' => '',
  771. ));
  772. }
  773. }
  774. /**
  775. * Rename {mollom}.did to .id, and {mollom}.session to .session_id.
  776. */
  777. function mollom_update_7008() {
  778. if (!db_field_exists('mollom', 'id')) {
  779. db_drop_primary_key('mollom');
  780. db_change_field('mollom', 'did', 'id', array(
  781. 'description' => 'Unique entity ID of the content.',
  782. 'type' => 'varchar',
  783. 'length' => 32,
  784. 'not null' => TRUE,
  785. 'default' => '',
  786. ));
  787. db_add_primary_key('mollom', array('entity', 'id'));
  788. }
  789. // When upgrading from 6.x-2.x, this is {mollom}.contentId or {mollom}.content_id already.
  790. if (db_index_exists('mollom', 'session')) {
  791. db_drop_index('mollom', 'session');
  792. }
  793. if (db_field_exists('mollom', 'session') && !db_field_exists('mollom', 'session_id') && !db_field_exists('mollom', 'contentId') && !db_field_exists('mollom', 'content_id')) {
  794. db_change_field('mollom', 'session', 'session_id', array(
  795. 'description' => 'Session hash returned by Mollom.',
  796. 'type' => 'varchar',
  797. 'length' => 255,
  798. 'not null' => TRUE,
  799. 'default' => '',
  800. ));
  801. db_add_index('mollom', 'session_id', array('session_id'));
  802. }
  803. }
  804. /**
  805. * Add {mollom_form}.discard and {mollom}.moderate columns.
  806. */
  807. function mollom_update_7009() {
  808. if (!db_field_exists('mollom_form', 'discard')) {
  809. db_add_field('mollom_form', 'discard', array(
  810. 'description' => 'Whether to discard (1) or retain (0) bad posts.',
  811. 'type' => 'int',
  812. 'size' => 'tiny',
  813. 'not null' => TRUE,
  814. 'default' => 1,
  815. ));
  816. }
  817. if (!db_field_exists('mollom', 'moderate')) {
  818. db_add_field('mollom', 'moderate', array(
  819. 'description' => 'Whether the content needs to be moderated.',
  820. 'type' => 'int',
  821. 'size' => 'tiny',
  822. 'not null' => TRUE,
  823. 'default' => 0,
  824. ));
  825. }
  826. }
  827. /**
  828. * Add {mollom_form}.strictness column.
  829. */
  830. function mollom_update_7010() {
  831. if (!db_field_exists('mollom_form', 'strictness')) {
  832. db_add_field('mollom_form', 'strictness', array(
  833. 'description' => 'Strictness of text analysis checks.',
  834. 'type' => 'varchar',
  835. 'length' => 8,
  836. 'not null' => TRUE,
  837. 'default' => 'normal',
  838. ));
  839. }
  840. }
  841. /**
  842. * Fix default value of {mollom_form}.strictness.
  843. */
  844. function mollom_update_7011() {
  845. db_change_field('mollom_form', 'strictness', 'strictness', array(
  846. 'description' => 'Strictness of text analysis checks.',
  847. 'type' => 'varchar',
  848. 'length' => 8,
  849. 'not null' => TRUE,
  850. 'default' => 'normal',
  851. ));
  852. db_update('mollom_form')
  853. ->condition('strictness', 'medium')
  854. ->fields(array('strictness' => 'normal'))
  855. ->execute();
  856. }
  857. /**
  858. * Change {mollom}: Add 'spamClassification', change 'spam', replace 'session_id' with 'contentId' and 'captchaId'.
  859. */
  860. function mollom_update_7200() {
  861. variable_del('mollom_servers');
  862. if (db_index_exists('mollom', 'session_id')) {
  863. db_drop_index('mollom', 'session_id');
  864. }
  865. // When upgrading from 6.x-2.x, this is {mollom}.contentId or {mollom}.content_id and {mollom}.captchaId and {mollom}.captcha_id already.
  866. if (db_field_exists('mollom', 'session_id') && !db_field_exists('mollom', 'contentId') && !db_field_exists('mollom', 'content_id') && !db_field_exists('mollom', 'captchaId') && !db_field_exists('mollom', 'captcha_id')) {
  867. // Truncate table. Old session IDs cannot be migrated.
  868. db_truncate('mollom')->execute();
  869. // Remove 'session_id'.
  870. db_drop_field('mollom', 'session_id');
  871. // Add 'contentId' and 'captchaId'.
  872. db_add_field('mollom', 'contentId', array(
  873. 'description' => 'Content ID returned by Mollom.',
  874. 'type' => 'varchar',
  875. 'length' => 128,
  876. 'not null' => TRUE,
  877. 'default' => '',
  878. ));
  879. db_add_field('mollom', 'captchaId', array(
  880. 'description' => 'CAPTCHA ID returned by Mollom.',
  881. 'type' => 'varchar',
  882. 'length' => 128,
  883. 'not null' => TRUE,
  884. 'default' => '',
  885. ));
  886. db_add_index('mollom', 'contentId', array('contentId'));
  887. db_add_index('mollom', 'captchaId', array('captchaId'));
  888. }
  889. // Add 'spamClassification'.
  890. // When upgrading from 6.x-2.x, this is {mollom}.spamClassification or {mollom}.spam_classification already.
  891. if (!db_field_exists('mollom', 'spamClassification') && !db_field_exists('mollom', 'spam_classification')) {
  892. db_add_field('mollom', 'spamClassification', array(
  893. 'description' => 'Text analysis final spam classification result.',
  894. 'type' => 'varchar',
  895. 'length' => 16,
  896. 'not null' => FALSE,
  897. ));
  898. }
  899. // Change 'spam' into 'spamScore' double.
  900. if (db_field_exists('mollom', 'spam') && !db_field_exists('mollom', 'spamScore') && !db_field_exists('mollom', 'spam_score')) {
  901. db_change_field('mollom', 'spam', 'spamScore', array(
  902. 'description' => 'Text analysis spam check result.',
  903. 'type' => 'float',
  904. 'size' => 'tiny',
  905. 'not null' => FALSE,
  906. ));
  907. }
  908. // Change 'profanity' into 'profanityScore' double.
  909. if (db_field_exists('mollom', 'profanity') && !db_field_exists('mollom', 'profanityScore') && !db_field_exists('mollom', 'profanity_score')) {
  910. db_change_field('mollom', 'profanity', 'profanityScore', array(
  911. 'description' => 'Text analysis profanity check result.',
  912. 'type' => 'float',
  913. 'size' => 'tiny',
  914. 'not null' => FALSE,
  915. ));
  916. }
  917. // Change 'quality' into 'qualityScore' double.
  918. if (db_field_exists('mollom', 'quality') && !db_field_exists('mollom', 'qualityScore') && !db_field_exists('mollom', 'quality_score')) {
  919. db_change_field('mollom', 'quality', 'qualityScore', array(
  920. 'description' => 'Text analysis quality check result.',
  921. 'type' => 'float',
  922. 'size' => 'tiny',
  923. 'not null' => FALSE,
  924. ));
  925. }
  926. // Add 'solved'.
  927. if (!db_field_exists('mollom', 'solved')) {
  928. db_add_field('mollom', 'solved', array(
  929. 'description' => 'Whether a CAPTCHA has been solved (1) or not (0).',
  930. 'type' => 'int',
  931. 'size' => 'tiny',
  932. 'not null' => FALSE,
  933. ));
  934. }
  935. // Add 'reason'.
  936. if (!db_field_exists('mollom', 'reason')) {
  937. db_add_field('mollom', 'reason', array(
  938. 'description' => 'A special reason for why a post was blocked.',
  939. 'type' => 'varchar',
  940. 'length' => 255,
  941. 'not null' => TRUE,
  942. 'default' => '',
  943. ));
  944. }
  945. }
  946. /**
  947. * Enlarge {mollom}.id to fit contentId and captchaId returned by Mollom.
  948. */
  949. function mollom_update_7201() {
  950. db_change_field('mollom', 'id', 'id', array(
  951. 'description' => 'Unique entity ID of the content.',
  952. 'type' => 'varchar',
  953. 'length' => 36,
  954. 'not null' => TRUE,
  955. 'default' => '',
  956. ));
  957. }
  958. /**
  959. * Add {mollom_form}.moderation column.
  960. */
  961. function mollom_update_7202() {
  962. if (!db_field_exists('mollom_form', 'moderation')) {
  963. variable_del('mollom_moderation_integration');
  964. db_add_field('mollom_form', 'moderation', array(
  965. 'description' => 'Whether to integrate with Mollom moderation.',
  966. 'type' => 'int',
  967. 'size' => 'tiny',
  968. 'not null' => TRUE,
  969. 'default' => 0,
  970. ));
  971. }
  972. }
  973. /**
  974. * Remove server list variables.
  975. */
  976. function mollom_update_7203() {
  977. variable_del('mollom_servers');
  978. variable_del('mollom_test_servers');
  979. }
  980. /**
  981. * Remove corrupted Mollom data records.
  982. *
  983. * Due to a bug in the Mollom moderation system integration code, contentIds of
  984. * existing Mollom data records might have been overwritten with the contentId
  985. * of a new post; i.e., corrupted. These records lead to invalid contentId
  986. * lookup results now. Since the original contentIds are no longer available,
  987. * the corrupted Mollom data records have to be deleted.
  988. *
  989. * @see http://drupal.org/node/1470326
  990. */
  991. function mollom_update_7204() {
  992. // Ensure our core database layer bug workaround functions are loaded.
  993. drupal_load('module', 'mollom');
  994. // Find all Mollom data records with duplicate contentIds.
  995. if (db_field_exists('mollom', 'contentId')) {
  996. $contentIds = mollom_db_query('SELECT contentId FROM {mollom} GROUP BY contentId HAVING COUNT(contentId) > 1')->fetchCol();
  997. // If there are any, delete them.
  998. if (!empty($contentIds)) {
  999. db_delete('mollom')
  1000. ->condition('contentId', $contentIds)
  1001. ->execute();
  1002. }
  1003. }
  1004. else {
  1005. $content_ids = mollom_db_query('SELECT content_id FROM {mollom} GROUP BY content_id HAVING COUNT(content_id) > 1')->fetchCol();
  1006. // If there are any, delete them.
  1007. if (!empty($content_ids)) {
  1008. db_delete('mollom')
  1009. ->condition('content_id', $content_ids)
  1010. ->execute();
  1011. }
  1012. }
  1013. }
  1014. /**
  1015. * Add {mollom_form}.entity and .bundle fields.
  1016. */
  1017. function mollom_update_7205() {
  1018. if (!db_field_exists('mollom_form', 'entity')) {
  1019. db_add_field('mollom_form', 'entity', array(
  1020. 'description' => 'Optional: Entity type of the form.',
  1021. 'type' => 'varchar',
  1022. 'length' => 32,
  1023. 'not null' => FALSE,
  1024. ));
  1025. }
  1026. if (!db_field_exists('mollom_form', 'bundle')) {
  1027. db_add_field('mollom_form', 'bundle', array(
  1028. 'description' => 'Optional: Entity bundle of the form.',
  1029. 'type' => 'varchar',
  1030. 'length' => 128,
  1031. 'not null' => FALSE,
  1032. ));
  1033. }
  1034. // Populate entity type and bundle values for core entity types.
  1035. // Any other values for contributed entities need to be updated manually,
  1036. // which is possible by simply updating the form protection through the
  1037. // administration interface.
  1038. $result = db_query('SELECT form_id, module FROM {mollom_form}');
  1039. foreach ($result as $mollom_form) {
  1040. if ($mollom_form->module == 'node') {
  1041. $bundle = substr($mollom_form->form_id, 0, -strlen('_node_form'));
  1042. db_update('mollom_form')
  1043. ->condition('form_id', $mollom_form->form_id)
  1044. ->fields(array('entity' => 'node', 'bundle' => $bundle))
  1045. ->execute();
  1046. }
  1047. elseif ($mollom_form->module == 'comment') {
  1048. $bundle = substr($mollom_form->form_id, 0, -strlen('_form'));
  1049. db_update('mollom_form')
  1050. ->condition('form_id', $mollom_form->form_id)
  1051. ->fields(array('entity' => 'comment', 'bundle' => $bundle))
  1052. ->execute();
  1053. }
  1054. elseif ($mollom_form->module == 'user') {
  1055. db_update('mollom_form')
  1056. ->condition('form_id', $mollom_form->form_id)
  1057. ->fields(array('entity' => 'user', 'bundle' => 'user'))
  1058. ->execute();
  1059. }
  1060. }
  1061. }
  1062. /**
  1063. * Add {mollom_form}.unsure field.
  1064. */
  1065. function mollom_update_7206() {
  1066. if (!db_field_exists('mollom_form', 'unsure')) {
  1067. db_add_field('mollom_form', 'unsure', array(
  1068. 'description' => 'Action to perform when text analysis is unsure.',
  1069. 'type' => 'varchar',
  1070. 'length' => 24,
  1071. 'not null' => TRUE,
  1072. 'default' => 'captcha',
  1073. ));
  1074. }
  1075. }
  1076. /**
  1077. * Remove 'mollom_status' variable (replaced by cache).
  1078. */
  1079. function mollom_update_7207() {
  1080. variable_del('mollom_status');
  1081. }
  1082. /**
  1083. * Remove obsolete 'mollom_moderation_redirect' setting.
  1084. */
  1085. function mollom_update_7208() {
  1086. variable_del('mollom_moderation_redirect');
  1087. }
  1088. /**
  1089. * Correct the stored definition of enabled Field API fields.
  1090. */
  1091. function mollom_update_7209() {
  1092. $mollom_forms = db_query('SELECT form_id, enabled_fields FROM {mollom_form}')->fetchAllKeyed();
  1093. foreach ($mollom_forms as $form_id => $enabled_fields) {
  1094. $changed = FALSE;
  1095. $enabled_fields = unserialize($enabled_fields);
  1096. if (is_array($enabled_fields)) {
  1097. foreach ($enabled_fields as $i => $name) {
  1098. // Remove '][und][0][value' suffix from element name.
  1099. if (substr($name, -15) == '][und][0][value') {
  1100. $enabled_fields[$i] = substr($name, 0, -15);
  1101. $changed = TRUE;
  1102. }
  1103. }
  1104. }
  1105. if ($changed) {
  1106. db_update('mollom_form')
  1107. ->condition('form_id', $form_id)
  1108. ->fields(array('enabled_fields' => serialize($enabled_fields)))
  1109. ->execute();
  1110. }
  1111. }
  1112. }
  1113. /**
  1114. * Disable minimum log severity threshold for existing sites.
  1115. */
  1116. function mollom_update_7210() {
  1117. if (variable_get('mollom_log_minimum_severity', NULL) === NULL) {
  1118. variable_set('mollom_log_minimum_severity', WATCHDOG_INFO);
  1119. }
  1120. }
  1121. /**
  1122. * Add columns for "report as inapporpriate" counts.
  1123. */
  1124. function mollom_update_7211() {
  1125. if (!db_field_exists('mollom', 'flags_spam')) {
  1126. db_add_field('mollom', 'flags_spam', array(
  1127. 'description' => 'Count of spam feedback reports.',
  1128. 'type' => 'int',
  1129. 'size' => 'medium',
  1130. 'not null' => TRUE,
  1131. 'default' => 0,
  1132. ));
  1133. }
  1134. if (!db_field_exists('mollom', 'flags_ham')) {
  1135. db_add_field('mollom', 'flags_ham', array(
  1136. 'description' => 'Count of ham feedback reports.',
  1137. 'type' => 'int',
  1138. 'size' => 'medium',
  1139. 'not null' => TRUE,
  1140. 'default' => 0,
  1141. ));
  1142. }
  1143. if (!db_field_exists('mollom', 'flags_profanity')) {
  1144. db_add_field('mollom', 'flags_profanity', array(
  1145. 'description' => 'Count of profanity feedback reports.',
  1146. 'type' => 'int',
  1147. 'size' => 'medium',
  1148. 'not null' => TRUE,
  1149. 'default' => 0,
  1150. ));
  1151. }
  1152. if (!db_field_exists('mollom', 'flags_quality')) {
  1153. db_add_field('mollom', 'flags_quality', array(
  1154. 'description' => 'Count of low quality feedback reports.',
  1155. 'type' => 'int',
  1156. 'size' => 'medium',
  1157. 'not null' => TRUE,
  1158. 'default' => 0,
  1159. ));
  1160. }
  1161. if (!db_field_exists('mollom', 'flags_unwanted')) {
  1162. db_add_field('mollom', 'flags_unwanted', array(
  1163. 'description' => 'Count of unwanted feedback reports.',
  1164. 'type' => 'int',
  1165. 'size' => 'medium',
  1166. 'not null' => TRUE,
  1167. 'default' => 0,
  1168. ));
  1169. }
  1170. }
  1171. /**
  1172. * Set default variable values for advanced administration features.
  1173. *
  1174. * Note that some of these may have already been set in previous versions.
  1175. */
  1176. function mollom_update_7212() {
  1177. variable_set('mollom_log_minimum_severity', variable_get('mollom_log_minimum_severity', WATCHDOG_WARNING));
  1178. variable_set('mollom_audio_captcha_enabled', variable_get('mollom_audio_captcha_enabled', 1));
  1179. variable_set('mollom_connection_timeout', variable_get('mollom_connection_timeout', 3));
  1180. variable_set('mollom_fba_enabled', variable_get('mollom_fba_enabled', 0));
  1181. variable_set('mollom_fai_entity_types', variable_get('mollom_fai_entity_types', array('comment' => 'comment')));
  1182. variable_set('mollom_fai_dialog', variable_get('mollom_fai_dialog', 'mollom'));
  1183. }
  1184. /**
  1185. * Change all mixedCase database columns and indexes to underscore separated.
  1186. */
  1187. function mollom_update_7213() {
  1188. if (db_index_exists('mollom', 'contentId')) {
  1189. db_drop_index('mollom', 'contentId');
  1190. }
  1191. if (db_field_exists('mollom', 'contentId') && !db_field_exists('mollom', 'content_id')) {
  1192. db_change_field('mollom', 'contentId', 'content_id', array(
  1193. 'description' => 'Content ID returned by Mollom.',
  1194. 'type' => 'varchar',
  1195. 'length' => 128,
  1196. 'not null' => TRUE,
  1197. 'default' => '',
  1198. ));
  1199. db_add_index('mollom', 'content_id', array('content_id'));
  1200. }
  1201. if (db_index_exists('mollom', 'captchaId')) {
  1202. db_drop_index('mollom', 'captchaId');
  1203. }
  1204. if (db_field_exists('mollom', 'captchaId') && !db_field_exists('mollom', 'captcha_id')) {
  1205. db_change_field('mollom', 'captchaId', 'captcha_id', array(
  1206. 'description' => 'CAPTCHA ID returned by Mollom.',
  1207. 'type' => 'varchar',
  1208. 'length' => 128,
  1209. ));
  1210. db_add_index('mollom', 'captcha_id', array('captcha_id'));
  1211. }
  1212. if (db_field_exists('mollom', 'spamScore') && !db_field_exists('mollom', 'spam_score')) {
  1213. db_change_field('mollom', 'spamScore', 'spam_score', array(
  1214. 'description' => 'Text analysis spam check result.',
  1215. 'type' => 'float',
  1216. 'size' => 'tiny',
  1217. 'not null' => FALSE,
  1218. ));
  1219. }
  1220. if (db_field_exists('mollom', 'spamClassification') && !db_field_exists('mollom', 'spam_classification')) {
  1221. db_change_field('mollom', 'spamClassification', 'spam_classification', array(
  1222. 'description' => 'Test analysis final spam classification result.',
  1223. 'type' => 'varchar',
  1224. 'length' => 16,
  1225. ));
  1226. }
  1227. if (db_field_exists('mollom', 'qualityScore') && !db_field_exists('mollom', 'quality_score')) {
  1228. db_change_field('mollom', 'qualityScore', 'quality_score', array(
  1229. 'description' => 'Text analysis quality check result.',
  1230. 'type' => 'float',
  1231. 'size' => 'tiny',
  1232. 'not null' => FALSE,
  1233. ));
  1234. }
  1235. if (db_field_exists('mollom', 'profanityScore') && !db_field_exists('mollom', 'profanity_score')) {
  1236. db_change_field('mollom', 'profanityScore', 'profanity_score', array(
  1237. 'description' => 'Text analysis profanity check result.',
  1238. 'type' => 'float',
  1239. 'size' => 'tiny',
  1240. 'not null' => FALSE,
  1241. ));
  1242. }
  1243. }
  1244. /**
  1245. * Restrict access to the Mollom Content Moderation Platform to current users.
  1246. */
  1247. function mollom_update_7214() {
  1248. $uses_cmp = FALSE;
  1249. $result = db_query('SELECT moderation FROM {mollom_form}')->fetchCol();
  1250. foreach ($result as $moderation) {
  1251. if (!empty($moderation)) {
  1252. $uses_cmp = TRUE;
  1253. break;
  1254. }
  1255. }
  1256. if ($uses_cmp) {
  1257. variable_set('mollom_cmp_enabled', TRUE);
  1258. }
  1259. }
  1260. /**
  1261. * Remove Mollom Content Moderation Platform variables.
  1262. */
  1263. function mollom_update_7215() {
  1264. variable_del('mollom_cmp_enabled');
  1265. }