function _add_db_field_data in Bibliography Module 6
Same name and namespace in other branches
- 7 biblio.install \_add_db_field_data()
- 7.2 biblio.install \_add_db_field_data()
3 calls to _add_db_field_data()
- biblio_install in ./
biblio.install - @file Install file for biblio module
- biblio_reset_types in ./
biblio.install - biblio_update_6000 in ./
biblio.install
File
- ./
biblio.install, line 1120 - Install file for biblio module
Code
function _add_db_field_data() {
global $db_type;
$schema = biblio_schema();
$fieldnames = array_keys($schema['biblio_fields']['fields']);
$field_type_fieldnames = array_keys($schema['biblio_field_type']['fields']);
$field_type_data_fieldnames = array_keys($schema['biblio_field_type_data']['fields']);
if ($db_type == 'mysql' or $db_type == 'mysqli') {
db_query("/*!40000 ALTER TABLE {biblio_field_type_data} DISABLE KEYS */;");
db_query("/*!40000 ALTER TABLE {biblio_fields} DISABLE KEYS */;");
}
$csv_file = drupal_get_path('module', 'biblio') . '/biblio.field.link.data.csv';
if ($handle = fopen($csv_file, "r")) {
$header = fgetcsv($handle, 10000, ",");
// the first line has the field names
while (($row = fgetcsv($handle, 10000, ",")) !== FALSE) {
$column = 0;
// add link data for default biblio type (0) and all other defined types (100-130)
foreach (array_merge(array(
0,
), range(100, 130)) as $t) {
$link_data = array(
$t,
$row[0],
$row[0],
$row[0],
$row[3],
$row[4],
$row[5],
$row[6],
$row[7],
);
db_query("INSERT INTO {biblio_field_type} (" . implode(", ", $field_type_fieldnames) . ")\n VALUES ('" . implode("', '", $link_data) . "')");
}
$ftd = array(
$row[0],
$row[1],
$row[2],
);
db_query("INSERT INTO {biblio_field_type_data} (" . implode(", ", $field_type_data_fieldnames) . ")\n VALUES('" . implode("', '", $ftd) . "')");
$field_data = array(
$row[0],
$row[8],
$row[9],
$row[10],
$row[11],
);
db_query("INSERT INTO {biblio_fields} (" . implode(", ", $fieldnames) . ")\n VALUES('" . implode("', '", $field_data) . "')");
// add contributor type data
if ($row[9] == 'contrib_widget') {
// use field name without trailing 's' as initial guess for author type
$auth_type = substr($row[1], -1, 1) == 's' ? substr($row[1], 0, -1) : $row[1];
db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", $row[0], $auth_type);
db_query("INSERT INTO {biblio_contributor_type} (auth_category, biblio_type, auth_type) VALUES (%d, %d, %d)", $row[0], 0, $row[0]);
}
}
fclose($handle);
$result = array(
'success' => TRUE,
'query' => 'Added field titles and default values',
);
}
else {
$result = array(
'success' => FALSE,
'query' => 'Could not open ' . $csv_file,
);
}
if ($db_type == 'mysql' or $db_type == 'mysqli') {
db_query("/*!40000 ALTER TABLE {biblio_field_type_data} ENABLE KEYS */;");
db_query("/*!40000 ALTER TABLE {biblio_fields} ENABLE KEYS */;");
}
return $result;
}