summaryrefslogtreecommitdiffstats
path: root/webform_multifile.install
blob: 863a691ec7f6185844cb48e0fa59a79ef3c10548 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
 * @file Webform multifile install functions.
 */

/**
 * Implements hook_requirements().
 */
function webform_multifile_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $t = get_t();
    $info = system_get_info('module', 'transliteration');
    $requirements['transliteration'] = array(
      'title' => $t('Transliteration'),
      'value' => $info['version'],
    );
    $version = explode('-', $info['version']);
    $version = explode('.', $version[1]);
    //check for latest dev version (format = 7.x-3.0+16-dev)
    if (((int)$version[0] <= 3) && !(strpos($version[1], '+') !== FALSE)) {
      //check version (format = 7.x-3.0)
      if (((int)$version[0] < 3) || ((int)$version[0] == 3 && (int)$version[1] <= 0)) {
        $requirements['transliteration']['description'] = $t('The Transliteration
          module\'s version needs to be 3.1 or higher. If that version is not yet
          available, you need to use Transliteration\'s latest dev version.');
        $requirements['transliteration']['severity'] = REQUIREMENT_ERROR;
      }
    }
  }
  return $requirements;
}

/**
 * Convert serialized php arrays to json encoded strings.
 */
function webform_multifile_update_7001(&$sandbox) {
  $q = db_select('webform_submitted_data', 'd')
      ->fields('d');
  $q->join('webform_component', 'c', 'c.cid = d.cid');
  $q->condition('c.type', 'multifile');
  if (!isset($sandbox['total'])) {
    $sandbox['current'] = 0;
    $sandbox['total'] = $q->countQuery()->execute()->fetchField();
  }
  $q->range($sandbox['current'], 50);
  module_load_include('inc', 'webform_multifile', 'safe_unserialize');
  foreach ($q->execute()->fetchAll() as $data) {
    $data->data = drupal_json_encode(safe_unserialize($data->data));
    db_update('webform_submitted_data')
      ->fields(array('data' => $data->data))
      ->condition('nid', $data->nid)
      ->condition('sid', $data->sid)
      ->condition('cid', $data->cid)
      ->condition('no', $data->no)
      ->execute();
    $sandbox['current']++;
  }
  $sandbox['#finished'] = 1;
  if ($sandbox['current'] < $sandbox['total']) {
    $sandbox['#finished'] = $sandbox['current'] / $sandbox['total'];
  }
}