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
f4397f1b
Commit
f4397f1b
authored
Jan 04, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixture controller improved
parent
ccfb7638
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
9 deletions
+53
-9
FixtureController.php
framework/yii/console/controllers/FixtureController.php
+53
-9
No files found.
framework/yii/console/controllers/FixtureController.php
View file @
f4397f1b
...
@@ -11,6 +11,7 @@ use Yii;
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\console\Controller
;
use
yii\console\Controller
;
use
yii\console\Exception
;
use
yii\console\Exception
;
use
yii\test\DbTestTrait
;
use
yii\test\DbTestTrait
;
use
yii\helpers\Console
;
/**
/**
* This command manages fixtures load to the database tables.
* This command manages fixtures load to the database tables.
...
@@ -103,7 +104,7 @@ class FixtureController extends Controller
...
@@ -103,7 +104,7 @@ class FixtureController extends Controller
* you can specify table name as a second parameter.
* you can specify table name as a second parameter.
* @param string $fixture
* @param string $fixture
*/
*/
public
function
actionApply
(
array
$fixture
)
public
function
actionApply
(
array
$fixture
s
)
{
{
if
(
$this
->
getFixtureManager
()
==
null
)
{
if
(
$this
->
getFixtureManager
()
==
null
)
{
throw
new
Exception
(
throw
new
Exception
(
...
@@ -111,20 +112,30 @@ class FixtureController extends Controller
...
@@ -111,20 +112,30 @@ class FixtureController extends Controller
.
'Please refer to official documentation for this purposes.'
);
.
'Please refer to official documentation for this purposes.'
);
}
}
if
(
!
$this
->
confirmApply
(
$fixtures
))
{
return
;
}
$this
->
getFixtureManager
()
->
basePath
=
$this
->
fixturePath
;
$this
->
getFixtureManager
()
->
basePath
=
$this
->
fixturePath
;
$this
->
getFixtureManager
()
->
db
=
$this
->
db
;
$this
->
getFixtureManager
()
->
db
=
$this
->
db
;
$this
->
loadFixtures
(
$fixture
);
$this
->
loadFixtures
(
$fixture
s
);
$this
->
notifySuccess
(
$fixture
);
$this
->
notifySuccess
(
$fixture
s
);
}
}
/**
/**
* Truncate given table and clear all fixtures from it.
* Truncate given table and clear all fixtures from it.
* @param string $table
* @param string $table
s
*/
*/
public
function
actionClear
(
$table
)
public
function
actionClear
(
array
$tables
)
{
{
$this
->
getDbConnection
()
->
createCommand
()
->
truncateTable
(
$table
)
->
execute
();
if
(
!
$this
->
confirmClear
(
$tables
))
{
echo
"Table
\"
{
$table
}
\"
was successfully cleared.
\n
"
;
return
;
}
foreach
(
$tables
as
$table
)
{
$this
->
getDbConnection
()
->
createCommand
()
->
truncateTable
(
$table
)
->
execute
();
$this
->
stdout
(
"Table
\"
{
$table
}
\"
was successfully cleared.
\n
"
,
Console
::
FG_GREEN
);
}
}
}
/**
/**
...
@@ -165,9 +176,42 @@ class FixtureController extends Controller
...
@@ -165,9 +176,42 @@ class FixtureController extends Controller
{
{
$this
->
stdout
(
"Fixtures were successfully loaded from path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"Fixtures were successfully loaded from path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
fixturePath
))
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
fixturePath
))
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
outputList
(
$fixtures
);
}
foreach
(
$fixtures
as
$index
=>
$fixture
)
{
/**
$this
->
stdout
(
$index
+
1
.
". "
.
$fixture
.
"
\n
"
,
Console
::
FG_GREEN
);
* Prompts user with confirmation if fixtures should be loaded.
* @param array $fixtures
* @return boolean
*/
private
function
confirmApply
(
$fixtures
)
{
$this
->
stdout
(
"Fixtures will be loaded from path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
fixturePath
))
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
outputList
(
$fixtures
);
return
$this
->
confirm
(
'Load to database above fixtures?'
);
}
/**
* Prompts user with confirmation for tables that should be cleared.
* @param array $tables
* @return boolean
*/
private
function
confirmClear
(
$tables
)
{
$this
->
stdout
(
"Tables below will be cleared:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$tables
);
return
$this
->
confirm
(
'Clear tables?'
);
}
/**
* Outputs data to the console as a list.
* @param array $data
*/
private
function
outputList
(
$data
)
{
foreach
(
$data
as
$index
=>
$item
)
{
$this
->
stdout
(
$index
+
1
.
". "
.
$item
.
"
\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