View source
<?php
module_load_include('inc', 'answers', 'answers.features.field');
function answers_update_7200() {
$fields = answers_field_default_fields();
if (!field_info_field('field_question_locked_p')) {
$field = $fields['node-question-field_question_locked_p']['field_config'];
field_create_field($field);
}
if (!field_info_instance('node', 'field_question_locked_p', 'question')) {
$instance = $fields['node-question-field_question_locked_p']['field_instance'];
field_create_instance($instance);
}
return array();
}
function answers_update_7201() {
$result = db_query("SELECT * from {node} WHERE type = 'question';");
foreach ($result as $question) {
$question = node_load($question->nid);
_answers_set_default_question_field_values($question);
}
return array();
}
function _answers_set_default_question_field_values($question) {
$changed_p = FALSE;
if (isset($question->field_answer_count['und'][0]['count'])) {
$question->field_question_locked_p['und'][0]['count'] = 0;
$changed_p = TRUE;
}
if (isset($question->field_notify_p['und'][0]['value'])) {
$question->field_notify_p['und'][0]['value'] = 0;
$changed_p = TRUE;
}
if (isset($question->field_question_locked_p['und'][0]['value'])) {
$question->field_question_locked_p['und'][0]['value'] = 0;
$changed_p = TRUE;
}
if ($changed_p) {
watchdog('answers', 'Set default question fields for nid ' . $question->nid);
node_save($question);
}
}