function taxonomy_save_term in Drupal 4
Same name and namespace in other branches
- 5 modules/taxonomy/taxonomy.module \taxonomy_save_term()
- 6 modules/taxonomy/taxonomy.module \taxonomy_save_term()
3 calls to taxonomy_save_term()
- forum_form_submit in modules/
forum.module - Process forum form and container form submissions.
- taxonomy_form_term_submit in modules/
taxonomy.module - Accept the form submission for a taxonomy term and save the result.
- taxonomy_node_save in modules/
taxonomy.module - Save term associations for a given node.
File
- modules/
taxonomy.module, line 418 - Enables the organization of content into categories.
Code
function taxonomy_save_term(&$edit) {
if ($edit['tid'] && $edit['name']) {
db_query("UPDATE {term_data} SET name = '%s', description = '%s', weight = %d WHERE tid = %d", $edit['name'], $edit['description'], $edit['weight'], $edit['tid']);
module_invoke_all('taxonomy', 'update', 'term', $edit);
$status = SAVED_UPDATED;
}
else {
if ($edit['tid']) {
return taxonomy_del_term($edit['tid']);
}
else {
$edit['tid'] = db_next_id('{term_data}_tid');
db_query("INSERT INTO {term_data} (tid, name, description, vid, weight) VALUES (%d, '%s', '%s', %d, %d)", $edit['tid'], $edit['name'], $edit['description'], $edit['vid'], $edit['weight']);
module_invoke_all('taxonomy', 'insert', 'term', $edit);
$status = SAVED_NEW;
}
}
db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $edit['tid'], $edit['tid']);
if ($edit['relations']) {
foreach ($edit['relations'] as $related_id) {
if ($related_id != 0) {
db_query('INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)', $edit['tid'], $related_id);
}
}
}
db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $edit['tid']);
if (!isset($edit['parent']) || empty($edit['parent'])) {
$edit['parent'] = array(
0,
);
}
if (is_array($edit['parent'])) {
foreach ($edit['parent'] as $parent) {
if (is_array($parent)) {
foreach ($parent as $tid) {
db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $edit['tid'], $tid);
}
}
else {
db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $edit['tid'], $parent);
}
}
}
else {
db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $edit['tid'], $edit['parent']);
}
db_query('DELETE FROM {term_synonym} WHERE tid = %d', $edit['tid']);
if ($edit['synonyms']) {
foreach (explode("\n", str_replace("\r", '', $edit['synonyms'])) as $synonym) {
if ($synonym) {
db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $edit['tid'], chop($synonym));
}
}
}
cache_clear_all();
return $status;
}