action update module add
This commit is contained in:
		@@ -64,4 +64,18 @@ class ModuleController extends ConsoleController
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @throws \Exception
 | 
			
		||||
     */
 | 
			
		||||
    public function actionUpdateModule(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!isset($this->argv['path'])) {
 | 
			
		||||
            throw new \Exception('Missing module path "--path" specified');
 | 
			
		||||
        }
 | 
			
		||||
        if (file_exists(ROOT_DIR . $this->argv['path'])) {
 | 
			
		||||
            $moduleService = new ModuleService();
 | 
			
		||||
            $moduleService->updateModule($this->argv['path']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -25,5 +25,6 @@ App::$collector->group(["prefix" => "module"], callback: function (RouteCollecto
 | 
			
		||||
    App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']);
 | 
			
		||||
    App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']);
 | 
			
		||||
    App::$collector->console('pack', [\kernel\console\controllers\ModuleController::class, 'actionPackModule']);
 | 
			
		||||
    App::$collector->console('update', [\kernel\console\controllers\ModuleController::class, 'actionUpdateModule']);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -172,6 +172,9 @@ class ModuleService
 | 
			
		||||
//            $out->out->r('Архив распакован', 'green');
 | 
			
		||||
//        } else {
 | 
			
		||||
//            $this->out->r('Message: Ошибка чтения архива', 'red');
 | 
			
		||||
        } else {
 | 
			
		||||
            $zip->close();
 | 
			
		||||
            throw new \Exception("unable to open zip archive");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) {
 | 
			
		||||
@@ -192,6 +195,7 @@ class ModuleService
 | 
			
		||||
 | 
			
		||||
//            $this->out->r("Удаляем временные файлы", 'green');
 | 
			
		||||
        $fileHelper->recursiveRemoveDir($tmpModuleDirFull);
 | 
			
		||||
        var_dump($tmpModuleDirFull);
 | 
			
		||||
 | 
			
		||||
//            $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green');
 | 
			
		||||
    }
 | 
			
		||||
@@ -229,7 +233,50 @@ class ModuleService
 | 
			
		||||
 | 
			
		||||
//        $this->out->r("Архив создан", 'green');
 | 
			
		||||
        $fileHelper->recursiveRemoveDir($tmpModuleDirFull);
 | 
			
		||||
 | 
			
		||||
//        $this->out->r("Временная папка удалена", 'green');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @throws \Exception
 | 
			
		||||
     */
 | 
			
		||||
    public function updateModule(string $path): void
 | 
			
		||||
    {
 | 
			
		||||
        $zip = new ZipArchive;
 | 
			
		||||
        $tmpModuleDir = md5(time());
 | 
			
		||||
        $res = $zip->open(ROOT_DIR . $path);
 | 
			
		||||
        if ($res === TRUE) {
 | 
			
		||||
            $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/";
 | 
			
		||||
            $zip->extractTo($tmpModuleDirFull);
 | 
			
		||||
            $zip->close();
 | 
			
		||||
//            $out->out->r('Архив распакован', 'green');
 | 
			
		||||
//        } else {
 | 
			
		||||
//            $this->out->r('Message: Ошибка чтения архива', 'red');
 | 
			
		||||
        } else {
 | 
			
		||||
            $zip->close();
 | 
			
		||||
            throw new \Exception("unable to open zip archive");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) {
 | 
			
		||||
            throw new \Exception('manifest.json not found');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json"));
 | 
			
		||||
        $manifest = Manifest::getWithVars($manifestJson);
 | 
			
		||||
//            $this->out->r('manifest.json инициализирован', 'green');
 | 
			
		||||
 | 
			
		||||
        $fileHelper = new Files();
 | 
			
		||||
        if (isset($manifest['kernel_module_path'])) {
 | 
			
		||||
            $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', $manifest['kernel_module_path']);
 | 
			
		||||
        } else {
 | 
			
		||||
            $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
//            $this->out->r("Удаляем временные файлы", 'green');
 | 
			
		||||
        $fileHelper->recursiveRemoveDir($tmpModuleDirFull);
 | 
			
		||||
 | 
			
		||||
//            $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green');
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user