Skip to content

Commit

Permalink
Enh yiisoft#6857: Added yii\gii\Module::$ignoreTables that allows y…
Browse files Browse the repository at this point in the history
…ou to ignore tables during model generation using `*`
  • Loading branch information
thiagotalma authored and samdark committed Jan 24, 2015
1 parent 06564db commit e562f8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extensions/gii/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 gii extension Change Log
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
Expand Down
5 changes: 5 additions & 0 deletions extensions/gii/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
public $newDirMode = 0777;
/**
* @var array the list of table names to be ignored.
* @since 2.0.3
*/
public $ignoreTables = [];


/**
Expand Down
5 changes: 5 additions & 0 deletions extensions/gii/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ protected function getTableNames()
}
$tableNames = [];
if (strpos($this->tableName, '*') !== false) {
$module = Yii::$app->controller->module;
if (($pos = strrpos($this->tableName, '.')) !== false) {
$schema = substr($this->tableName, 0, $pos);
$pattern = '/^' . str_replace('*', '\w+', substr($this->tableName, $pos + 1)) . '$/';
Expand All @@ -534,6 +535,10 @@ protected function getTableNames()
}

foreach ($db->schema->getTableNames($schema) as $table) {
if (in_array($table, $module->ignoreTables)) {
continue;
}

if (preg_match($pattern, $table)) {
$tableNames[] = $schema === '' ? $table : ($schema . '.' . $table);
}
Expand Down

0 comments on commit e562f8e

Please sign in to comment.