webform_multifile.install in Webform Multiple File Upload 7
Same filename and directory in other branches
Webform multifile install functions.
File
webform_multifile.installView source
<?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.nid = d.nid and 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) {
// Check to see if this data is already JSON. Can happen when the update
// gets interrupted: https://www.drupal.org/node/2811847.
$json = drupal_json_decode($data->data);
if (json_last_error() === JSON_ERROR_NONE) {
$sandbox['current']++;
continue;
}
$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'];
}
}
Functions
Name![]() |
Description |
---|---|
webform_multifile_requirements | Implements hook_requirements(). |
webform_multifile_update_7001 | Convert serialized php arrays to json encoded strings. |