function document_insert in Document 6
Same name and namespace in other branches
- 7 document.module \document_insert()
- 8.x document.module \document_insert()
Implementation of hook_insert().
1 call to document_insert()
- document_update in ./
document.module - Implementation of hook_update().
File
- ./
document.module, line 281
Code
function document_insert($node) {
try {
$external_url = isset($node->document_external_url) ? $node->document_external_url : '';
$external = strlen($external_url) > 0 ? DOCUMENT_EXTERNAL : DOCUMENT_INTERNAL;
$author = $node->document_author;
$year = $node->document_year;
$keywords = $node->document_keywords;
$type = NULL;
$fid = 0;
$file = NULL;
$doc_url = NULL;
if (isset($node->is_node_revision) && $node->is_node_revision) {
$type = $node->document_type;
$fid = $node->document_fid;
$doc_url = $node->document_url;
$external = $node->document_external;
}
else {
$type = _document_get_node_terms($node);
if ($external == DOCUMENT_INTERNAL) {
//Save the Document uploaded.
$file = file_save_upload('document_filepath', array(), document_get_path());
if ($file !== 0) {
$fid = $file->fid;
$doc_url = file_create_url($file->filepath);
//Set the status of the uploaded file.
file_set_status($file, FILE_STATUS_PERMANENT);
}
else {
drupal_set_message(t('Please select a document to upload.'), 'error');
}
}
else {
$doc_url = $external_url;
}
}
db_query("INSERT INTO {document} (nid, vid, fid, type, author, publish_year, keywords, url, external) VALUES (%d, %d, %d, '%s', '%s', '%d', '%s', '%s', %d)", $node->nid, $node->vid, $fid, $type, $author, $year, $keywords, $doc_url, $external);
if ($node->status == 0) {
drupal_set_message(t('The document has been submitted. Please wait until administrators review and publish it.'), 'status');
}
} catch (Exception $ex) {
drupal_set_message(t($ex
->getMessage()), 'error');
}
}