function webform_validation_update_7101 in Webform Validation 7
Adjust DB schema.
Add column to track negated rules. Remove explicit length limit on data field. Remove regex escaping of blacklist data.
File
- ./
webform_validation.install, line 158 - Webform_validation installation file.
Code
function webform_validation_update_7101() {
db_add_field('webform_validation_rule', 'negate', array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'description' => 'Validate the inverse of the rule',
'not null' => TRUE,
'default' => 0,
));
db_change_field('webform_validation_rule', 'data', 'data', array(
'type' => 'text',
'description' => 'Additional rule data',
'not null' => FALSE,
));
$replace = array(
'.',
'\\',
'+',
'*',
'?',
'[',
'^',
']',
'$',
'(',
')',
'{',
'}',
'=',
'!',
'<',
'>',
'|',
':',
'-',
'/',
);
$search = array();
foreach ($replace as $value) {
$search[] = '\\' . $value;
}
$result = db_query("SELECT DISTINCT data FROM {webform_validation_rule} WHERE validator = 'blacklist'");
foreach ($result as $row) {
$data_new = str_replace($search, $replace, $row->data);
if ($row->data !== $data_new) {
db_update('webform_validation_rule')
->fields(array(
'data' => $data_new,
))
->condition('data', $row->data, '=')
->execute();
}
}
}