Revision 06c2b3e2
Added by Andreas Kohlbecker almost 8 years ago
modules/cdm_dataportal/cdm_api/cdm_node.php | ||
---|---|---|
4 | 4 |
* CDM Node functions. |
5 | 5 |
*/ |
6 | 6 |
|
7 |
|
|
8 |
define('CDM_DRUPAL_NODE_CREATION', 'cdm_drupal_node_creation'); |
|
9 |
|
|
10 |
function do_create_drupal_nodes(){ |
|
11 |
static $value = null; |
|
12 |
if($value === NULL){ |
|
13 |
$value = variable_get(CDM_DRUPAL_NODE_CREATION, FALSE); |
|
14 |
} |
|
15 |
return $value; |
|
16 |
} |
|
17 |
|
|
7 | 18 |
/** |
8 | 19 |
* Implements hook_node_view(). |
9 | 20 |
* |
... | ... | |
104 | 115 |
$title = substr($title, 0, 128); |
105 | 116 |
$node->title = $title; |
106 | 117 |
|
107 |
// Comment @WA: this was used in the D5 module version. |
|
108 |
// Remove this to change it to the current user. |
|
109 |
$node->uid = 0; |
|
110 |
|
|
111 |
// 2 = comments on, 1 = comments off. |
|
112 |
$node->comment = variable_get('comment_' . $node->type); |
|
113 |
|
|
114 |
// Preserve the current messages but before saving the node. |
|
115 |
$messages = drupal_set_message(); |
|
116 |
|
|
117 |
if ($node = node_submit($node)) { |
|
118 |
// Prepare node for saving by populating author and creation date. |
|
119 |
// Comment @WA: Note that node_save is using a helper function to save a |
|
120 |
// revision with the uid of the current user so the revision will not |
|
121 |
// have uid = 0 but the uid of the current user. |
|
122 |
// I guess that is not a problem so I leave it like this. Remedy would be |
|
123 |
// to alter that revision entry afterwards. |
|
124 |
// Will create a watchdog log entry if it fails to create the node. |
|
125 |
node_save($node); |
|
126 |
} |
|
118 |
if(do_create_drupal_nodes()){ |
|
119 |
// using the system admin user for all new nodes |
|
120 |
$node->uid = 0; |
|
127 | 121 |
|
128 |
// Restore the messages. |
|
129 |
$_SESSION['messages'] = $messages; |
|
130 |
|
|
131 |
// Comment @WA: I think http://dev.e-taxonomy.eu/trac/ticket/2964 is not |
|
132 |
// relevant here anymore, since node_save will roll_back if node cannot be |
|
133 |
// created. |
|
134 |
if (!isset($node->nid)) { |
|
135 |
$message = t('Could not create node for !nodetype (!title).', array( |
|
136 |
'!nodetype' => $nodetype, |
|
137 |
'!title' => $title, |
|
138 |
)); |
|
139 |
drupal_set_message($message, 'error'); |
|
140 |
watchdog('content', $message, WATCHDOG_ERROR); |
|
141 |
return NULL; |
|
142 |
} |
|
122 |
// 2 = comments on, 1 = comments off. |
|
123 |
$node->comment = variable_get('comment_' . $node->type); |
|
143 | 124 |
|
144 |
// Hash as a 32-character hexadecimal number. |
|
145 |
$hash = md5(variable_get('cdm_webservice_url') . $uuid); |
|
125 |
// Preserve the current messages but before saving the node. |
|
126 |
$messages = drupal_set_message(); |
|
127 |
|
|
128 |
if ($node = node_submit($node)) { |
|
129 |
// Prepare node for saving by populating author and creation date. |
|
130 |
// Comment @WA: Note that node_save is using a helper function to save a |
|
131 |
// revision with the uid of the current user so the revision will not |
|
132 |
// have uid = 0 but the uid of the current user. |
|
133 |
// I guess that is not a problem so I leave it like this. Remedy would be |
|
134 |
// to alter that revision entry afterwards. |
|
135 |
// Will create a watchdog log entry if it fails to create the node. |
|
136 |
node_save($node); |
|
137 |
} |
|
146 | 138 |
|
147 |
$id = db_insert('node_cdm')->fields(array( |
|
148 |
'nid' => $node->nid, |
|
149 |
'wsuri' => variable_get('cdm_webservice_url'), |
|
150 |
'hash' => $hash, |
|
151 |
'cdmtype' => $nodetype, |
|
152 |
'uuid' => $uuid, |
|
153 |
))->execute(); |
|
139 |
// Restore the messages. |
|
140 |
$_SESSION['messages'] = $messages; |
|
141 |
|
|
142 |
// Comment @WA: I think http://dev.e-taxonomy.eu/trac/ticket/2964 is not |
|
143 |
// relevant here anymore, since node_save will roll_back if node cannot be |
|
144 |
// created. |
|
145 |
if (!isset($node->nid)) { |
|
146 |
$message = t('Could not create node for !nodetype (!title).', array( |
|
147 |
'!nodetype' => $nodetype, |
|
148 |
'!title' => $title, |
|
149 |
)); |
|
150 |
drupal_set_message($message, 'error'); |
|
151 |
watchdog('content', $message, WATCHDOG_ERROR); |
|
152 |
return NULL; |
|
153 |
} |
|
154 |
|
|
155 |
// Hash as a 32-character hexadecimal number. |
|
156 |
$hash = md5(variable_get('cdm_webservice_url') . $uuid); |
|
157 |
|
|
158 |
$id = db_insert('node_cdm')->fields(array( |
|
159 |
'nid' => $node->nid, |
|
160 |
'wsuri' => variable_get('cdm_webservice_url'), |
|
161 |
'hash' => $hash, |
|
162 |
'cdmtype' => $nodetype, |
|
163 |
'uuid' => $uuid, |
|
164 |
))->execute(); |
|
165 |
} |
|
154 | 166 |
} |
155 | 167 |
|
156 | 168 |
return $node; |
... | ... | |
189 | 201 |
drupal_set_title($title, PASS_THROUGH); |
190 | 202 |
|
191 | 203 |
cdm_add_node_content($node, $content); |
192 |
return node_show($node); |
|
204 |
|
|
205 |
if(do_create_drupal_nodes()){ |
|
206 |
// use the full node_show() |
|
207 |
$nodes = node_show($node); |
|
208 |
} else { |
|
209 |
// only use a part of the methods called in the node_show() method |
|
210 |
$nodes = node_view_multiple(array($node->nid => $node), 'full'); |
|
211 |
} |
|
212 |
return $nodes; |
|
193 | 213 |
} |
194 | 214 |
|
195 | 215 |
/** |
Also available in: Unified diff
creation of cdm drupal nodes now optional