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
55c686cb
Commit
55c686cb
authored
Jan 16, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
except option added
parent
c5022203
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
9 deletions
+27
-9
FixtureController.php
framework/console/controllers/FixtureController.php
+27
-9
No files found.
framework/console/controllers/FixtureController.php
View file @
55c686cb
...
...
@@ -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
(
$fixtures
,
$except
);
$this
->
getFixtureManager
()
->
basePath
=
$this
->
fixturePath
;
$this
->
getFixtureManager
()
->
db
=
$this
->
db
;
...
...
@@ -159,23 +161,25 @@ 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
{
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
false
)
->
execute
();
foreach
(
$tables
as
$table
)
{
$this
->
getDbConnection
()
->
createCommand
()
->
truncateTabl
e
(
$table
)
->
execute
();
$this
->
getDbConnection
()
->
createCommand
()
->
delet
e
(
$table
)
->
execute
();
$this
->
getDbConnection
()
->
createCommand
()
->
resetSequence
(
$table
)
->
execute
();
$this
->
stdout
(
" Table
\"
{
$table
}
\"
was successfully cleared.
\n
"
,
Console
::
FG_GREEN
);
}
...
...
@@ -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
(
"
\n
Fixtures that will NOT be loaded:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$except
);
}
return
$this
->
confirm
(
"
\n
Load 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
(
"
\n
Tables that will NOT be cleared:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$except
);
}
return
$this
->
confirm
(
"
\n
Clear tables?"
);
}
/**
...
...
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