Skip to content

Commit 4473dad

Browse files
committed
cp upgrade
1 parent 2bc627c commit 4473dad

File tree

15 files changed

+193
-140
lines changed

15 files changed

+193
-140
lines changed

app/Http/Controllers/SettingsController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function __construct()
2222
$this->middleware('can:settings-edit_voice')->only(['updateVoice']);
2323

2424
$this->middleware('can:settings-cp_update_check')->only(['checkForCpUpdate']);
25+
26+
$this->middleware('can:settings-cp_upgrade')->only(['checkForCpUpdate']);
2527
}
2628

2729
/**
@@ -87,4 +89,26 @@ public function checkForCpUpdate(): JsonResponse
8789
'target' => $target
8890
]);
8991
}
92+
93+
/**
94+
* Initiates the upgrade process for the control panel by calling the cli using the gRpc Bridge
95+
*
96+
* @return JsonResponse
97+
*/
98+
public function upgradeCp(): JsonResponse
99+
{
100+
try {
101+
$bridgeClient = new BridgeClientService();
102+
103+
$bridgeClient->upgradeControlPanel();
104+
} catch (Exception $e) {
105+
flash('BRIDGE ERROR', $e->getMessage(), 'error');
106+
}
107+
108+
flash('Control Panel update started.', 'the application will be offline for a few minutes ', 'warning');
109+
110+
return response()->json([
111+
'upgrade' => 'started'
112+
]);
113+
}
90114
}

app/Services/Bridge/BridgeClientService.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace App\Services\Bridge;
44

55
use Bridge\BridgeClient;
6-
use Bridge\CheckForCpUpdateRequest;
7-
use Bridge\GetCpVersionRequest;
6+
use Bridge\EmptyMessage;
7+
use Bridge\UpgradeCpRequest;
88
use Exception;
99
use Illuminate\Contracts\Filesystem\FileNotFoundException;
1010
use Illuminate\Support\Facades\Storage;
@@ -36,10 +36,10 @@ public function __construct()
3636
* @return string
3737
*/
3838
public function getControlPanelVersion(): string {
39-
$request = new GetCpVersionRequest();
39+
$request = new EmptyMessage();
4040
list($response, $status) = $this->client->getCpVersion($request)->wait();
4141
if ($status->code !== \Grpc\STATUS_OK) {
42-
throw new Exception('Error while getting version: ' . $status->code . ", " . $status->details . PHP_EOL);
42+
throw new Exception('Error while retrieving current version: ' . $status->code . ", " . $status->details . PHP_EOL);
4343
}
4444
return $response->getVersion();
4545
}
@@ -49,11 +49,30 @@ public function getControlPanelVersion(): string {
4949
* @return string
5050
*/
5151
public function checkForControlPanelUpdate(): string {
52-
$request = new CheckForCpUpdateRequest();
52+
$request = new EmptyMessage();
5353
list($response, $status) = $this->client->CheckForCpUpdate($request)->wait();
5454
if ($status->code !== \Grpc\STATUS_OK) {
55-
throw new Exception('Error while checking for Control Panel update: ' . $status->code . ", " . $status->details . PHP_EOL);
55+
throw new Exception('Error while checking for Control Panel updates: ' . $status->code . ", " . $status->details . PHP_EOL);
5656
}
5757
return $response->getTarget();
5858
}
59+
60+
/**
61+
* @throws Exception
62+
* @return void
63+
*/
64+
public function upgradeControlPanel(): void {
65+
$request = new UpgradeCpRequest();
66+
67+
$target = $this->checkForControlPanelUpdate();
68+
if ($target === 'none') {
69+
throw new Exception('Error while initiating Control Panel upgrade: No valid upgrade target found');
70+
}
71+
72+
$request->setVersion($target);
73+
list($response, $status) = $this->client->UpgradeCp($request)->wait();
74+
if ($status->code !== \Grpc\STATUS_OK) {
75+
throw new Exception('Error while initiating Control Panel upgrade: ' . $status->code . ", " . $status->details . PHP_EOL);
76+
}
77+
}
5978
}

bridge/Bridge/BridgeClient.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public function SayHello(\Bridge\HelloRequest $argument,
3434

3535
/**
3636
* Get the current version of the control panel
37-
* @param \Bridge\GetCpVersionRequest $argument input argument
37+
* @param \Bridge\EmptyMessage $argument input argument
3838
* @param array $metadata metadata
3939
* @param array $options call options
4040
* @return \Grpc\UnaryCall
4141
*/
42-
public function GetCpVersion(\Bridge\GetCpVersionRequest $argument,
42+
public function GetCpVersion(\Bridge\EmptyMessage $argument,
4343
$metadata = [], $options = []) {
4444
return $this->_simpleRequest('/bridge.Bridge/GetCpVersion',
4545
$argument,
@@ -48,17 +48,31 @@ public function GetCpVersion(\Bridge\GetCpVersionRequest $argument,
4848
}
4949

5050
/**
51-
* @param \Bridge\CheckForCpUpdateRequest $argument input argument
51+
* @param \Bridge\EmptyMessage $argument input argument
5252
* @param array $metadata metadata
5353
* @param array $options call options
5454
* @return \Grpc\UnaryCall
5555
*/
56-
public function CheckForCpUpdate(\Bridge\CheckForCpUpdateRequest $argument,
56+
public function CheckForCpUpdate(\Bridge\EmptyMessage $argument,
5757
$metadata = [], $options = []) {
5858
return $this->_simpleRequest('/bridge.Bridge/CheckForCpUpdate',
5959
$argument,
6060
['\Bridge\CheckForCpUpdateReply', 'decode'],
6161
$metadata, $options);
6262
}
6363

64+
/**
65+
* @param \Bridge\UpgradeCpRequest $argument input argument
66+
* @param array $metadata metadata
67+
* @param array $options call options
68+
* @return \Grpc\UnaryCall
69+
*/
70+
public function UpgradeCp(\Bridge\UpgradeCpRequest $argument,
71+
$metadata = [], $options = []) {
72+
return $this->_simpleRequest('/bridge.Bridge/UpgradeCp',
73+
$argument,
74+
['\Bridge\EmptyMessage', 'decode'],
75+
$metadata, $options);
76+
}
77+
6478
}

bridge/Bridge/BridgeStub.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,47 @@ public function SayHello(
2525

2626
/**
2727
* Get the current version of the control panel
28-
* @param \Bridge\GetCpVersionRequest $request client request
28+
* @param \Bridge\EmptyMessage $request client request
2929
* @param \Grpc\ServerContext $context server request context
3030
* @return \Bridge\GetCpVersionReply for response data, null if if error occured
3131
* initial metadata (if any) and status (if not ok) should be set to $context
3232
*/
3333
public function GetCpVersion(
34-
\Bridge\GetCpVersionRequest $request,
34+
\Bridge\EmptyMessage $request,
3535
\Grpc\ServerContext $context
3636
): ?\Bridge\GetCpVersionReply {
3737
$context->setStatus(\Grpc\Status::unimplemented());
3838
return null;
3939
}
4040

4141
/**
42-
* @param \Bridge\CheckForCpUpdateRequest $request client request
42+
* @param \Bridge\EmptyMessage $request client request
4343
* @param \Grpc\ServerContext $context server request context
4444
* @return \Bridge\CheckForCpUpdateReply for response data, null if if error occured
4545
* initial metadata (if any) and status (if not ok) should be set to $context
4646
*/
4747
public function CheckForCpUpdate(
48-
\Bridge\CheckForCpUpdateRequest $request,
48+
\Bridge\EmptyMessage $request,
4949
\Grpc\ServerContext $context
5050
): ?\Bridge\CheckForCpUpdateReply {
5151
$context->setStatus(\Grpc\Status::unimplemented());
5252
return null;
5353
}
5454

55+
/**
56+
* @param \Bridge\UpgradeCpRequest $request client request
57+
* @param \Grpc\ServerContext $context server request context
58+
* @return \Bridge\EmptyMessage for response data, null if if error occured
59+
* initial metadata (if any) and status (if not ok) should be set to $context
60+
*/
61+
public function UpgradeCp(
62+
\Bridge\UpgradeCpRequest $request,
63+
\Grpc\ServerContext $context
64+
): ?\Bridge\EmptyMessage {
65+
$context->setStatus(\Grpc\Status::unimplemented());
66+
return null;
67+
}
68+
5569
/**
5670
* Get the method descriptors of the service for server registration
5771
*
@@ -69,13 +83,19 @@ public final function getMethodDescriptors(): array
6983
'/bridge.Bridge/GetCpVersion' => new \Grpc\MethodDescriptor(
7084
$this,
7185
'GetCpVersion',
72-
'\Bridge\GetCpVersionRequest',
86+
'\Bridge\EmptyMessage',
7387
\Grpc\MethodDescriptor::UNARY_CALL
7488
),
7589
'/bridge.Bridge/CheckForCpUpdate' => new \Grpc\MethodDescriptor(
7690
$this,
7791
'CheckForCpUpdate',
78-
'\Bridge\CheckForCpUpdateRequest',
92+
'\Bridge\EmptyMessage',
93+
\Grpc\MethodDescriptor::UNARY_CALL
94+
),
95+
'/bridge.Bridge/UpgradeCp' => new \Grpc\MethodDescriptor(
96+
$this,
97+
'UpgradeCp',
98+
'\Bridge\UpgradeCpRequest',
7999
\Grpc\MethodDescriptor::UNARY_CALL
80100
),
81101
];

bridge/Bridge/CheckForCpUpdateRequest.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

bridge/Bridge/GetCpVersionRequest.php renamed to bridge/Bridge/EmptyMessage.php

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/GetVersionReply.php renamed to bridge/Bridge/UpgradeCpRequest.php

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/GPBMetadata/Bridge.php

48 Bytes
Binary file not shown.

bridge/GetVersionRequest.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

config/cerberus.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,9 @@
145145
'slug' => 'settings-cp_update_check',
146146
'description' => 'a user can check if an update of the control panel is available'
147147
],
148+
[
149+
'slug' => 'settings-cp_upgrade',
150+
'description' => 'a user can initiate the upgrade process for the control panel.'
151+
],
148152
]
149153
];

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@
7272
},
7373
"resolutions": {
7474
"vue-loader": "^15.10.0"
75+
},
76+
"dependencies": {
77+
"retry-axios": "^3.0.0"
7578
}
7679
}

0 commit comments

Comments
 (0)