r2812 - updateObjectAllocation(): restore the code lost in changeset:2395 to fix...
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 2 Jun 2009 11:53:37 +0000 (11:53 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 2 Jun 2009 11:53:37 +0000 (11:53 +0000)
ChangeLog
inc/ophandlers.php

index 68f1fefd2709d849c331fe9619c9a98ad7ad7477..d43c6ede3177fe1296fadcfbc4d81e4b75f62875 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
        bugfix: rackspace rows highlightling was broken in previous release
        bugfix: IPv4 address picker window was broken
        bugfix: string value "0" was incorrectly handled, when displaying or entering data
+       bugfix: rackspace allocation history recording did not work in 0.17.0
        update: removed unused database index
 0.17.0 2009-05-20
        new feature: file attachments (by Aaron)
index e59aca67d427c3ccb21614b450b5cd69f56b45eb..7874eb3f865a90d0db5f288acf5f50e79625e005 100644 (file)
@@ -686,54 +686,77 @@ function clearSticker ()
                return buildRedirectURL (__FUNCTION__, 'ERR');
 }
 
+$msgcode['updateObjectAllocation']['OK'] = 63;
 function updateObjectAllocation ()
 {
        assertUIntArg ('object_id', __FUNCTION__);
 
-       $is_submit = isset ($_REQUEST['got_atoms']);
-
-       if ($is_submit)
+       if (!isset ($_REQUEST['got_atoms']))
        {
-               $object_id = $_REQUEST['object_id'];
-               $workingRacksData = array();
-               foreach ($_REQUEST['rackmulti'] as $cand_id)
+               unset($_GET['page']);
+               unset($_GET['tab']);
+               unset($_GET['op']);
+               unset($_POST['page']);
+               unset($_POST['tab']);
+               unset($_POST['op']);
+               return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
+       }
+       $object_id = $_REQUEST['object_id'];
+       $workingRacksData = array();
+       foreach ($_REQUEST['rackmulti'] as $cand_id)
+       {
+               if (!isset ($workingRacksData[$cand_id]))
                {
-                       if (!isset ($workingRacksData[$cand_id]))
+                       $rackData = spotEntity ('rack', $cand_id);
+                       if ($rackData == NULL)
                        {
-                               $rackData = spotEntity ('rack', $cand_id);
-                               if ($rackData == NULL)
-                               {
-                                       showError ('rack not found', __FUNCTION__);
-                                       return;
-                               }
-                               amplifyCell ($rackData);
-                               $workingRacksData[$cand_id] = $rackData;
+                               showError ('rack not found', __FUNCTION__);
+                               return;
                        }
+                       amplifyCell ($rackData);
+                       $workingRacksData[$cand_id] = $rackData;
                }
+       }
 
-               foreach ($workingRacksData as &$rd)
-                       applyObjectMountMask ($rd, $object_id);
+       foreach ($workingRacksData as &$rd)
+               applyObjectMountMask ($rd, $object_id);
 
-               $oldMolecule = getMoleculeForObject ($object_id);
-               $worldchanged = FALSE;
-               $log = array();
-               foreach ($workingRacksData as $rack_id => $rackData)
-               {
-                       $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
-                       $log[] = $logrecord;
-               }
-               return buildWideRedirectURL($log);
-       }
-       else
+       $oldMolecule = getMoleculeForObject ($object_id);
+       $changecnt = 0;
+       $log = array();
+       foreach ($workingRacksData as $rack_id => $rackData)
        {
-               unset($_GET['page']);
-               unset($_GET['tab']);
-               unset($_GET['op']);
-               unset($_POST['page']);
-               unset($_POST['tab']);
-               unset($_POST['op']);
-               return buildWideRedirectURL(array(), NULL, NULL, array_merge($_GET, $_POST));
+               $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
+               $log[] = $logrecord;
+               if ($logrecord['code'] == 300)
+                       continue;
+               $changecnt++;
+               // Reload our working copy after form processing.
+               $rackData = spotEntity ('rack', $cand_id);
+               amplifyCell ($rackData);
+               applyObjectMountMask ($rackData, $object_id);
+               $workingRacksData[$rack_id] = $rackData;
        }
+       if (!$changecnt)
+               return buildRedirectURL (__FUNCTION__, 'OK', $changecnt);
+       // Log a record.
+       $newMolecule = getMoleculeForObject ($object_id);
+       $oc = count ($oldMolecule);
+       $nc = count ($newMolecule);
+       $omid = $oc ? createMolecule ($oldMolecule) : 'NULL';
+       $nmid = $nc ? createMolecule ($newMolecule) : 'NULL';
+       global $remote_username;
+       $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'";
+       $query =
+               "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
+               "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
+       global $dbxlink;
+       $result = $dbxlink->query ($query);
+       if ($result == NULL)
+               $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
+       else
+               $log[] = array ('code' => 200, 'message' => 'History logged.');
+       return buildWideRedirectURL ($log);
 }
 
 $msgcode['updateObject']['OK'] = 16;