Commit e562f8e4 by Thiago Talma Committed by Alexander Makarov

Enh #6857: Added `yii\gii\Module::$ignoreTables` that allows you to ignore…

Enh #6857: Added `yii\gii\Module::$ignoreTables` that allows you to ignore tables during model generation using `*`
parent 06564db6
...@@ -4,7 +4,7 @@ Yii Framework 2 gii extension Change Log ...@@ -4,7 +4,7 @@ Yii Framework 2 gii extension Change Log
2.0.3 under development 2.0.3 under development
----------------------- -----------------------
- no changes in this release. - Enh #6857: Added `yii\gii\Module::$ignoreTables` that allows you to ignore tables during model generation using `*` (thiagotalma)
2.0.2 January 11, 2015 2.0.2 January 11, 2015
......
...@@ -77,6 +77,11 @@ class Module extends \yii\base\Module implements BootstrapInterface ...@@ -77,6 +77,11 @@ class Module extends \yii\base\Module implements BootstrapInterface
* Defaults to 0777, meaning the directory can be read, written and executed by all users. * Defaults to 0777, meaning the directory can be read, written and executed by all users.
*/ */
public $newDirMode = 0777; public $newDirMode = 0777;
/**
* @var array the list of table names to be ignored.
* @since 2.0.3
*/
public $ignoreTables = [];
/** /**
......
...@@ -525,6 +525,7 @@ class Generator extends \yii\gii\Generator ...@@ -525,6 +525,7 @@ class Generator extends \yii\gii\Generator
} }
$tableNames = []; $tableNames = [];
if (strpos($this->tableName, '*') !== false) { if (strpos($this->tableName, '*') !== false) {
$module = Yii::$app->controller->module;
if (($pos = strrpos($this->tableName, '.')) !== false) { if (($pos = strrpos($this->tableName, '.')) !== false) {
$schema = substr($this->tableName, 0, $pos); $schema = substr($this->tableName, 0, $pos);
$pattern = '/^' . str_replace('*', '\w+', substr($this->tableName, $pos + 1)) . '$/'; $pattern = '/^' . str_replace('*', '\w+', substr($this->tableName, $pos + 1)) . '$/';
...@@ -534,6 +535,10 @@ class Generator extends \yii\gii\Generator ...@@ -534,6 +535,10 @@ class Generator extends \yii\gii\Generator
} }
foreach ($db->schema->getTableNames($schema) as $table) { foreach ($db->schema->getTableNames($schema) as $table) {
if (in_array($table, $module->ignoreTables)) {
continue;
}
if (preg_match($pattern, $table)) { if (preg_match($pattern, $table)) {
$tableNames[] = $schema === '' ? $table : ($schema . '.' . $table); $tableNames[] = $schema === '' ? $table : ($schema . '.' . $table);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment