Prepare("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = ?"); $stmt->Execute([$do]); $fieldhelp = $stmt->FetchObject(); // Find the default value. $stmt = Bugdar::$db->Prepare("SELECT value FROM " . TABLE_PREFIX . "setting WHERE varname = ?"); if ($do == 'resolution') $stmt->Execute(['defaultresolve']); // Unclear why this ever was. else $stmt->Execute(['default' . $do]); $default_setting = $stmt->FetchObject(); // Get all the values. $stmt = Bugdar::$db->Query("SELECT * FROM " . TABLE_PREFIX . $do . " ORDER BY displayorder"); $values = []; $default_value = NULL; while ($value = $stmt->Fetch()) { $values[] = $value[$do]; if ($value[$do . 'id'] == $default_setting->value) $default_value = $value[$do]; } // Create the new field. $field = new bugdar\Field(); $field->title = $fieldhelp->title; $field->description = $fieldhelp->body; $field->type = bugdar\Field::TYPE_LIST; $field->validator_pattern = implode("\n", $values); $field->required = TRUE; $field->default_value = $default_value; $field->can_search = TRUE; var_dump($field); $field->Insert(); // Migrate the data from field IDs in the bug table to the values in the new // all-values table. $stmt = Bugdar::$db->Prepare(" INSERT INTO ". TABLE_PREFIX . "bugfield2 (bugid, title, value) SELECT bug.bugid, '" . $field->title . "', field." . $do . " FROM " . TABLE_PREFIX . "bug AS bug LEFT JOIN " . TABLE_PREFIX . $do . " AS field ON (bug." . $do . " = field." . $do . "id) "); $stmt->Execute(); } /////////////////////////////////////////////////////////////////////////////// if ($do === 'product') { } print Bugdar::$db->ConstructHTMLDebugBlock();