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
afa6ad5a
Commit
afa6ad5a
authored
Feb 05, 2014
by
Thiago Talma
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/yiisoft/yii2
parents
2a3c87b7
3e732a2b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
53 deletions
+76
-53
composer.json
composer.json
+1
-2
console-fixture.md
docs/guide/console-fixture.md
+25
-16
index.php
extensions/debug/views/default/index.php
+1
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
FixtureController.php
framework/console/controllers/FixtureController.php
+45
-33
Session.php
framework/web/Session.php
+3
-1
No files found.
composer.json
View file @
afa6ad5a
...
...
@@ -92,8 +92,7 @@
"fzaninotto/faker"
:
"required by yii2-faker extension"
,
"imagine/imagine"
:
"required by yii2-imagine extension"
,
"smarty/smarty"
:
"required by yii2-smarty extension"
,
"swiftmailer/swiftmailer"
:
"required by yii2-swiftmailer extension"
,
"twig/twig"
:
"required by yii2-twig extension"
"swiftmailer/swiftmailer"
:
"required by yii2-swiftmailer extension"
},
"autoload"
:
{
"psr-4"
:
{
...
...
docs/guide/console-fixture.md
View file @
afa6ad5a
...
...
@@ -49,36 +49,41 @@ Loading fixtures
Fixture classes should be suffixed by
`Fixture`
class. By default fixtures will be searched under
`tests\unit\fixtures`
namespace, you can
change this behavior with config or command options.
To
apply
fixture, run the following command:
To
load
fixture, run the following command:
```
yii fixture/
apply
<fixture_name>
yii fixture/
load
<fixture_name>
```
The required
`fixture_name`
parameter specifies a fixture name which data will be loaded. You can load several fixtures at once.
Below are correct formats of this command:
```
//
apply
`users` fixture
yii fixture/
apply
User
//
load
`users` fixture
yii fixture/
load
User
// same as above, because default action of "fixture" command is "
apply
"
// same as above, because default action of "fixture" command is "
load
"
yii fixture User
//
apply
several fixtures. Note that there should not be any whitespace between ",", it should be one string.
//
load
several fixtures. Note that there should not be any whitespace between ",", it should be one string.
yii fixture User,UserProfile
//
apply
all fixtures
yii fixture/
apply
all
//
load
all fixtures
yii fixture/
load
all
// same as above
yii fixture all
//
apply
fixtures, but for other database connection.
yii fixture
s
User --db='customDbConnectionId'
//
load
fixtures, but for other database connection.
yii fixture User --db='customDbConnectionId'
// apply fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
yii fixtures User --namespace='alias\my\custom\namespace'
// load fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
yii fixture User --namespace='alias\my\custom\namespace'
// load global fixture `some\name\space\CustomFixture` before other fixtures will be loaded.
// By default this option is set to `InitDbFixture` to disable/enable integrity checks. You can specify several
// global fixtures separated by comma.
yii fixture User --globalFixtures='some\name\space\Custom'
```
Unloading fixtures
...
...
@@ -88,16 +93,16 @@ To unload fixture, run the following command:
```
// unload Users fixture, by default it will clear fixture storage (for example "users" table, or "users" collection if this is mongodb fixture).
yii fixture/
clear
User
yii fixture/
unload
User
// Unload several fixtures. Note that there should not be any whitespace between ",", it should be one string.
yii fixture/
clear
User,UserProfile
yii fixture/
unload
User,UserProfile
// unload all fixtures
yii fixture/
clear
all
yii fixture/
unload
all
```
Same command options like:
`db`
,
`namespace`
also can be applied to this command.
Same command options like:
`db`
,
`namespace`
,
`globalFixtures`
also can be applied to this command.
Configure Command Globally
--------------------------
...
...
@@ -111,6 +116,10 @@ different migration path as follows:
'class' => 'yii\console\controllers\FixtureController',
'db' => 'customDbConnectionId',
'namespace' => 'myalias\some\custom\namespace',
'globalFixtures' => [
'some\name\space\Foo',
'other\name\space\Bar'
],
],
]
```
...
...
extensions/debug/views/default/index.php
View file @
afa6ad5a
...
...
@@ -67,7 +67,7 @@ echo GridView::widget([
if
(
$dbPanel
->
isQueryCountCritical
(
$data
[
'sqlCount'
]))
{
$content
=
Html
::
tag
(
'b'
,
$data
[
'sqlCount'
])
.
' '
.
Html
::
tag
(
'span'
,
''
,[
'class'
=>
'glyphicon glyphicon-exclamation-sign'
]);
return
Html
::
a
(
$content
,
$dbPanel
->
getUrl
()
,
[
return
Html
::
a
(
$content
,
[
'view'
,
'panel'
=>
'db'
,
'tag'
=>
$data
[
'tag'
]]
,
[
'title'
=>
'Too many queries. Allowed count is '
.
$dbPanel
->
criticalQueryThreshold
,
]);
...
...
framework/CHANGELOG.md
View file @
afa6ad5a
...
...
@@ -26,6 +26,7 @@ Yii Framework 2 Change Log
-
Bug #1710: OpenId auth client does not request required attributes correctly (klimov-paul)
-
Bug #1798: Fixed label attributes for array fields (zhuravljov)
-
Bug #1800: Better check for
`$_SERVER['HTTPS']`
in
`yii\web\Request::getIsSecureConnection()`
(ginus, samdark)
-
Bug #1812: Hide potential warning message due to race condition occurring to
`Session::regenerateID()`
call (qiangxue)
-
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)
...
...
framework/console/controllers/FixtureController.php
View file @
afa6ad5a
...
...
@@ -12,8 +12,6 @@ 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
;
/**
...
...
@@ -35,16 +33,16 @@ use yii\test\FixtureTrait;
*
* ~~~
* #load fixtures under $fixturePath from UsersFixture class with default namespace "tests\unit\fixtures"
* yii fixture/
apply
User
* yii fixture/
load
User
*
* #also a short version of this command (generate action is default)
* yii fixture User
*
* #load fixtures under $fixturePath with the different database connection
* yii fixture/
apply
User --db=someOtherDbConnection
* yii fixture/
load
User --db=someOtherDbConnection
*
* #load fixtures under different $fixturePath.
* yii fixture/
apply
User --namespace=alias\my\custom\namespace\goes\here
* yii fixture/
load
User --namespace=alias\my\custom\namespace\goes\here
* ~~~
*
* @author Mark Jebri <mark.github@yandex.ru>
...
...
@@ -68,11 +66,17 @@ class FixtureController extends Controller
* @var string id of the database connection component of the application.
*/
public
$db
=
'db'
;
/**
* @var string default namespace to search fixtures in
*/
public
$namespace
=
'tests\unit\fixtures'
;
/**
* @var array global fixtures that should be applied when loading and unloading. By default it is set to `InitDbFixture`
* that disables and enables integrity check, so your data can be safely loaded.
*/
public
$globalFixtures
=
[
'yii\test\InitDb'
,
];
/**
* Returns the names of the global options for this command.
...
...
@@ -81,18 +85,19 @@ class FixtureController extends Controller
public
function
globalOptions
()
{
return
array_merge
(
parent
::
globalOptions
(),
[
'db'
,
'namespace'
'db'
,
'namespace'
,
'globalFixtures'
]);
}
/**
* Apply given fixture to the table. You can load several fixtures specifying
* their names separated with commas, like: tbl_user,tbl_profile. Be sure there is no
* whitespace between tables names.
* Loads given fixture. You can load several fixtures specifying
* their names separated with commas, like: User,UserProfile,MyCustom. Be sure there is no
* whitespace between names. Note that if you are loading fixtures to storage, for example: database or nosql,
* storage will not be cleared, data will be appended to already existed.
* @param array $fixtures
* @throws \yii\console\Exception
*/
public
function
action
Apply
(
array
$fixtures
,
array
$except
=
[])
public
function
action
Load
(
array
$fixtures
,
array
$except
=
[])
{
$foundFixtures
=
$this
->
findFixtures
(
$fixtures
);
...
...
@@ -110,39 +115,38 @@ class FixtureController extends Controller
);
}
if
(
!
$this
->
confirm
Apply
(
$foundFixtures
,
$except
))
{
if
(
!
$this
->
confirm
Load
(
$foundFixtures
,
$except
))
{
return
;
}
$fixtures
=
$this
->
getFixturesConfig
(
array_diff
(
$foundFixtures
,
$except
));
$filtered
=
array_diff
(
$foundFixtures
,
$except
);
$fixtures
=
$this
->
getFixturesConfig
(
array_merge
(
$this
->
globalFixtures
,
$filtered
));
if
(
!
$fixtures
)
{
throw
new
Exception
(
'No fixtures were found in namespace: "'
.
$this
->
namespace
.
'"'
.
''
);
}
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
$transaction
=
$this
->
getDbConnection
()
->
beginTransaction
();
try
{
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
false
)
->
execute
();
$this
->
loadFixtures
(
$this
->
createFixtures
(
$fixtures
));
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
true
)
->
execute
();
$transaction
->
commit
();
}
catch
(
\Exception
$e
)
{
$transaction
->
rollback
();
$this
->
stdout
(
"Exception occurred, transaction rollback. Tables will be in same state.
\n
"
,
Console
::
BG_RED
);
throw
$e
;
}
$this
->
notifyLoaded
(
ArrayHelper
::
getColumn
(
$fixtures
,
'class'
,
false
)
);
$this
->
notifyLoaded
(
$fixtures
);
}
/**
* Unloads given fixtures. You can clear environment and unload multiple fixtures by specifying
* their names separated with commas, like:
tbl_user,tbl_profile
. Be sure there is no
* their names separated with commas, like:
User,UserProfile,MyCustom
. Be sure there is no
* whitespace between tables names.
* @param array|string $fixtures
* @param array|string $except
*/
public
function
action
Clear
(
array
$fixtures
,
array
$except
=
[])
public
function
action
Unload
(
array
$fixtures
,
array
$except
=
[])
{
$foundFixtures
=
$this
->
findFixtures
(
$fixtures
);
...
...
@@ -160,22 +164,21 @@ class FixtureController extends Controller
);
}
if
(
!
$this
->
confirm
Clear
(
$foundFixtures
,
$except
))
{
if
(
!
$this
->
confirm
Unload
(
$foundFixtures
,
$except
))
{
return
;
}
$fixtures
=
$this
->
getFixturesConfig
(
array_diff
(
$foundFixtures
,
$except
));
$filtered
=
array_diff
(
$foundFixtures
,
$except
);
$fixtures
=
$this
->
getFixturesConfig
(
array_merge
(
$this
->
globalFixtures
,
$filtered
));
if
(
!
$fixtures
)
{
throw
new
Exception
(
'No fixtures were found in namespace: '
.
$this
->
namespace
.
'".'
);
}
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
$transaction
=
$this
->
getDbConnection
()
->
beginTransaction
();
try
{
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
false
)
->
execute
();
$this
->
unloadFixtures
(
$this
->
createFixtures
(
$fixtures
));
$this
->
getDbConnection
()
->
createCommand
()
->
checkIntegrity
(
true
)
->
execute
();
$transaction
->
commit
();
}
catch
(
\Exception
$e
)
{
...
...
@@ -183,7 +186,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
)
);
$this
->
notifyUnloaded
(
$fixtures
);
}
/**
...
...
@@ -243,12 +246,17 @@ class FixtureController extends Controller
* @param array $except
* @return boolean
*/
private
function
confirm
Apply
(
$fixtures
,
$except
)
private
function
confirm
Load
(
$fixtures
,
$except
)
{
$this
->
stdout
(
"Fixtures namespace is:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"
\t
"
.
$this
->
namespace
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"Fixtures below will be loaded:
\n\n
"
,
Console
::
FG_YELLOW
);
if
(
count
(
$this
->
globalFixtures
))
{
$this
->
stdout
(
"Global fixtures will be loaded:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$this
->
globalFixtures
);
}
$this
->
stdout
(
"
\n
Fixtures below will be loaded:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$fixtures
);
if
(
count
(
$except
))
{
...
...
@@ -265,12 +273,17 @@ class FixtureController extends Controller
* @param array $except
* @return boolean
*/
private
function
confirm
Clear
(
$fixtures
,
$except
)
private
function
confirm
Unload
(
$fixtures
,
$except
)
{
$this
->
stdout
(
"Fixtures namespace is:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"
\t
"
.
$this
->
namespace
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"Fixtures below will be unloaded:
\n\n
"
,
Console
::
FG_YELLOW
);
if
(
count
(
$this
->
globalFixtures
))
{
$this
->
stdout
(
"Global fixtures will be unloaded:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$this
->
globalFixtures
);
}
$this
->
stdout
(
"
\n
Fixtures below will be unloaded:
\n\n
"
,
Console
::
FG_YELLOW
);
$this
->
outputList
(
$fixtures
);
if
(
count
(
$except
))
{
...
...
@@ -339,12 +352,11 @@ class FixtureController extends Controller
foreach
(
$fixtures
as
$fixture
)
{
$fullClassName
=
$this
->
namespace
.
'\\'
.
$fixture
.
'Fixture'
;
$isNamespaced
=
(
strpos
(
$fixture
,
'\\'
)
!==
false
);
$fullClassName
=
$isNamespaced
?
$fixture
.
'Fixture'
:
$this
->
namespace
.
'\\'
.
$fixture
.
'Fixture'
;
if
(
class_exists
(
$fullClassName
))
{
$config
[
Inflector
::
camel2id
(
$fixture
,
'_'
)]
=
[
'class'
=>
$fullClassName
,
];
$config
[]
=
$fullClassName
;
}
}
...
...
framework/web/Session.php
View file @
afa6ad5a
...
...
@@ -211,7 +211,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
*/
public
function
regenerateID
(
$deleteOldSession
=
false
)
{
session_regenerate_id
(
$deleteOldSession
);
// add @ to inhibit possible warning due to race condition
// https://github.com/yiisoft/yii2/pull/1812
@
session_regenerate_id
(
$deleteOldSession
);
}
/**
...
...
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