webform_conditional.install in Webform Conditional (Same Page Conditionals) 6
Same filename and directory in other branches
Used for module updates
@author Ted Bowman <ted@tedbow.com>
File
webform_conditional.installView source
<?php
/**
* @file
* Used for module updates
*
* @author Ted Bowman <ted@tedbow.com>
*/
function webform_conditional_update_6000() {
$sql = "SELECT name, form_key, type, extra,cid,nid FROM {webform_component}";
$result = db_query($sql);
if ($result) {
while ($row = db_fetch_array($result)) {
$extra = unserialize($row['extra']);
$extra['webform_conditional_field_key'] = trim($extra['webform_conditional_field_key']);
if (!empty($extra['webform_conditional_field_key'])) {
$row['extra'] = $extra;
$rows[] = $row;
}
}
if ($rows) {
//keep track of which dependent components coould not be update because keys are not unique
$cannot_update = array();
foreach ($rows as $row) {
if (empty($cannot_update[$row['nid']][$row['extra']['webform_conditional_field_key']])) {
$sql = "SELECT count(cid) FROM {webform_component} WHERE nid = %d and form_key = '%s'";
$count = db_result(db_query($sql, $row['nid'], $row['extra']['webform_conditional_field_key']));
if ($count == 1) {
//can only update if key appears once in webform node
$sql = "SELECT cid FROM {webform_component} WHERE nid = %d and form_key = '%s'";
//get cid to replace key
$dependet_cid = db_result(db_query($sql, $row['nid'], $row['extra']['webform_conditional_field_key']));
//no longer storing key
unset($row['extra']['webform_conditional_field_key']);
$row['extra']['webform_conditional_cid'] = $dependet_cid;
$row['extra']['webform_conditional_field_value'] = str_replace("|", "\n", $row['extra']['webform_conditional_field_value']);
$row['extra']['webform_conditional_operator '] = "=";
$extra = serialize($row['extra']);
//can't use update_sql here becauce of serialized data??? is that right?
$success = db_query("UPDATE {webform_component} SET extra = '%s' WHERE nid = %d AND cid = '%s'", $extra, $row['nid'], $row['cid']);
$affected = db_affected_rows();
if (!$success || $affected != 1) {
watchdog("wfc_conditional", "Webform_conditional could not update. Could not update webform_component table.", NULL, WATCHDOG_ERROR);
$ret['#abort'] = array(
'success' => FALSE,
);
return $ret;
}
}
else {
$cannot_update[$row['nid']][$row['extra']['webform_conditional_field_key']][] = $row['form_key'];
}
}
}
}
if (!empty($cannot_update)) {
$error_msg = "For Webform conditional the following problems were found during the update:<br /><ul>";
foreach ($cannot_update as $nid => $conditional_keys) {
$error_msg .= "<li>In Node {$nid} the following dependent field keys were not unique:<ul>";
foreach ($conditional_keys as $conditional_key => $keys) {
$error_msg .= "<li>{$conditional_key} used by these components: " . implode(", ", $keys) . "<li>";
}
$error_msg .= "</ul></li>";
}
$error_msg .= "</ul>";
drupal_set_message($error_msg, "warning");
}
}
return array();
}
function webform_conditional_update_6001() {
$ret = array();
$sql = "SELECT nid, cid,extra FROM {webform_component}";
$result = db_query($sql);
if ($result) {
while ($row = db_fetch_array($result)) {
$extra = unserialize($row['extra']);
if (!empty($extra['webform_conditional_mandatory'])) {
$update_components[$row['nid']][] = $row['cid'];
}
}
if ($update_components) {
foreach ($update_components as $nid => $cids) {
$ret[] = update_sql("UPDATE {webform_component} SET mandatory = 1 where nid = {$nid} and cid in (" . implode(",", $cids) . ")");
}
}
}
return $ret;
}
Functions
Name![]() |
Description |
---|---|
webform_conditional_update_6000 | @file Used for module updates |
webform_conditional_update_6001 |