From 45785f9610a97000bdc9b4c4fab82acd0c9789d4 Mon Sep 17 00:00:00 2001
From: Gerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org>
Date: Thu, 20 Apr 2006 16:38:22 +0000
Subject: [PATCH] #46549, more robust node_submit, patch by chx

---
 modules/node.module      | 11 ++++++-----
 modules/node/node.module | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/modules/node.module b/modules/node.module
index 1357eaa77fc4..c548741a2cf1 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -1488,7 +1488,8 @@ function node_submit($node) {
     $node->teaser = isset($node->body) ? node_teaser($node->body, isset($node->format) ? $node->format : NULL) : '';
   }
 
-  if (user_access('administer nodes')) {
+  $access = user_access('administer nodes');
+  if ($access) {
     // Populate the "authored by" field.
     if ($account = user_load(array('name' => $node->name))) {
       $node->uid = $account->uid;
@@ -1499,10 +1500,10 @@ function node_submit($node) {
 
     $node->created = $node->date ? strtotime($node->date) : NULL;
   }
-  else {
-    // Force defaults in case people modify the form:
-    $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
-    foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
+  // Force defaults in case people modify the form:
+  $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
+  foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
+    if (!$access || !isset($node->$key)) {
       $node->$key = in_array($key, $node_options);
     }
   }
diff --git a/modules/node/node.module b/modules/node/node.module
index 1357eaa77fc4..c548741a2cf1 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1488,7 +1488,8 @@ function node_submit($node) {
     $node->teaser = isset($node->body) ? node_teaser($node->body, isset($node->format) ? $node->format : NULL) : '';
   }
 
-  if (user_access('administer nodes')) {
+  $access = user_access('administer nodes');
+  if ($access) {
     // Populate the "authored by" field.
     if ($account = user_load(array('name' => $node->name))) {
       $node->uid = $account->uid;
@@ -1499,10 +1500,10 @@ function node_submit($node) {
 
     $node->created = $node->date ? strtotime($node->date) : NULL;
   }
-  else {
-    // Force defaults in case people modify the form:
-    $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
-    foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
+  // Force defaults in case people modify the form:
+  $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
+  foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
+    if (!$access || !isset($node->$key)) {
       $node->$key = in_array($key, $node_options);
     }
   }
-- 
GitLab