@@ -532,7 +532,6 @@ public function changeBuild($id, array $data)
532532 $ newPorts = false ;
533533 // Remove Assignments
534534 if (isset ($ data ['remove_additional ' ])) {
535- $ newPorts = true ;
536535 foreach ($ data ['remove_additional ' ] as $ id => $ combo ) {
537536 list ($ ip , $ port ) = explode (': ' , $ combo );
538537 // Invalid, not worth killing the whole thing, we'll just skip over it.
@@ -541,10 +540,11 @@ public function changeBuild($id, array $data)
541540 }
542541
543542 // Can't remove the assigned IP/Port combo
544- if ($ ip === $ allocation ->ip && $ port === $ allocation ->port ) {
543+ if ($ ip === $ allocation ->ip && ( int ) $ port === ( int ) $ allocation ->port ) {
545544 break ;
546545 }
547546
547+ $ newPorts = true ;
548548 Models \Allocation::where ('ip ' , $ ip )->where ('port ' , $ port )->where ('assigned_to ' , $ server ->id )->update ([
549549 'assigned_to ' => null
550550 ]);
@@ -553,7 +553,6 @@ public function changeBuild($id, array $data)
553553
554554 // Add Assignments
555555 if (isset ($ data ['add_additional ' ])) {
556- $ newPorts = true ;
557556 foreach ($ data ['add_additional ' ] as $ id => $ combo ) {
558557 list ($ ip , $ port ) = explode (': ' , $ combo );
559558 // Invalid, not worth killing the whole thing, we'll just skip over it.
@@ -566,6 +565,7 @@ public function changeBuild($id, array $data)
566565 break ;
567566 }
568567
568+ $ newPorts = true ;
569569 Models \Allocation::where ('ip ' , $ ip )->where ('port ' , $ port )->whereNull ('assigned_to ' )->update ([
570570 'assigned_to ' => $ server ->id
571571 ]);
@@ -589,50 +589,51 @@ public function changeBuild($id, array $data)
589589
590590 // @TODO: verify that server can be set to this much memory without
591591 // going over node limits.
592- if (isset ($ data ['memory ' ])) {
592+ if (isset ($ data ['memory ' ]) && $ server -> memory !== ( int ) $ data [ ' memory ' ] ) {
593593 $ server ->memory = $ data ['memory ' ];
594+ $ newBuild ['memory ' ] = (int ) $ server ->memory ;
594595 }
595596
596- if (isset ($ data ['swap ' ])) {
597+ if (isset ($ data ['swap ' ]) && $ server -> swap !== ( int ) $ data [ ' swap ' ] ) {
597598 $ server ->swap = $ data ['swap ' ];
599+ $ newBuild ['swap ' ] = (int ) $ server ->swap ;
598600 }
599601
600602 // @TODO: verify that server can be set to this much disk without
601603 // going over node limits.
602- if (isset ($ data ['disk ' ])) {
604+ if (isset ($ data ['disk ' ]) && $ server -> disk !== ( int ) $ data [ ' disk ' ] ) {
603605 $ server ->disk = $ data ['disk ' ];
606+ $ newBuild ['disk ' ] = (int ) $ server ->disk ;
604607 }
605608
606- if (isset ($ data ['cpu ' ])) {
609+ if (isset ($ data ['cpu ' ]) && $ server -> cpu !== ( int ) $ data [ ' cpu ' ] ) {
607610 $ server ->cpu = $ data ['cpu ' ];
611+ $ newBuild ['cpu ' ] = (int ) $ server ->cpu ;
608612 }
609613
610- if (isset ($ data ['io ' ])) {
614+ if (isset ($ data ['io ' ]) && $ server -> io !== ( int ) $ data [ ' io ' ] ) {
611615 $ server ->io = $ data ['io ' ];
616+ $ newBuild ['io ' ] = (int ) $ server ->io ;
612617 }
613618
614619 // Try save() here so if it fails we haven't contacted the daemon
615620 // This won't be committed unless the HTTP request succeedes anyways
616621 $ server ->save ();
617622
618- $ newBuild ['memory ' ] = (int ) $ server ->memory ;
619- $ newBuild ['swap ' ] = (int ) $ server ->swap ;
620- $ newBuild ['io ' ] = (int ) $ server ->io ;
621- $ newBuild ['cpu ' ] = (int ) $ server ->cpu ;
622- $ newBuild ['disk ' ] = (int ) $ server ->disk ;
623+ if (!empty ($ newBuild )) {
624+ $ node = Models \Node::getByID ($ server ->node );
625+ $ client = Models \Node::guzzleRequest ($ server ->node );
623626
624- $ node = Models \Node::getByID ($ server ->node );
625- $ client = Models \Node::guzzleRequest ($ server ->node );
626-
627- $ client ->request ('PATCH ' , '/server ' , [
628- 'headers ' => [
629- 'X-Access-Server ' => $ server ->uuid ,
630- 'X-Access-Token ' => $ node ->daemonSecret
631- ],
632- 'json ' => [
633- 'build ' => $ newBuild
634- ]
635- ]);
627+ $ client ->request ('PATCH ' , '/server ' , [
628+ 'headers ' => [
629+ 'X-Access-Server ' => $ server ->uuid ,
630+ 'X-Access-Token ' => $ node ->daemonSecret
631+ ],
632+ 'json ' => [
633+ 'build ' => $ newBuild
634+ ]
635+ ]);
636+ }
636637
637638 DB ::commit ();
638639 return true ;
0 commit comments