diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index c8a13cfb..14bb2dc8 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -22,6 +22,8 @@ public function __construct() $this->middleware('can:settings-edit_voice')->only(['updateVoice']); $this->middleware('can:settings-cp_update_check')->only(['checkForCpUpdate']); + + $this->middleware('can:settings-cp_upgrade')->only(['checkForCpUpdate']); } /** @@ -87,4 +89,26 @@ public function checkForCpUpdate(): JsonResponse 'target' => $target ]); } + + /** + * Initiates the upgrade process for the control panel by calling the cli using the gRpc Bridge + * + * @return JsonResponse + */ + public function upgradeCp(): JsonResponse + { + try { + $bridgeClient = new BridgeClientService(); + + $bridgeClient->upgradeControlPanel(); + } catch (Exception $e) { + flash('BRIDGE ERROR', $e->getMessage(), 'error'); + } + + flash('Control Panel update started.', 'the application will be offline for a few minutes ', 'warning'); + + return response()->json([ + 'upgrade' => 'started' + ]); + } } diff --git a/app/Services/Bridge/BridgeClientService.php b/app/Services/Bridge/BridgeClientService.php index 47d85e7e..90ab4120 100644 --- a/app/Services/Bridge/BridgeClientService.php +++ b/app/Services/Bridge/BridgeClientService.php @@ -3,8 +3,8 @@ namespace App\Services\Bridge; use Bridge\BridgeClient; -use Bridge\CheckForCpUpdateRequest; -use Bridge\GetCpVersionRequest; +use Bridge\EmptyMessage; +use Bridge\UpgradeCpRequest; use Exception; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Facades\Storage; @@ -36,10 +36,10 @@ public function __construct() * @return string */ public function getControlPanelVersion(): string { - $request = new GetCpVersionRequest(); + $request = new EmptyMessage(); list($response, $status) = $this->client->getCpVersion($request)->wait(); if ($status->code !== \Grpc\STATUS_OK) { - throw new Exception('Error while getting version: ' . $status->code . ", " . $status->details . PHP_EOL); + throw new Exception('Error while retrieving current version: ' . $status->code . ", " . $status->details . PHP_EOL); } return $response->getVersion(); } @@ -49,11 +49,30 @@ public function getControlPanelVersion(): string { * @return string */ public function checkForControlPanelUpdate(): string { - $request = new CheckForCpUpdateRequest(); + $request = new EmptyMessage(); list($response, $status) = $this->client->CheckForCpUpdate($request)->wait(); if ($status->code !== \Grpc\STATUS_OK) { - throw new Exception('Error while checking for Control Panel update: ' . $status->code . ", " . $status->details . PHP_EOL); + throw new Exception('Error while checking for Control Panel updates: ' . $status->code . ", " . $status->details . PHP_EOL); } return $response->getTarget(); } + + /** + * @throws Exception + * @return void + */ + public function upgradeControlPanel(): void { + $request = new UpgradeCpRequest(); + + $target = $this->checkForControlPanelUpdate(); + if ($target === 'none') { + throw new Exception('Error while initiating Control Panel upgrade: No valid upgrade target found'); + } + + $request->setVersion($target); + list($response, $status) = $this->client->UpgradeCp($request)->wait(); + if ($status->code !== \Grpc\STATUS_OK) { + throw new Exception('Error while initiating Control Panel upgrade: ' . $status->code . ", " . $status->details . PHP_EOL); + } + } } diff --git a/bridge/Bridge/BridgeClient.php b/bridge/Bridge/BridgeClient.php index f625061a..a4a3b024 100644 --- a/bridge/Bridge/BridgeClient.php +++ b/bridge/Bridge/BridgeClient.php @@ -34,12 +34,12 @@ public function SayHello(\Bridge\HelloRequest $argument, /** * Get the current version of the control panel - * @param \Bridge\GetCpVersionRequest $argument input argument + * @param \Bridge\EmptyMessage $argument input argument * @param array $metadata metadata * @param array $options call options * @return \Grpc\UnaryCall */ - public function GetCpVersion(\Bridge\GetCpVersionRequest $argument, + public function GetCpVersion(\Bridge\EmptyMessage $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/bridge.Bridge/GetCpVersion', $argument, @@ -48,12 +48,12 @@ public function GetCpVersion(\Bridge\GetCpVersionRequest $argument, } /** - * @param \Bridge\CheckForCpUpdateRequest $argument input argument + * @param \Bridge\EmptyMessage $argument input argument * @param array $metadata metadata * @param array $options call options * @return \Grpc\UnaryCall */ - public function CheckForCpUpdate(\Bridge\CheckForCpUpdateRequest $argument, + public function CheckForCpUpdate(\Bridge\EmptyMessage $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/bridge.Bridge/CheckForCpUpdate', $argument, @@ -61,4 +61,18 @@ public function CheckForCpUpdate(\Bridge\CheckForCpUpdateRequest $argument, $metadata, $options); } + /** + * @param \Bridge\UpgradeCpRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function UpgradeCp(\Bridge\UpgradeCpRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/bridge.Bridge/UpgradeCp', + $argument, + ['\Bridge\EmptyMessage', 'decode'], + $metadata, $options); + } + } diff --git a/bridge/Bridge/BridgeStub.php b/bridge/Bridge/BridgeStub.php index ceb81e65..be35546e 100644 --- a/bridge/Bridge/BridgeStub.php +++ b/bridge/Bridge/BridgeStub.php @@ -25,13 +25,13 @@ public function SayHello( /** * Get the current version of the control panel - * @param \Bridge\GetCpVersionRequest $request client request + * @param \Bridge\EmptyMessage $request client request * @param \Grpc\ServerContext $context server request context * @return \Bridge\GetCpVersionReply for response data, null if if error occured * initial metadata (if any) and status (if not ok) should be set to $context */ public function GetCpVersion( - \Bridge\GetCpVersionRequest $request, + \Bridge\EmptyMessage $request, \Grpc\ServerContext $context ): ?\Bridge\GetCpVersionReply { $context->setStatus(\Grpc\Status::unimplemented()); @@ -39,19 +39,33 @@ public function GetCpVersion( } /** - * @param \Bridge\CheckForCpUpdateRequest $request client request + * @param \Bridge\EmptyMessage $request client request * @param \Grpc\ServerContext $context server request context * @return \Bridge\CheckForCpUpdateReply for response data, null if if error occured * initial metadata (if any) and status (if not ok) should be set to $context */ public function CheckForCpUpdate( - \Bridge\CheckForCpUpdateRequest $request, + \Bridge\EmptyMessage $request, \Grpc\ServerContext $context ): ?\Bridge\CheckForCpUpdateReply { $context->setStatus(\Grpc\Status::unimplemented()); return null; } + /** + * @param \Bridge\UpgradeCpRequest $request client request + * @param \Grpc\ServerContext $context server request context + * @return \Bridge\EmptyMessage for response data, null if if error occured + * initial metadata (if any) and status (if not ok) should be set to $context + */ + public function UpgradeCp( + \Bridge\UpgradeCpRequest $request, + \Grpc\ServerContext $context + ): ?\Bridge\EmptyMessage { + $context->setStatus(\Grpc\Status::unimplemented()); + return null; + } + /** * Get the method descriptors of the service for server registration * @@ -69,13 +83,19 @@ public final function getMethodDescriptors(): array '/bridge.Bridge/GetCpVersion' => new \Grpc\MethodDescriptor( $this, 'GetCpVersion', - '\Bridge\GetCpVersionRequest', + '\Bridge\EmptyMessage', \Grpc\MethodDescriptor::UNARY_CALL ), '/bridge.Bridge/CheckForCpUpdate' => new \Grpc\MethodDescriptor( $this, 'CheckForCpUpdate', - '\Bridge\CheckForCpUpdateRequest', + '\Bridge\EmptyMessage', + \Grpc\MethodDescriptor::UNARY_CALL + ), + '/bridge.Bridge/UpgradeCp' => new \Grpc\MethodDescriptor( + $this, + 'UpgradeCp', + '\Bridge\UpgradeCpRequest', \Grpc\MethodDescriptor::UNARY_CALL ), ]; diff --git a/bridge/Bridge/CheckForCpUpdateRequest.php b/bridge/Bridge/CheckForCpUpdateRequest.php deleted file mode 100644 index 97d45cc8..00000000 --- a/bridge/Bridge/CheckForCpUpdateRequest.php +++ /dev/null @@ -1,31 +0,0 @@ -bridge.CheckForCpUpdateRequest - */ -class CheckForCpUpdateRequest extends \Google\Protobuf\Internal\Message -{ - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Bridge::initOnce(); - parent::__construct($data); - } - -} - diff --git a/bridge/Bridge/GetCpVersionRequest.php b/bridge/Bridge/EmptyMessage.php similarity index 78% rename from bridge/Bridge/GetCpVersionRequest.php rename to bridge/Bridge/EmptyMessage.php index 11d1aa5c..4e6836c9 100644 --- a/bridge/Bridge/GetCpVersionRequest.php +++ b/bridge/Bridge/EmptyMessage.php @@ -9,9 +9,9 @@ use Google\Protobuf\Internal\GPBUtil; /** - * Generated from protobuf message bridge.GetCpVersionRequest + * Generated from protobuf message bridge.EmptyMessage */ -class GetCpVersionRequest extends \Google\Protobuf\Internal\Message +class EmptyMessage extends \Google\Protobuf\Internal\Message { /** diff --git a/bridge/GetVersionReply.php b/bridge/Bridge/UpgradeCpRequest.php similarity index 82% rename from bridge/GetVersionReply.php rename to bridge/Bridge/UpgradeCpRequest.php index d4d3036c..3e7de7c4 100644 --- a/bridge/GetVersionReply.php +++ b/bridge/Bridge/UpgradeCpRequest.php @@ -1,15 +1,17 @@ GetVersionReply + * Generated from protobuf message bridge.UpgradeCpRequest */ -class GetVersionReply extends \Google\Protobuf\Internal\Message +class UpgradeCpRequest extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field string version = 1; @@ -26,7 +28,7 @@ class GetVersionReply extends \Google\Protobuf\Internal\Message * } */ public function __construct($data = NULL) { - \GPBMetadata\Updater::initOnce(); + \GPBMetadata\Bridge::initOnce(); parent::__construct($data); } diff --git a/bridge/GPBMetadata/Bridge.php b/bridge/GPBMetadata/Bridge.php index fd5e4021..ac482aab 100644 Binary files a/bridge/GPBMetadata/Bridge.php and b/bridge/GPBMetadata/Bridge.php differ diff --git a/bridge/GetVersionRequest.php b/bridge/GetVersionRequest.php deleted file mode 100644 index 9860b067..00000000 --- a/bridge/GetVersionRequest.php +++ /dev/null @@ -1,56 +0,0 @@ -GetVersionRequest - */ -class GetVersionRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string version = 1; - */ - protected $version = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $version - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Updater::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string version = 1; - * @return string - */ - public function getVersion() - { - return $this->version; - } - - /** - * Generated from protobuf field string version = 1; - * @param string $var - * @return $this - */ - public function setVersion($var) - { - GPBUtil::checkString($var, True); - $this->version = $var; - - return $this; - } - -} - diff --git a/config/cerberus.php b/config/cerberus.php index 51da74b8..bdc31d4d 100644 --- a/config/cerberus.php +++ b/config/cerberus.php @@ -145,5 +145,9 @@ 'slug' => 'settings-cp_update_check', 'description' => 'a user can check if an update of the control panel is available' ], + [ + 'slug' => 'settings-cp_upgrade', + 'description' => 'a user can initiate the upgrade process for the control panel.' + ], ] ]; diff --git a/package.json b/package.json index 4d3561bc..33cf4747 100644 --- a/package.json +++ b/package.json @@ -72,5 +72,8 @@ }, "resolutions": { "vue-loader": "^15.10.0" + }, + "dependencies": { + "retry-axios": "^3.0.0" } } diff --git a/resources/js/Pages/Settings/Components/UpdateSettingsForm.vue b/resources/js/Pages/Settings/Components/UpdateSettingsForm.vue index 4e62af85..bfc661b4 100644 --- a/resources/js/Pages/Settings/Components/UpdateSettingsForm.vue +++ b/resources/js/Pages/Settings/Components/UpdateSettingsForm.vue @@ -1,38 +1,56 @@ diff --git a/resources/js/Shared/Notifications/Flash.vue b/resources/js/Shared/Notifications/Flash.vue index c287b4ba..ddfd87fe 100644 --- a/resources/js/Shared/Notifications/Flash.vue +++ b/resources/js/Shared/Notifications/Flash.vue @@ -14,7 +14,7 @@ leave-active-class="origin-top-right transition transform-gpu duration-500 ease-in-out" >
diff --git a/routes/web.php b/routes/web.php index 1257160e..6043a9af 100644 --- a/routes/web.php +++ b/routes/web.php @@ -47,5 +47,6 @@ // Settings Route::get('settings/edit', [SettingsController::class, 'edit'])->name('settings.edit'); Route::put('settings/voices', [SettingsController::class, 'updateVoice'])->name('settings.update.voice'); - Route::get('settings/update', [SettingsController::class, 'checkForCpUpdate'])->name('settings.update.check'); + Route::get('settings/update/check', [SettingsController::class, 'checkForCpUpdate'])->name('settings.update.check'); + Route::get('settings/upgrade', [SettingsController::class, 'upgradeCp'])->name('settings.upgrade.cp'); }); diff --git a/yarn.lock b/yarn.lock index 940c3353..eaf71b2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6582,6 +6582,11 @@ restore-cursor@^3.1.0: onetime "^5.1.0" signal-exit "^3.0.2" +retry-axios@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/retry-axios/-/retry-axios-3.0.0.tgz#5fd54f65330d155c36d01e3685238889375b9aa0" + integrity sha512-/jRv4nCDytusFZIY+zD6aKP29+wpgnbjfap5B76rqvgROWfONG5Bf7vCXx7grhxJwYGLlumraKZQUMzNgfXNCg== + retry@^0.13.1: version "0.13.1" resolved "https://registry.yarnpkg.com/retry/-/retry-0.13.1.tgz#185b1587acf67919d63b357349e03537b2484658"