Commit 369e4218 by Carsten Brandt

Merge branch 'fixtures_except_option_added' of https://github.com/Ragazzo/yii2…

Merge branch 'fixtures_except_option_added' of https://github.com/Ragazzo/yii2 into Ragazzo-fixtures_except_option_added * 'fixtures_except_option_added' of https://github.com/Ragazzo/yii2: filter fix changelog added changes of other pr reverted except option added Conflicts: framework/CHANGELOG.md
parents 1621c6fa e1c921a2
......@@ -25,6 +25,7 @@ Yii Framework 2 Change Log
- Bug #1798: Fixed label attributes for array fields (zhuravljov)
- Bug #1800: Better check for `$_SERVER['HTTPS']` in `yii\web\Request::getIsSecureConnection()` (ginus, samdark)
- Bug #1827: Debugger toolbar is loaded twice if an action is calling `run()` to execute another action (qiangxue)
- Bug #1868: Added ability to exclude tables from FixtureController apply/clear actions. (Ragazzo)
- Bug #1869: Fixed tables clearing. `TRUNCATE` changed to `DELETE` to avoid postgresql tables checks (and truncating all tables) (Ragazzo)
- Bug #1870: Validation errors weren't properly translated when using clientside validation (samdark)
- Bug #1930: Fixed domain based URL matching for website root (samdark)
......
......@@ -110,7 +110,7 @@ class FixtureController extends Controller
* @param array $fixtures
* @throws \yii\console\Exception
*/
public function actionApply(array $fixtures)
public function actionApply(array $fixtures, array $except = [])
{
if ($this->getFixtureManager() === null) {
throw new Exception('Fixture manager is not configured properly. Please refer to official documentation for this purposes.');
......@@ -132,10 +132,12 @@ class FixtureController extends Controller
);
}
if (!$this->confirmApply($foundFixtures)) {
if (!$this->confirmApply($foundFixtures, $except)) {
return;
}
$fixtures = array_diff($foundFixtures, $except);
$this->getFixtureManager()->basePath = $this->fixturePath;
$this->getFixtureManager()->db = $this->db;
......@@ -159,16 +161,18 @@ class FixtureController extends Controller
* whitespace between tables names.
* @param array|string $tables
*/
public function actionClear(array $tables)
public function actionClear(array $tables, array $except = ['tbl_migration'])
{
if ($this->needToApplyAll($tables[0])) {
$tables = $this->getDbConnection()->schema->getTableNames();
}
if (!$this->confirmClear($tables)) {
if (!$this->confirmClear($tables, $except)) {
return;
}
$tables = array_diff($tables, $except);
$transaction = Yii::$app->db->beginTransaction();
try {
......@@ -246,26 +250,40 @@ class FixtureController extends Controller
/**
* Prompts user with confirmation if fixtures should be loaded.
* @param array $fixtures
* @param array $except
* @return boolean
*/
private function confirmApply($fixtures)
private function confirmApply($fixtures, $except)
{
$this->stdout("Fixtures will be loaded from path: \n", Console::FG_YELLOW);
$this->stdout(Yii::getAlias($this->fixturePath) . "\n\n", Console::FG_GREEN);
$this->outputList($fixtures);
return $this->confirm('Load to database above fixtures?');
if (count($except)) {
$this->stdout("\nFixtures that will NOT be loaded: \n\n", Console::FG_YELLOW);
$this->outputList($except);
}
return $this->confirm("\nLoad to database above fixtures?");
}
/**
* Prompts user with confirmation for tables that should be cleared.
* @param array $tables
* @param array $except
* @return boolean
*/
private function confirmClear($tables)
private function confirmClear($tables, $except)
{
$this->stdout("Tables below will be cleared:\n\n", Console::FG_YELLOW);
$this->outputList($tables);
return $this->confirm('Clear tables?');
if (count($except)) {
$this->stdout("\nTables that will NOT be cleared:\n\n", Console::FG_YELLOW);
$this->outputList($except);
}
return $this->confirm("\nClear tables?");
}
/**
......
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