Exemple #1
1
 protected function installSystem($arParams)
 {
     $arConfig = [];
     $dbConfig = [];
     if ($arParams['dbType'] == 'mysql') {
         $dbConfig[$arParams['dbType']] = ['driver' => $arParams['dbType'], 'host' => $arParams['dbHost'], 'database' => $arParams['dbName'], 'username' => $arParams['dbLogin'], 'password' => $arParams['dbPassword'], 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => ''];
     } elseif ($arParams['dbType'] == 'sqlite') {
         $file = RESOURCE_PATH . 'database/' . strtolower($arParams['dbFileName']) . '.sqlite';
         FileWorker::saveFile($file, '');
         $dbConfig[$arParams['dbType']] = ['driver' => $arParams['dbType'], 'database' => $file, 'prefix' => ''];
     }
     $arConfig['db'] = $dbConfig;
     $arConfig['slim']['settings'] = ['db_driver' => $arParams['dbType'], 'displayErrorDetails' => $arParams['displayErrorDetails'], 'debug' => $arParams['debug'], 'use_log' => $arParams['use_log'], 'log_system' => $arParams['log_system'], 'log_filename' => 'app.log', 'register_log' => $arParams['register_log'], 'determineRouteBeforeAppMiddleware' => true, 'protect_double_route_register' => true];
     $arConfig['view'] = ['template_path' => APP_PATH . 'templates', 'twig' => ['cache' => CACHE_PATH . 'twig', 'debug' => $arParams['debug'], 'auto_reload' => $arParams['debug']]];
     $arConfig['cache'] = array('cache.default' => 'files', 'cache.stores.files' => array('driver' => 'file', 'path' => CACHE_PATH . 'slimcms'));
     FileWorker::savePhpReturnFile(APP_PATH . 'config/local/autoconfig.php', $arConfig);
     $this->registerDB($dbConfig[$arParams['dbType']]);
     if (isset($this->specialData['coreClassName']) && class_exists($this->specialData['coreClassName'])) {
         $cl = $this->specialData['coreClassName'];
         ModuleLoader::install(new $cl());
     } else {
         ModuleLoader::install(new \Modules\Core\Module());
     }
     if ($arParams['modules'] && is_array($arParams['modules'])) {
         foreach ($arParams['modules'] as $module) {
             $cl = '\\Modules\\' . $module . '\\Module';
             if (class_exists($cl)) {
                 ModuleLoader::install(new $cl());
             }
         }
     }
 }
 public function doAdd($req, $res)
 {
     $params = new RequestParams($req);
     $name = $params->post('name');
     $sys_name = $params->post('system_name');
     $desc = $params->post('description');
     $version = $params->post('version');
     $author = $params->post('author');
     $sys_name = preg_replace("/[^A-Za-z0-9_]/", "", $sys_name);
     if (!$sys_name) {
         $this->flash->addMessage('errors', 'Module system_name is empty!');
         return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('developers.module.generator'));
     }
     $sys_name = Str::studly($sys_name);
     if (is_dir(MODULE_PATH . $sys_name)) {
         $this->flash->addMessage('errors', 'Module exist!');
         return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('developers.module.generator'));
     }
     $path = MODULE_PATH . $sys_name;
     if (!FileWorker::copy(MODULE_PATH . 'ModuleGenerator' . DIRECTORY_SEPARATOR . 'Source' . DIRECTORY_SEPARATOR . '.default', $path)) {
         $this->flash->addMessage('errors', 'Module dir \\"' . MODULE_PATH . '\\" - is write protect. Check permissions!');
         return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('developers.module.generator'));
     }
     $ret = FileWorker::replaseInFile($path . '/info.json', ["%name%", "%description%", "%system_name%", "%version%", "%author%"], [$name, $desc, $sys_name, $version, $author]);
     if ($ret === false) {
         $this->flash->addMessage('errors', 'Replace file content for \\"' . $path . '/info.json' . '\\" - is write protect. Check permissions!');
         return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('developers.module.generator'));
     }
     $ret = FileWorker::replaseInFile($path . '/Module.php', ["%system_name%"], [$sys_name]);
     if ($ret === false) {
         $this->flash->addMessage('errors', 'Replace file content for \\"' . $path . '/Module.php' . '\\" - is write protect. Check permissions!');
         return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('developers.module.generator'));
     }
     $this->flash->addMessage('success', 'Module create!');
     return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('developers.module.generator'));
 }
Exemple #3
0
 public function uninstallModule()
 {
     parent::uninstallModule();
     $this->container->get('db')->schema()->table('pages', function ($table) {
         $table->dropColumn('category_id');
     });
     $this->container->get('db')->schema()->dropIfExists('sections');
     $path = RESOURCE_PATH . 'models_field_info/pages.json';
     $pagesField = FileWorker::getJsonDataFile($path);
     if ($pagesField) {
         $cId = false;
         foreach ($pagesField as $k => $field) {
             if ($field->name == 'url_prefix') {
                 $field->type = "string";
                 continue;
             }
             if ($field->name == 'category_id') {
                 $cId = $k;
                 continue;
             }
         }
         if ($cId !== false) {
             unset($pagesField[$cId]);
             FileWorker::saveJsonFile($path, $pagesField);
         }
     }
     FileWorker::removeItemInModelsFillable('Pages', 'category_id');
     $this->saveConfigForModule(self::class, ["params" => ["installed" => false, "active" => false]]);
 }