Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
69ad9238
Commit
69ad9238
authored
Feb 04, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2304 from Ragazzo/fixture_controller_improved
controller improved
parents
023daf25
ff987aa4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
33 deletions
+17
-33
FixtureController.php
framework/console/controllers/FixtureController.php
+17
-33
No files found.
framework/console/controllers/FixtureController.php
View file @
69ad9238
...
...
@@ -12,6 +12,7 @@ use yii\console\Controller;
use
yii\console\Exception
;
use
yii\helpers\Console
;
use
yii\helpers\FileHelper
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Inflector
;
use
yii\test\FixtureTrait
;
...
...
@@ -119,25 +120,11 @@ class FixtureController extends Controller
throw
new
Exception
(
'No fixtures were found in namespace: "'
.
$this
->
namespace
.
'"'
.
''
);
}
$fixtures
=
$this
->
createFixtures
(
$fixtures
);
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
false
)
->
execute
();
/** @var \yii\test\Fixture $fixture */
foreach
(
$fixtures
as
$fixture
)
{
$fixture
->
beforeLoad
();
}
foreach
(
$fixtures
as
$fixture
)
{
$fixture
->
load
();
}
foreach
(
array_reverse
(
$fixtures
)
as
$fixture
)
{
$fixture
->
afterLoad
();
$this
->
stdout
(
" Fixture
\"
{
$fixture
::
className
()
}
\"
was successfully loaded.
\n
"
,
Console
::
FG_GREEN
);
}
$this
->
loadFixtures
(
$this
->
createFixtures
(
$fixtures
));
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
true
)
->
execute
();
$transaction
->
commit
();
}
catch
(
\Exception
$e
)
{
...
...
@@ -145,7 +132,7 @@ class FixtureController extends Controller
$this
->
stdout
(
"Exception occurred, transaction rollback. Tables will be in same state.
\n
"
,
Console
::
BG_RED
);
throw
$e
;
}
$this
->
notify
Success
(
$foundFixtures
);
$this
->
notify
Loaded
(
ArrayHelper
::
getColumn
(
$fixtures
,
'class'
,
false
)
);
}
/**
...
...
@@ -183,26 +170,11 @@ class FixtureController extends Controller
throw
new
Exception
(
'No fixtures were found in namespace: '
.
$this
->
namespace
.
'".'
);
}
$fixtures
=
$this
->
createFixtures
(
$fixtures
);
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
false
)
->
execute
();
/** @var \yii\test\Fixture $fixture */
foreach
(
$fixtures
as
$fixture
)
{
$fixture
->
beforeUnload
();
}
$fixtures
=
array_reverse
(
$fixtures
);
foreach
(
$fixtures
as
$fixture
)
{
$fixture
->
unload
();
}
foreach
(
$fixtures
as
$fixture
)
{
$fixture
->
afterUnload
();
$this
->
stdout
(
" Fixture
\"
{
$fixture
::
className
()
}
\"
was successfully unloaded.
\n
"
,
Console
::
FG_GREEN
);
}
$this
->
unloadFixtures
(
$this
->
createFixtures
(
$fixtures
));
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
true
)
->
execute
();
$transaction
->
commit
();
...
...
@@ -211,6 +183,7 @@ class FixtureController extends Controller
$this
->
stdout
(
"Exception occurred, transaction rollback. Tables will be in same state.
\n
"
,
Console
::
BG_RED
);
throw
$e
;
}
$this
->
notifyUnloaded
(
ArrayHelper
::
getColumn
(
$fixtures
,
'class'
,
false
));
}
/**
...
...
@@ -233,7 +206,18 @@ class FixtureController extends Controller
* Notifies user that fixtures were successfully loaded.
* @param array $fixtures
*/
private
function
notifySuccess
(
$fixtures
)
private
function
notifyLoaded
(
$fixtures
)
{
$this
->
stdout
(
"Fixtures were successfully loaded from namespace:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"
\t\"
"
.
Yii
::
getAlias
(
$this
->
namespace
)
.
"
\"\n\n
"
,
Console
::
FG_GREEN
);
$this
->
outputList
(
$fixtures
);
}
/**
* Notifies user that fixtures were successfully unloaded.
* @param array $fixtures
*/
private
function
notifyUnloaded
(
$fixtures
)
{
$this
->
stdout
(
"Fixtures were successfully loaded from namespace:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"
\t\"
"
.
Yii
::
getAlias
(
$this
->
namespace
)
.
"
\"\n\n
"
,
Console
::
FG_GREEN
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment