/** * This command echoes what you have entered as the message. * * @param string $message the message to be echoed. */ public function actionIndex() { echo "Running batch...\n"; $config = $this->getYiiConfiguration(); $config['id'] = 'temp'; // create models foreach ($this->tables as $table) { #var_dump($this->tableNameMap, $table);exit; $params = ['interactive' => $this->interactive, 'template' => 'default', 'ns' => $this->modelNamespace, 'db' => $this->modelDb, 'tableName' => $table, 'tablePrefix' => $this->tablePrefix, 'generateModelClass' => $this->extendedModels, 'modelClass' => isset($this->tableNameMap[$table]) ? $this->tableNameMap[$table] : Inflector::camelize($table), 'baseClass' => $this->modelBaseClass, 'tableNameMap' => $this->tableNameMap]; $route = 'gii/giix-model'; $app = \Yii::$app; $temp = new \yii\console\Application($config); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; } // create CRUDs $providers = ArrayHelper::merge($this->crudProviders, Generator::getCoreProviders()); foreach ($this->tables as $table) { $table = str_replace($this->tablePrefix, '', $table); $name = isset($this->tableNameMap[$table]) ? $this->tableNameMap[$table] : Inflector::camelize($table); $params = ['interactive' => $this->interactive, 'overwrite' => $this->overwrite, 'template' => 'default', 'modelClass' => $this->modelNamespace . '\\' . $name, 'searchModelClass' => $this->modelNamespace . '\\search\\' . $name . 'Search', 'controllerClass' => $this->crudControllerNamespace . '\\' . $name . 'Controller', 'viewPath' => $this->crudViewPath, 'pathPrefix' => $this->crudPathPrefix, 'actionButtonClass' => 'yii\\grid\\ActionColumn', 'baseControllerClass' => $this->crudBaseControllerClass, 'providerList' => implode(',', $providers)]; $route = 'gii/giix-crud'; $app = \Yii::$app; $temp = new \yii\console\Application($config); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; } }
/** * Run batch process to generate CRUDs all given tables * @throws \yii\console\Exception */ public function actionCruds() { // create CRUDs $providers = ArrayHelper::merge($this->crudProviders, Generator::getCoreProviders()); // create folders $this->createDirectoryFromNamespace($this->crudControllerNamespace); $this->createDirectoryFromNamespace($this->crudSearchModelNamespace); foreach ($this->tables as $table) { $table = str_replace($this->tablePrefix, '', $table); $name = isset($this->tableNameMap[$table]) ? $this->tableNameMap[$table] : $this->modelGenerator->generateClassName($table); $params = ['interactive' => $this->interactive, 'overwrite' => $this->overwrite, 'template' => $this->template, 'modelClass' => $this->modelNamespace . '\\' . $name, 'searchModelClass' => $this->crudSearchModelNamespace . '\\' . $name . $this->crudSearchModelSuffix, 'controllerNs' => $this->crudControllerNamespace, 'controllerClass' => $this->crudControllerNamespace . '\\' . $name . 'Controller', 'viewPath' => $this->crudViewPath, 'pathPrefix' => $this->crudPathPrefix, 'tablePrefix' => $this->tablePrefix, 'enableI18N' => $this->enableI18N, 'singularEntities' => $this->singularEntities, 'messageCategory' => $this->messageCategory, 'actionButtonClass' => 'yii\\grid\\ActionColumn', 'baseControllerClass' => $this->crudBaseControllerClass, 'providerList' => $providers, 'skipRelations' => $this->crudSkipRelations, 'accessFilter' => $this->crudAccessFilter, 'tidyOutput' => $this->crudTidyOutput]; $route = 'gii/giiant-crud'; $app = \Yii::$app; $temp = new \yii\console\Application($this->appConfig); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; \Yii::$app->log->logger->flush(true); } }
/** * Run batch process to generate CRUDs all given tables * @throws \yii\console\Exception */ public function actionCruds() { // create CRUDs $providers = ArrayHelper::merge($this->crudProviders, Generator::getCoreProviders()); foreach ($this->tables as $table) { $table = str_replace($this->tablePrefix, '', $table); $name = isset($this->tableNameMap[$table]) ? $this->tableNameMap[$table] : Inflector::camelize($table); $params = ['interactive' => $this->interactive, 'overwrite' => $this->overwrite, 'template' => $this->template, 'modelClass' => $this->modelNamespace . '\\' . $name, 'searchModelClass' => $this->crudSearchModelNamespace . '\\' . $name, 'controllerClass' => $this->crudControllerNamespace . '\\' . $name . 'Controller', 'viewPath' => $this->crudViewPath, 'pathPrefix' => $this->crudPathPrefix, 'tablePrefix' => $this->tablePrefix, 'enableI18N' => $this->enableI18N, 'messageCategory' => $this->messageCategory, 'actionButtonClass' => 'yii\\grid\\ActionColumn', 'baseControllerClass' => $this->crudBaseControllerClass, 'providerList' => implode(',', $providers), 'skipRelations' => $this->crudSkipRelations]; $route = 'gii/giiant-crud'; $app = \Yii::$app; $temp = new \yii\console\Application($this->appConfig); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; } }
/** * Generate Giiant Model and Giiant CRUD using physical table * @param integer $id * @throws HttpException */ public function actionGenerate($id) { $table = $this->findModel($id); $setting = Setting::find()->where(["id" => 1])->one(); //Generate Model $params = ['interactive' => false, 'overwrite' => true, 'template' => "default", 'ns' => $setting->model_namespace, 'db' => "db", 'tableName' => $table->slug_name, 'tablePrefix' => "", 'enableI18N' => false, 'singularEntities' => true, 'messageCategory' => "app", 'generateModelClass' => false, 'baseClassSuffix' => "", 'modelClass' => Inflector::camelize($table->slug_name), 'baseClass' => "yii\\db\\ActiveRecord", 'baseTraits' => null, 'tableNameMap' => [], 'generateQuery' => false, 'queryNs' => 'app\\models\\query', 'queryBaseClass' => 'yii\\db\\ActiveQuery']; $route = 'gii/giiant-model'; $app = \Yii::$app; $config = $GLOBALS['config']; unset($config["components"]["errorHandler"]); unset($config["components"]["user"]); $temp = new \yii\console\Application($config); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; $table->model_class = $setting->model_namespace . "\\" . Inflector::camelize($table->slug_name); $table->model_base_class = $setting->model_namespace . "\\base\\" . Inflector::camelize($table->slug_name); $table->save(); //Generate CRUD $this->createDirectoryFromNamespace($setting->controller_namespace); $this->createDirectoryFromNamespace($setting->model_namespace . "\\search"); $name = Inflector::camelize($table->slug_name); $params = ['interactive' => false, 'overwrite' => true, 'template' => "default", 'modelClass' => $setting->model_namespace . '\\' . $name, 'searchModelClass' => $setting->model_namespace . '\\search\\' . $name, 'controllerNs' => $setting->controller_namespace, 'controllerClass' => $setting->controller_namespace . '\\' . $name . 'Controller', 'viewPath' => $setting->view_path, 'pathPrefix' => "", 'tablePrefix' => "", 'enableI18N' => false, 'singularEntities' => true, 'messageCategory' => "app", 'actionButtonClass' => "yii\\grid\\ActionColumn", 'baseControllerClass' => "yii\\web\\Controller", 'providerList' => [], 'skipRelations' => [], 'accessFilter' => true, 'tidyOutput' => true]; $route = 'gii/giiant-crud'; $app = \Yii::$app; $temp = new \yii\console\Application($config); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; \Yii::$app->log->logger->flush(true); $table->controller_class = $setting->controller_namespace . '\\' . $name . 'Controller'; $table->view_path = $setting->view_path . "/" . Util::slugify($table->slug_name); $table->save(); \Yii::$app->session->addFlash("success", "Generate Success."); $this->redirect(["table/index"]); }
<?php // ensure we get report on all possible php errors error_reporting(-1); define('YII_ENABLE_ERROR_HANDLER', false); define('YII_DEBUG', true); $_SERVER['SCRIPT_NAME'] = '/' . __DIR__; $_SERVER['SCRIPT_FILENAME'] = __FILE__; // require composer autoloader if available $vendor = __DIR__ . '/../vendor'; require_once $vendor . '/autoload.php'; require_once $vendor . '/yiisoft/yii2/Yii.php'; require_once __DIR__ . '/TestCase.php'; $count = count(glob(__DIR__ . '/migrations/*.php')); $config = (require __DIR__ . '/_config.php'); $app = new \yii\console\Application($config); $app->runAction('migrate/down', [$count, 'interactive' => 0, 'migrationPath' => '@app/tests/migrations']); $app->runAction('migrate', ['interactive' => 0, 'migrationPath' => '@app/tests/migrations']); $app = null;