Commit 205400f1 by Qiang Xue

Fixes #5176: `ActiveFixture` will reset table in its `load()` method instead of `unload()`

parent 014aab1b
...@@ -53,12 +53,13 @@ class ActiveFixture extends BaseActiveFixture ...@@ -53,12 +53,13 @@ class ActiveFixture extends BaseActiveFixture
/** /**
* Loads the fixture data. * Loads the fixture data.
* Data will be batch inserted into the given collection. * The default implementation will first reset the DB table and then populate it with the data
* returned by [[getData()]].
*/ */
public function load() public function load()
{ {
parent::load(); $this->resetCollection();
$this->data = [];
$data = $this->getData(); $data = $this->getData();
$this->getCollection()->batchInsert($data); $this->getCollection()->batchInsert($data);
foreach ($data as $alias => $row) { foreach ($data as $alias => $row) {
...@@ -66,17 +67,6 @@ class ActiveFixture extends BaseActiveFixture ...@@ -66,17 +67,6 @@ class ActiveFixture extends BaseActiveFixture
} }
} }
/**
* Unloads the fixture.
*
* The default implementation will clean up the collection by calling [[resetCollection()]].
*/
public function unload()
{
$this->resetCollection();
parent::unload();
}
protected function getCollection() protected function getCollection()
{ {
return $this->db->getCollection($this->getCollectionName()); return $this->db->getCollection($this->getCollectionName());
......
...@@ -285,6 +285,7 @@ Yii Framework 2 Change Log ...@@ -285,6 +285,7 @@ Yii Framework 2 Change Log
- Chg #4955: Replaced callbacks with events for `ActiveForm` (qiangxue) - Chg #4955: Replaced callbacks with events for `ActiveForm` (qiangxue)
- Removed `beforeValidate()`, `beforeValidateAll()`, `afterValidate()`, `afterValidateAll()`, `ajaxBeforeSend()` and `ajaxComplete()` from `ActiveForm`. - Removed `beforeValidate()`, `beforeValidateAll()`, `afterValidate()`, `afterValidateAll()`, `ajaxBeforeSend()` and `ajaxComplete()` from `ActiveForm`.
- Added `beforeValidate`, `afterValidate`, `beforeValidateAttribute`, `afterValidateAttribute`, `beforeSubmit`, `ajaxBeforeSend` and `ajaxComplete` events to `yii.activeForm` jQuery plugin. - Added `beforeValidate`, `afterValidate`, `beforeValidateAttribute`, `afterValidateAttribute`, `beforeSubmit`, `ajaxBeforeSend` and `ajaxComplete` events to `yii.activeForm` jQuery plugin.
- Chg #5176: `ActiveFixture` will reset table in its `load()` method instead of `unload()` (qiangxue)
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue) - Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue) - Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe) - Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
......
...@@ -65,6 +65,7 @@ class ActiveFixture extends BaseActiveFixture ...@@ -65,6 +65,7 @@ class ActiveFixture extends BaseActiveFixture
/** /**
* Loads the fixture. * Loads the fixture.
* *
* The default implementation will first clean up the table by calling [[resetTable()]].
* It will then populate the table with the data returned by [[getData()]]. * It will then populate the table with the data returned by [[getData()]].
* *
* If you override this method, you should consider calling the parent implementation * If you override this method, you should consider calling the parent implementation
...@@ -72,10 +73,9 @@ class ActiveFixture extends BaseActiveFixture ...@@ -72,10 +73,9 @@ class ActiveFixture extends BaseActiveFixture
*/ */
public function load() public function load()
{ {
parent::load(); $this->resetTable();
$this->data = [];
$table = $this->getTableSchema(); $table = $this->getTableSchema();
foreach ($this->getData() as $alias => $row) { foreach ($this->getData() as $alias => $row) {
$this->db->createCommand()->insert($table->fullName, $row)->execute(); $this->db->createCommand()->insert($table->fullName, $row)->execute();
if ($table->sequenceName !== null) { if ($table->sequenceName !== null) {
...@@ -91,17 +91,6 @@ class ActiveFixture extends BaseActiveFixture ...@@ -91,17 +91,6 @@ class ActiveFixture extends BaseActiveFixture
} }
/** /**
* Unloads the fixture.
*
* The default implementation will clean up the table by calling [[resetTable()]].
*/
public function unload()
{
$this->resetTable();
parent::unload();
}
/**
* Returns the fixture data. * Returns the fixture data.
* *
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]]. * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
......
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