update modules from ms
This commit is contained in:
@ -6,8 +6,10 @@ use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
||||
use kernel\Request;
|
||||
use kernel\services\ModuleService;
|
||||
@ -33,13 +35,7 @@ class ModuleShopClientController extends AdminController
|
||||
public function actionIndex(int $page_number = 1): void
|
||||
{
|
||||
$per_page = 8;
|
||||
|
||||
$token = $_ENV['MODULE_SHOP_TOKEN'];
|
||||
$modules_info = $this->client->request('GET', $_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
]
|
||||
]);
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
$module_count = count($modules_info);
|
||||
$modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page);
|
||||
@ -52,17 +48,9 @@ class ModuleShopClientController extends AdminController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function actionView(int $id): void
|
||||
{
|
||||
$token = $_ENV['MODULE_SHOP_TOKEN'];
|
||||
$module_info = $this->client->request('GET', $_ENV['MODULE_SHOP_URL'] . '/api/module_shop/' . $id, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
]
|
||||
]);
|
||||
$module_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/' . $id);
|
||||
$module_info = json_decode($module_info->getBody()->getContents(), true);
|
||||
$this->cgView->render("view.php", ['data' => $module_info]);
|
||||
}
|
||||
@ -72,39 +60,31 @@ class ModuleShopClientController extends AdminController
|
||||
*/
|
||||
#[NoReturn] public function actionInstall(): void
|
||||
{
|
||||
// $request = new Request();
|
||||
// $id = $request->get('id');
|
||||
// $token = $_ENV['MODULE_SHOP_TOKEN'];
|
||||
// Debug::prn(123);
|
||||
// $module = $this->client->request('GET', $_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id, [
|
||||
// 'headers' => [
|
||||
// 'Authorization' => 'Bearer ' . $token,
|
||||
// 'Accept' => 'application/itguild',
|
||||
// 'sink' => RESOURCES_DIR . '/tmp/ms/some.itguild'
|
||||
// ]
|
||||
// ]);
|
||||
//
|
||||
// $module = json_decode($module->getBody()->getContents(), true);
|
||||
//// Debug::dd(123);
|
||||
// $this->moduleService->installModule(RESOURCES_DIR . '/tmp/ms/some.igm');
|
||||
// $this->redirect('/admin/module_shop_client', 302);
|
||||
|
||||
|
||||
$request = new Request();
|
||||
$id = $request->get("id");
|
||||
$token = $_ENV['MODULE_SHOP_TOKEN'];
|
||||
$module_info = $this->client->request('GET', $_ENV['MODULE_SHOP_URL'] . '/api/module_shop/' . $id, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
]
|
||||
]);
|
||||
$module_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
|
||||
|
||||
$module_info = json_decode($module_info->getBody()->getContents(), true);
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $module_info['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->installModule('/resources/tmp/modules/' . basename($module_info['path_to_archive']));
|
||||
// Debug::prn($this->moduleService->getErrors());
|
||||
// Debug::dd(RESOURCES_DIR . '/tmp/modules/' . basename($module_info['path_to_archive']));
|
||||
$this->moduleService->installModule(RESOURCES_DIR . '/tmp/ms/some.igm');
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно установлен.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionUpdate(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$id = $request->get("id");
|
||||
$module_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/' . $id);
|
||||
|
||||
$module_info = json_decode($module_info->getBody()->getContents(), true);
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $module_info['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->updateModule('/resources/tmp/modules/' . basename($module_info['path_to_archive']));
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно обновлен.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -114,6 +94,8 @@ class ModuleShopClientController extends AdminController
|
||||
$slug = $request->get("slug");
|
||||
$module_info = $this->moduleService->getModuleInfoBySlug($slug);
|
||||
$this->moduleService->uninstallModule($module_info['app_module_path']);
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно удален.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user