From 2f1d74bdd48e3beaf6b52cad126de0271875e7ac Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 1 Oct 2011 15:31:08 -0700 Subject: Fix the multiple-edit protection (I'd done this yesterday, but didn't commit) --- src/controllers/Users.class.php | 60 ++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'src/controllers') diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php index 1d947e1..a5d23fc 100644 --- a/src/controllers/Users.class.php +++ b/src/controllers/Users.class.php @@ -256,30 +256,46 @@ class Users extends Controller { if (isset($_POST[$key]) && is_array($_POST[$key])) { $old = $_POST['_old'][$key]; foreach ($_POST[$key] as $uid => $value) { - $have_old = !isset($old[$uid]); - @$change_it = $old[$uid]!==$value; - if (!$have_old || $change_it) { - $user = Auth::getObj($uid); - $oldvalue = $this->getConf($user,$key); - $oldvalue = $oldvalue['value']; - if ($oldvalue===false) $oldvalue = 'false'; - if ($oldvalue===true) $oldvalue = 'true'; - $changed = $value != $oldvalue; - if ($changed) { - echo "
\n";
-							echo "Error: Value changed elsewhere, and I don't have real handling for this yet.\n";
-							echo "uid: $uid\n";
-							echo "Name: ".$user->getName()."\n";
-							echo "Key: $key\n";
-							echo "oldvalue: "; var_dump($oldvalue); echo "\n";
-							echo "newvalue: "; var_dump($value); echo "\n";
-							echo "
"; + $doit = true; + $forked = false; + $have_old = isset($old[$uid]); + if ($have_old) { + @$value_base = $old[$uid]; + $we_changed_it = $value_base != $value; + if ($we_changed_it) { + $user = Auth::getObj($uid); + $value_fork = $this->getConf($user,$key); + $value_fork = $value_fork['value']; + if ($value_fork===false) $value_fork = 'false'; + if ($value_fork===true) $value_fork = 'true'; - } else { - $this->setConf($uid, - $key, - $value); + $someone_else_changed_it = $value_fork != $value_base; + if ($someone_else_changed_it) { + if ($value == $value_fork) { + // we might as well not have + $we_changed_it = false; + } else { + $forked = true; + } + } } + if (!$we_changed_it) { + $doit = false;// nothing to do + } + } + if ($doit) { + $this->setConf($uid, $key, $value); + } + if ($forked) { + echo "
\n";
+						echo "Error: Value changed elsewhere, and I don't have real handling for this yet.\n";
+						echo "UID: $uid\n";
+						echo "Name: ".$user->getName()."\n";
+						echo "Key: $key\n";
+						echo "Value: Original  : "; var_dump($value_base);
+						echo "Value: Other edit: "; var_dump($value_fork);
+						echo "Value: This edit : "; var_dump($value);
+						echo "
"; } } } -- cgit v1.2.3-54-g00ecf