From 87495f77aa95b27a464eafd7d4c65a7a2e30df99 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 4 Jan 2014 19:19:02 -0500 Subject: [PATCH 01/27] try to fix basic app travis test. --- apps/basic/.travis.yml | 5 +---- apps/basic/composer.json | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/basic/.travis.yml b/apps/basic/.travis.yml index 9b11e83..e8687e8 100644 --- a/apps/basic/.travis.yml +++ b/apps/basic/.travis.yml @@ -4,11 +4,8 @@ php: - 5.5 - 5.4 -install: - - composer require --prefer-dist --dev 'codeception/codeception \*' 'codeception/specify \*' - before_script: - php vendor/bin/codecept build script: - - php vendor/bin/codecept run \ No newline at end of file + - php vendor/bin/codecept run functional diff --git a/apps/basic/composer.json b/apps/basic/composer.json index 6170429..e45c994 100644 --- a/apps/basic/composer.json +++ b/apps/basic/composer.json @@ -22,7 +22,9 @@ "require-dev": { "yiisoft/yii2-codeception": "*", "yiisoft/yii2-debug": "*", - "yiisoft/yii2-gii": "*" + "yiisoft/yii2-gii": "*", + "codeception/codeception": "*", + "codeception/specify": "*" }, "scripts": { "post-create-project-cmd": [ From df44626c39608aab22617a28ef9e82637f81c279 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 06:15:42 +0400 Subject: [PATCH 02/27] docs added, guide style added. --- docs/guide/README.md | 8 + docs/guide/console-fixture.md | 105 +++++++++++++ docs/guide/console-migrate.md | 333 ++++++++++++++++++++++++++++++++++++++++++ docs/guide/debugger.md | 38 ----- docs/guide/migration.md | 333 ------------------------------------------ docs/guide/module-debug.md | 38 +++++ 6 files changed, 484 insertions(+), 371 deletions(-) create mode 100644 docs/guide/README.md create mode 100644 docs/guide/console-fixture.md create mode 100644 docs/guide/console-migrate.md delete mode 100644 docs/guide/debugger.md delete mode 100644 docs/guide/migration.md create mode 100644 docs/guide/module-debug.md diff --git a/docs/guide/README.md b/docs/guide/README.md new file mode 100644 index 0000000..5717e71 --- /dev/null +++ b/docs/guide/README.md @@ -0,0 +1,8 @@ +This folder contains official Yii 2 guides documentation. + +To add new guide, take the following steps: + +1. Create `guide-name` and put there relevant documentation; +2. If guide has more then one word in name, then it should be with dashes, like: `console-fixture.md`, `module-debug.md` +3. If your guide is for console commands, than its name should follow convention: `console-{command}.md` +4. If your guide is for custom modules, than its name should follow convention: `module-{moduleName}.md` diff --git a/docs/guide/console-fixture.md b/docs/guide/console-fixture.md new file mode 100644 index 0000000..0ec7401 --- /dev/null +++ b/docs/guide/console-fixture.md @@ -0,0 +1,105 @@ +Database Fixtures +================= + +Fixtures are important part of testing. Their main purpose is to populate you with data that needed by testing +different cases. With this data using your tests becoming more efficient and useful. + +Yii supports database fixtures via the `yii fixture` command line tool. This tool supports: + +* Applying new fixtures to database tables; +* Clearing, database tables (with sequences); +* Auto-generating fixtures and populating it with random data. + +Fixtures format +--------------- + +Fixtures are just plain php files returning array, as follows: + +``` +#users.php file under fixtures path + +return [ + [ + 'name' => 'Chase', + 'login' => 'lmayert', + 'email' => 'strosin.vernice@jerde.com', + 'auth_key' => 'K3nF70it7tzNsHddEiq0BZ0i-OU8S3xV', + 'password' => '$2y$13$WSyE5hHsG1rWN2jV8LRHzubilrCLI5Ev/iK0r3jRuwQEs2ldRu.a2', + ], + [ + 'name' => 'Celestine', + 'login' => 'napoleon69', + 'email' => 'aileen.barton@heaneyschumm.com', + 'auth_key' => 'dZlXsVnIDgIzFgX4EduAqkEPuphhOh9q', + 'password' => '$2y$13$kkgpvJ8lnjKo8RuoR30ay.RjDf15bMcHIF7Vz1zz/6viYG5xJExU6', + ], +]; +``` + +This data will be loaded to the `users`, but before it will be loaded table `users` will be cleared: all data deleted, sequence reseted. +Above fixture example was auto-generated by `yii2-faker` extension, read more about it in these [section](#auto-generating-fixtures). + +Applying fixtures +----------------- + +To apply fixture to the table, run the following command: + +``` +yii fixture/apply +``` + +The required `tbl_name` parameter specifies a database table to which data will be loaded. You can load data to several tables at once. +Below are correct formats of this command: + +``` +// apply fixtures to the "users" table of database +yii fixture/apply users + +// same as above, because default action of "fixture" command is "apply" +yii fixture users + +// apply several fixtures to several tables. Note that there should not be any whitespace between ",", it should be one string. +yii fixture users,users_profiles + +// apply fixtures to the table users, but fixtures will be taken from different path. +yii fixture users --fixturePath='@app/my/custom/path/to/fixtures' + +// apply fixtures to the table users, but for other database connection. +yii fixtures users --db='customDbConnectionId' +``` + +Clearing tables +--------------- + +To clear table, run the following command: + +``` +// clear given table: delete all data and reset sequence. +yii fixture/clear users + +// clear several tables. Note that there should not be any whitespace between ",", it should be one string. +yii fixture/clear users,users_profile +``` + +Configure Command Globally +-------------------------- +While command line options allow us to configure the migration command +on-the-fly, sometimes we may want to configure the command once for all. For example you can configure +different migration path as follows: + +``` +'controllerMap' => [ + 'fixture' => [ + 'class' => 'yii\console\FixtureController', + 'fixturePath' => '@app/my/custom/path/to/fixtures', + 'db' => 'customDbConnectionId', + ], +] +``` + +Auto-generating fixtures +------------------------ + +Yii also can auto-generate fixtures for you based on some template. You can generate your fixtures with different data on different languages and formats. +These feature is done by [Faker](https://github.com/fzaninotto/Faker) library and `yii2-faker` extension. +See extension [guide](https://github.com/yiisoft/yii2/tree/master/extensions/yii/faker) for more docs. diff --git a/docs/guide/console-migrate.md b/docs/guide/console-migrate.md new file mode 100644 index 0000000..7d31ca5 --- /dev/null +++ b/docs/guide/console-migrate.md @@ -0,0 +1,333 @@ +Database Migration +================== + +Like source code, the structure of a database evolves as a database-driven application is developed and maintained. For example, during development, a new table may be added; Or, after the application goes live, it may be discovered that an additional index is required. It is important to keep track of these structural database changes (called **migration**), just as changes to the source code is tracked using version control. If the source code and the database become out of sync, bugs will occur, or the whole application might break. For this reason, Yii provides a database migration +tool that can keep track of database migration history, apply new migrations, or revert existing ones. + +The following steps show how database migration is used by a team during development: + +1. Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.). +2. Tim commits the new migration into the source control system (e.g. Git, Mercurial). +3. Doug updates his repository from the source control system and receives the new migration. +4. Doug applies the migration to his local development database, thereby syncing his database to reflect the changes Tim made. + +Yii supports database migration via the `yii migrate` command line tool. This tool supports: + +* Creating new migrations +* Applying, reverting, and redoing migrations +* Showing migration history and new migrations + +Creating Migrations +------------------- + +To create a new migration, run the following command: + +``` +yii migrate/create +``` + +The required `name` parameter specifies a very brief description of the migration. For example, if the migration creates a new table named *news*, you'd use the command: + +``` +yii migrate/create create_news_table +``` + +As you'll shortly see, the `name` parameter +is used as part of a PHP class name in the migration. Therefore, it should only contain letters, +digits and/or underscore characters. + +The above command will create a new +file named `m101129_185401_create_news_table.php`. This file will be created within the `protected/migrations` directory. Initially, the migration file will be generated with the following code: + +```php +class m101129_185401_create_news_table extends \yii\db\Migration +{ + public function up() + { + } + + public function down() + { + echo "m101129_185401_create_news_table cannot be reverted.\n"; + return false; + } +} +``` + +Notice that the class name is the same as the file name, and follows the pattern +`m_`, where: + +* `` refers to the UTC timestamp (in the +format of `yymmdd_hhmmss`) when the migration is created, +* `` is taken from the command's `name` parameter. + +In the class, the `up()` method should contain the code implementing the actual database +migration. In other words, the `up()` method executes code that actually changes the database. The `down()` method may contain code that reverts the changes made by `up()`. + +Sometimes, it is impossible for the `down()` to undo the database migration. For example, if the migration deletes +table rows or an entire table, that data cannot be recovered in the `down()` method. In such +cases, the migration is called irreversible, meaning the database cannot be rolled back to +a previous state. When a migration is irreversible, as in the above generated code, the `down()` +method returns `false` to indicate that the migration cannot be reverted. + +As an example, let's show the migration about creating a news table. + +```php + +use yii\db\Schema; + +class m101129_185401_create_news_table extends \yii\db\Migration +{ + public function up() + { + $this->createTable('tbl_news', [ + 'id' => 'pk', + 'title' => Schema::TYPE_STRING . ' NOT NULL', + 'content' => Schema::TYPE_TEXT, + ]); + } + + public function down() + { + $this->dropTable('tbl_news'); + } + +} +``` + +The base class [\yii\db\Migration] exposes a database connection via `db` +property. You can use it for manipulating data and schema of a database. + +The column types used in this example are abstract types that will be replaced +by Yii with the corresponding types depended on your database management system. +You can use them to write database independent migrations. +For example `pk` will be replaced by `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY` +for MySQL and `integer PRIMARY KEY AUTOINCREMENT NOT NULL` for sqlite. +See documentation of [[QueryBuilder::getColumnType()]] for more details and a list +of available types. You may also use the constants defined in [[\yii\db\Schema]] to +define column types. + + +Transactional Migrations +------------------------ + +While performing complex DB migrations, we usually want to make sure that each +migration succeed or fail as a whole so that the database maintains the +consistency and integrity. In order to achieve this goal, we can exploit +DB transactions. We could use special methods `safeUp` and `safeDown` for these purposes. + +```php + +use yii\db\Schema; + +class m101129_185401_create_news_table extends \yii\db\Migration +{ + public function safeUp() + { + $this->createTable('tbl_news', [ + 'id' => 'pk', + 'title' => Schema::TYPE_STRING . ' NOT NULL', + 'content' => Schema::TYPE_TEXT, + ]); + + $this->createTable('tbl_user', [ + 'id' => 'pk', + 'login' => Schema::TYPE_STRING . ' NOT NULL', + 'password' => Schema::TYPE_STRING . ' NOT NULL', + ]); + } + + public function safeDown() + { + $this->dropTable('tbl_news); + $this->dropTable('tbl_user'); + } + +} +``` + +When your code uses more then one query it is recommended to use `safeUp` and `safeDown`. + +> Note: Not all DBMS support transactions. And some DB queries cannot be put +> into a transaction. In this case, you will have to implement `up()` and +> `down()`, instead. And for MySQL, some SQL statements may cause +> [implicit commit](http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html). + + +Applying Migrations +------------------- + +To apply all available new migrations (i.e., make the local database up-to-date), +run the following command: + +``` +yii migrate +``` + +The command will show the list of all new migrations. If you confirm to apply +the migrations, it will run the `up()` method in every new migration class, one +after another, in the order of the timestamp value in the class name. + +After applying a migration, the migration tool will keep a record in a database +table named `tbl_migration`. This allows the tool to identify which migrations +have been applied and which are not. If the `tbl_migration` table does not exist, +the tool will automatically create it in the database specified by the `db` +application component. + +Sometimes, we may only want to apply one or a few new migrations. We can use the +following command: + +``` +yii migrate/up 3 +``` + +This command will apply the 3 new migrations. Changing the value 3 will allow +us to change the number of migrations to be applied. + +We can also migrate the database to a specific version with the following command: + +``` +yii migrate/to 101129_185401 +``` + +That is, we use the timestamp part of a migration name to specify the version +that we want to migrate the database to. If there are multiple migrations between +the last applied migration and the specified migration, all these migrations +will be applied. If the specified migration has been applied before, then all +migrations applied after it will be reverted (to be described in the next section). + + +Reverting Migrations +-------------------- + +To revert the last one or several applied migrations, we can use the following +command: + +``` +yii migrate/down [step] +``` + +where the optional `step` parameter specifies how many migrations to be reverted +back. It defaults to 1, meaning reverting back the last applied migration. + +As we described before, not all migrations can be reverted. Trying to revert +such migrations will throw an exception and stop the whole reverting process. + + +Redoing Migrations +------------------ + +Redoing migrations means first reverting and then applying the specified migrations. +This can be done with the following command: + +``` +yii migrate/redo [step] +``` + +where the optional `step` parameter specifies how many migrations to be redone. +It defaults to 1, meaning redoing the last migration. + + +Showing Migration Information +----------------------------- + +Besides applying and reverting migrations, the migration tool can also display +the migration history and the new migrations to be applied. + +``` +yii migrate/history [limit] +yii migrate/new [limit] +``` + +where the optional parameter `limit` specifies the number of migrations to be +displayed. If `limit` is not specified, all available migrations will be displayed. + +The first command shows the migrations that have been applied, while the second +command shows the migrations that have not been applied. + + +Modifying Migration History +--------------------------- + +Sometimes, we may want to modify the migration history to a specific migration +version without actually applying or reverting the relevant migrations. This +often happens when developing a new migration. We can use the following command +to achieve this goal. + +``` +yii migrate/mark 101129_185401 +``` + +This command is very similar to `yii migrate/to` command, except that it only +modifies the migration history table to the specified version without applying +or reverting the migrations. + + +Customizing Migration Command +----------------------------- + +There are several ways to customize the migration command. + +### Use Command Line Options + +The migration command comes with four options that can be specified in command +line: + +* `interactive`: boolean, specifies whether to perform migrations in an + interactive mode. Defaults to true, meaning the user will be prompted when + performing a specific migration. You may set this to false should the + migrations be done in a background process. + +* `migrationPath`: string, specifies the directory storing all migration class + files. This must be specified in terms of a path alias, and the corresponding + directory must exist. If not specified, it will use the `migrations` + sub-directory under the application base path. + +* `migrationTable`: string, specifies the name of the database table for storing + migration history information. It defaults to `tbl_migration`. The table + structure is `version varchar(255) primary key, apply_time integer`. + +* `connectionID`: string, specifies the ID of the database application component. + Defaults to 'db'. + +* `templateFile`: string, specifies the path of the file to be served as the code + template for generating the migration classes. This must be specified in terms + of a path alias (e.g. `application.migrations.template`). If not set, an + internal template will be used. Inside the template, the token `{ClassName}` + will be replaced with the actual migration class name. + +To specify these options, execute the migrate command using the following format + +``` +yii migrate/up --option1=value1 --option2=value2 ... +``` + +For example, if we want to migrate for a `forum` module whose migration files +are located within the module's `migrations` directory, we can use the following +command: + +``` +yii migrate/up --migrationPath=@app/modules/forum/migrations +``` + + +### Configure Command Globally + +While command line options allow us to configure the migration command +on-the-fly, sometimes we may want to configure the command once for all. +For example, we may want to use a different table to store the migration history, +or we may want to use a customized migration template. We can do so by modifying +the console application's configuration file like the following, + +```php +'controllerMap' => [ + 'migrate' => [ + 'class' => 'yii\console\MigrateController', + 'migrationTable' => 'my_custom_migrate_table', + ], +] +``` + +Now if we run the `migrate` command, the above configurations will take effect +without requiring us to enter the command line options every time. Other command options +can be also configured this way. diff --git a/docs/guide/debugger.md b/docs/guide/debugger.md deleted file mode 100644 index 710f7a3..0000000 --- a/docs/guide/debugger.md +++ /dev/null @@ -1,38 +0,0 @@ -Debug toolbar and debugger -========================== - -Yii2 includes a handy toolbar to aid faster development and debugging as well as debugger. Toolbar displays information -about currently opened page while using debugger you can analyze data collected before. - -Installing and configuring --------------------------- - -Add these lines to your config file: - -``` -'preload' => ['debug'], -'modules' => [ - 'debug' => ['yii\debug\Module'] -] -``` - -**Watch out: by default the debug module only works when browsing the website from the localhost. If you want to use it -on a remote (staging) server, add the parameter allowedIPs to the config to whitelist your IP, e.g. :** - -``` -'preload' => ['debug'], -'modules' => [ - 'debug' => [ - 'class'=>'yii\debug\Module', - 'allowedIPs'=>['1.2.3.4', '127.0.0.1', '::1'] - ] -] -``` - -How to use it -------------- - - -Creating your own panels ------------------------- - diff --git a/docs/guide/migration.md b/docs/guide/migration.md deleted file mode 100644 index 7d31ca5..0000000 --- a/docs/guide/migration.md +++ /dev/null @@ -1,333 +0,0 @@ -Database Migration -================== - -Like source code, the structure of a database evolves as a database-driven application is developed and maintained. For example, during development, a new table may be added; Or, after the application goes live, it may be discovered that an additional index is required. It is important to keep track of these structural database changes (called **migration**), just as changes to the source code is tracked using version control. If the source code and the database become out of sync, bugs will occur, or the whole application might break. For this reason, Yii provides a database migration -tool that can keep track of database migration history, apply new migrations, or revert existing ones. - -The following steps show how database migration is used by a team during development: - -1. Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.). -2. Tim commits the new migration into the source control system (e.g. Git, Mercurial). -3. Doug updates his repository from the source control system and receives the new migration. -4. Doug applies the migration to his local development database, thereby syncing his database to reflect the changes Tim made. - -Yii supports database migration via the `yii migrate` command line tool. This tool supports: - -* Creating new migrations -* Applying, reverting, and redoing migrations -* Showing migration history and new migrations - -Creating Migrations -------------------- - -To create a new migration, run the following command: - -``` -yii migrate/create -``` - -The required `name` parameter specifies a very brief description of the migration. For example, if the migration creates a new table named *news*, you'd use the command: - -``` -yii migrate/create create_news_table -``` - -As you'll shortly see, the `name` parameter -is used as part of a PHP class name in the migration. Therefore, it should only contain letters, -digits and/or underscore characters. - -The above command will create a new -file named `m101129_185401_create_news_table.php`. This file will be created within the `protected/migrations` directory. Initially, the migration file will be generated with the following code: - -```php -class m101129_185401_create_news_table extends \yii\db\Migration -{ - public function up() - { - } - - public function down() - { - echo "m101129_185401_create_news_table cannot be reverted.\n"; - return false; - } -} -``` - -Notice that the class name is the same as the file name, and follows the pattern -`m_`, where: - -* `` refers to the UTC timestamp (in the -format of `yymmdd_hhmmss`) when the migration is created, -* `` is taken from the command's `name` parameter. - -In the class, the `up()` method should contain the code implementing the actual database -migration. In other words, the `up()` method executes code that actually changes the database. The `down()` method may contain code that reverts the changes made by `up()`. - -Sometimes, it is impossible for the `down()` to undo the database migration. For example, if the migration deletes -table rows or an entire table, that data cannot be recovered in the `down()` method. In such -cases, the migration is called irreversible, meaning the database cannot be rolled back to -a previous state. When a migration is irreversible, as in the above generated code, the `down()` -method returns `false` to indicate that the migration cannot be reverted. - -As an example, let's show the migration about creating a news table. - -```php - -use yii\db\Schema; - -class m101129_185401_create_news_table extends \yii\db\Migration -{ - public function up() - { - $this->createTable('tbl_news', [ - 'id' => 'pk', - 'title' => Schema::TYPE_STRING . ' NOT NULL', - 'content' => Schema::TYPE_TEXT, - ]); - } - - public function down() - { - $this->dropTable('tbl_news'); - } - -} -``` - -The base class [\yii\db\Migration] exposes a database connection via `db` -property. You can use it for manipulating data and schema of a database. - -The column types used in this example are abstract types that will be replaced -by Yii with the corresponding types depended on your database management system. -You can use them to write database independent migrations. -For example `pk` will be replaced by `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY` -for MySQL and `integer PRIMARY KEY AUTOINCREMENT NOT NULL` for sqlite. -See documentation of [[QueryBuilder::getColumnType()]] for more details and a list -of available types. You may also use the constants defined in [[\yii\db\Schema]] to -define column types. - - -Transactional Migrations ------------------------- - -While performing complex DB migrations, we usually want to make sure that each -migration succeed or fail as a whole so that the database maintains the -consistency and integrity. In order to achieve this goal, we can exploit -DB transactions. We could use special methods `safeUp` and `safeDown` for these purposes. - -```php - -use yii\db\Schema; - -class m101129_185401_create_news_table extends \yii\db\Migration -{ - public function safeUp() - { - $this->createTable('tbl_news', [ - 'id' => 'pk', - 'title' => Schema::TYPE_STRING . ' NOT NULL', - 'content' => Schema::TYPE_TEXT, - ]); - - $this->createTable('tbl_user', [ - 'id' => 'pk', - 'login' => Schema::TYPE_STRING . ' NOT NULL', - 'password' => Schema::TYPE_STRING . ' NOT NULL', - ]); - } - - public function safeDown() - { - $this->dropTable('tbl_news); - $this->dropTable('tbl_user'); - } - -} -``` - -When your code uses more then one query it is recommended to use `safeUp` and `safeDown`. - -> Note: Not all DBMS support transactions. And some DB queries cannot be put -> into a transaction. In this case, you will have to implement `up()` and -> `down()`, instead. And for MySQL, some SQL statements may cause -> [implicit commit](http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html). - - -Applying Migrations -------------------- - -To apply all available new migrations (i.e., make the local database up-to-date), -run the following command: - -``` -yii migrate -``` - -The command will show the list of all new migrations. If you confirm to apply -the migrations, it will run the `up()` method in every new migration class, one -after another, in the order of the timestamp value in the class name. - -After applying a migration, the migration tool will keep a record in a database -table named `tbl_migration`. This allows the tool to identify which migrations -have been applied and which are not. If the `tbl_migration` table does not exist, -the tool will automatically create it in the database specified by the `db` -application component. - -Sometimes, we may only want to apply one or a few new migrations. We can use the -following command: - -``` -yii migrate/up 3 -``` - -This command will apply the 3 new migrations. Changing the value 3 will allow -us to change the number of migrations to be applied. - -We can also migrate the database to a specific version with the following command: - -``` -yii migrate/to 101129_185401 -``` - -That is, we use the timestamp part of a migration name to specify the version -that we want to migrate the database to. If there are multiple migrations between -the last applied migration and the specified migration, all these migrations -will be applied. If the specified migration has been applied before, then all -migrations applied after it will be reverted (to be described in the next section). - - -Reverting Migrations --------------------- - -To revert the last one or several applied migrations, we can use the following -command: - -``` -yii migrate/down [step] -``` - -where the optional `step` parameter specifies how many migrations to be reverted -back. It defaults to 1, meaning reverting back the last applied migration. - -As we described before, not all migrations can be reverted. Trying to revert -such migrations will throw an exception and stop the whole reverting process. - - -Redoing Migrations ------------------- - -Redoing migrations means first reverting and then applying the specified migrations. -This can be done with the following command: - -``` -yii migrate/redo [step] -``` - -where the optional `step` parameter specifies how many migrations to be redone. -It defaults to 1, meaning redoing the last migration. - - -Showing Migration Information ------------------------------ - -Besides applying and reverting migrations, the migration tool can also display -the migration history and the new migrations to be applied. - -``` -yii migrate/history [limit] -yii migrate/new [limit] -``` - -where the optional parameter `limit` specifies the number of migrations to be -displayed. If `limit` is not specified, all available migrations will be displayed. - -The first command shows the migrations that have been applied, while the second -command shows the migrations that have not been applied. - - -Modifying Migration History ---------------------------- - -Sometimes, we may want to modify the migration history to a specific migration -version without actually applying or reverting the relevant migrations. This -often happens when developing a new migration. We can use the following command -to achieve this goal. - -``` -yii migrate/mark 101129_185401 -``` - -This command is very similar to `yii migrate/to` command, except that it only -modifies the migration history table to the specified version without applying -or reverting the migrations. - - -Customizing Migration Command ------------------------------ - -There are several ways to customize the migration command. - -### Use Command Line Options - -The migration command comes with four options that can be specified in command -line: - -* `interactive`: boolean, specifies whether to perform migrations in an - interactive mode. Defaults to true, meaning the user will be prompted when - performing a specific migration. You may set this to false should the - migrations be done in a background process. - -* `migrationPath`: string, specifies the directory storing all migration class - files. This must be specified in terms of a path alias, and the corresponding - directory must exist. If not specified, it will use the `migrations` - sub-directory under the application base path. - -* `migrationTable`: string, specifies the name of the database table for storing - migration history information. It defaults to `tbl_migration`. The table - structure is `version varchar(255) primary key, apply_time integer`. - -* `connectionID`: string, specifies the ID of the database application component. - Defaults to 'db'. - -* `templateFile`: string, specifies the path of the file to be served as the code - template for generating the migration classes. This must be specified in terms - of a path alias (e.g. `application.migrations.template`). If not set, an - internal template will be used. Inside the template, the token `{ClassName}` - will be replaced with the actual migration class name. - -To specify these options, execute the migrate command using the following format - -``` -yii migrate/up --option1=value1 --option2=value2 ... -``` - -For example, if we want to migrate for a `forum` module whose migration files -are located within the module's `migrations` directory, we can use the following -command: - -``` -yii migrate/up --migrationPath=@app/modules/forum/migrations -``` - - -### Configure Command Globally - -While command line options allow us to configure the migration command -on-the-fly, sometimes we may want to configure the command once for all. -For example, we may want to use a different table to store the migration history, -or we may want to use a customized migration template. We can do so by modifying -the console application's configuration file like the following, - -```php -'controllerMap' => [ - 'migrate' => [ - 'class' => 'yii\console\MigrateController', - 'migrationTable' => 'my_custom_migrate_table', - ], -] -``` - -Now if we run the `migrate` command, the above configurations will take effect -without requiring us to enter the command line options every time. Other command options -can be also configured this way. diff --git a/docs/guide/module-debug.md b/docs/guide/module-debug.md new file mode 100644 index 0000000..710f7a3 --- /dev/null +++ b/docs/guide/module-debug.md @@ -0,0 +1,38 @@ +Debug toolbar and debugger +========================== + +Yii2 includes a handy toolbar to aid faster development and debugging as well as debugger. Toolbar displays information +about currently opened page while using debugger you can analyze data collected before. + +Installing and configuring +-------------------------- + +Add these lines to your config file: + +``` +'preload' => ['debug'], +'modules' => [ + 'debug' => ['yii\debug\Module'] +] +``` + +**Watch out: by default the debug module only works when browsing the website from the localhost. If you want to use it +on a remote (staging) server, add the parameter allowedIPs to the config to whitelist your IP, e.g. :** + +``` +'preload' => ['debug'], +'modules' => [ + 'debug' => [ + 'class'=>'yii\debug\Module', + 'allowedIPs'=>['1.2.3.4', '127.0.0.1', '::1'] + ] +] +``` + +How to use it +------------- + + +Creating your own panels +------------------------ + From f93666d1961f05605836128232750151fa3922c8 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 06:17:06 +0400 Subject: [PATCH 03/27] formatting fix --- docs/guide/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/README.md b/docs/guide/README.md index 5717e71..60ee8fb 100644 --- a/docs/guide/README.md +++ b/docs/guide/README.md @@ -3,6 +3,6 @@ This folder contains official Yii 2 guides documentation. To add new guide, take the following steps: 1. Create `guide-name` and put there relevant documentation; -2. If guide has more then one word in name, then it should be with dashes, like: `console-fixture.md`, `module-debug.md` -3. If your guide is for console commands, than its name should follow convention: `console-{command}.md` -4. If your guide is for custom modules, than its name should follow convention: `module-{moduleName}.md` +2. If guide has more then one word in name, then it should be with dashes, like: `console-fixture.md`, `module-debug.md`; +3. If your guide is for console commands, than its name should follow convention: `console-{command}.md`; +4. If your guide is for custom modules, than its name should follow convention: `module-{moduleName}.md`. From 51bfe1a3a439c1a491303d30e8845801c37e4f67 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 06:20:48 +0400 Subject: [PATCH 04/27] docs added --- docs/guide/console-fixture.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/guide/console-fixture.md b/docs/guide/console-fixture.md index 0ec7401..01b136f 100644 --- a/docs/guide/console-fixture.md +++ b/docs/guide/console-fixture.md @@ -13,7 +13,8 @@ Yii supports database fixtures via the `yii fixture` command line tool. This too Fixtures format --------------- -Fixtures are just plain php files returning array, as follows: +Fixtures are just plain php files returning array. These files are usually stored under `@tests/unit/fixtures` path, but it +can be [configured](#configure-command-globally) in other way. Example of fixture file: ``` #users.php file under fixtures path From 7a3583e7b4c7b7fd863a82beed3ea4abe8788010 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 04:04:33 +0100 Subject: [PATCH 05/27] fixed broken links in guide index [ci skip] --- docs/guide/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index a560a3c..65436ad 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -32,13 +32,13 @@ Database - [Basics](database-basics.md) - Connecting to a database, basic queries, transactions and schema manipulation - [Query Builder](query-builder.md) - Querying the database using a simple abstraction layer - [ActiveRecord](active-record.md) - The active record ORM, retrieving and manipulatings records and defining relations -- [Database Migration](migration.md) - Versioning your database with database migrations +- [Database Migration](console-migrate.md) - Versioning your database with database migrations Developers Toolbox ================== - [Automatic Code Generation](gii.md) -- [Debug toolbar and debugger](debugger.md) +- [Debug toolbar and debugger](module-debug.md) - [Error Handling](error.md) - [Logging](logging.md) From 1c6872ad3e3400bf2c101f53b4468267d4c7301d Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 04:07:21 +0100 Subject: [PATCH 06/27] fixed basic app build --- apps/basic/.travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/basic/.travis.yml b/apps/basic/.travis.yml index e8687e8..0feafd5 100644 --- a/apps/basic/.travis.yml +++ b/apps/basic/.travis.yml @@ -5,6 +5,7 @@ php: - 5.4 before_script: + - composer install --dev --prefer-dist - php vendor/bin/codecept build script: From a04e77e5b6a948a6966534b90d892c5d85b9b0f4 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 12:31:56 +0100 Subject: [PATCH 07/27] removed unused log level from debug dropdown the LogPanel already filters out profile so it does not make sense adding it here. --- extensions/yii/debug/views/default/panels/log/detail.php | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/yii/debug/views/default/panels/log/detail.php b/extensions/yii/debug/views/default/panels/log/detail.php index 7460516..f3a1cd1 100644 --- a/extensions/yii/debug/views/default/panels/log/detail.php +++ b/extensions/yii/debug/views/default/panels/log/detail.php @@ -43,7 +43,6 @@ echo GridView::widget([ Logger::LEVEL_INFO => ' Info ', Logger::LEVEL_WARNING => ' Warning ', Logger::LEVEL_ERROR => ' Error ', - Logger::LEVEL_PROFILE => ' Profile ', ], ], 'category', From 5f7653b0c72b6ffba36a48fc856054651536454d Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 12:49:37 +0100 Subject: [PATCH 08/27] run basic app functional tests within the main repo test chain --- .travis.yml | 5 +++++ apps/basic/.travis.yml | 12 ------------ 2 files changed, 5 insertions(+), 12 deletions(-) delete mode 100644 apps/basic/.travis.yml diff --git a/.travis.yml b/.travis.yml index 957efad..544f556 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ services: - mongodb install: +# core framework: - composer self-update && composer --version # - composer require satooshi/php-coveralls 0.6.* --dev --prefer-dist - composer install --prefer-dist @@ -19,6 +20,9 @@ install: - tests/unit/data/travis/apc-setup.sh - tests/unit/data/travis/memcache-setup.sh - tests/unit/data/travis/cubrid-setup.sh +# basic application: + - composer install --dev --prefer-dist -d apps/basic + - cd apps/basic && php vendor/bin/codecept build && cd ../.. before_script: - echo 'elasticsearch version ' && curl http://localhost:9200/ @@ -29,6 +33,7 @@ before_script: script: - vendor/bin/phpunit --coverage-text --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor + - cd apps/basic && php vendor/bin/codecept run functional && cd ../.. #after_script: # - php vendor/bin/coveralls diff --git a/apps/basic/.travis.yml b/apps/basic/.travis.yml deleted file mode 100644 index 0feafd5..0000000 --- a/apps/basic/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: php - -php: - - 5.5 - - 5.4 - -before_script: - - composer install --dev --prefer-dist - - php vendor/bin/codecept build - -script: - - php vendor/bin/codecept run functional From b7800eca605c1b2b96c44e9c6622f0fd6e4ec816 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 13:01:24 +0100 Subject: [PATCH 09/27] enabled acceptance tests for basic application --- .travis.yml | 9 ++++++--- apps/basic/tests/acceptance.suite.yml | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 544f556..5aa71e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ services: - mongodb install: -# core framework: - composer self-update && composer --version +# core framework: # - composer require satooshi/php-coveralls 0.6.* --dev --prefer-dist - composer install --prefer-dist - tests/unit/data/travis/mongodb-setup.sh @@ -23,6 +23,8 @@ install: # basic application: - composer install --dev --prefer-dist -d apps/basic - cd apps/basic && php vendor/bin/codecept build && cd ../.. + - cd apps/basic/web && php -S localhost:8080 & + - cd ../../.. before_script: - echo 'elasticsearch version ' && curl http://localhost:9200/ @@ -32,8 +34,9 @@ before_script: - mongo yii2test --eval 'db.addUser("travis", "test");' script: - - vendor/bin/phpunit --coverage-text --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor - - cd apps/basic && php vendor/bin/codecept run functional && cd ../.. +# - vendor/bin/phpunit --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor + - vendor/bin/phpunit --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor + - cd apps/basic && php vendor/bin/codecept run && cd ../.. #after_script: # - php vendor/bin/coveralls diff --git a/apps/basic/tests/acceptance.suite.yml b/apps/basic/tests/acceptance.suite.yml index f4d36f5..34e4397 100644 --- a/apps/basic/tests/acceptance.suite.yml +++ b/apps/basic/tests/acceptance.suite.yml @@ -18,7 +18,7 @@ modules: # - WebDriver config: PhpBrowser: - url: 'http://localhost' + url: 'http://localhost:8080' # WebDriver: # url: 'http://localhost' # browser: firefox From fe749e45fb3d15bff09e613df3f912b9f60317f3 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 13:09:21 +0100 Subject: [PATCH 10/27] fixed issue with too long th columns in debugger fixes #1787 --- extensions/yii/debug/assets/main.css | 4 ++-- extensions/yii/debug/views/default/panels/db/detail.php | 1 + extensions/yii/debug/views/default/panels/log/detail.php | 1 + extensions/yii/debug/views/default/panels/profile/detail.php | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/yii/debug/assets/main.css b/extensions/yii/debug/assets/main.css index 63df423..cc38766 100644 --- a/extensions/yii/debug/assets/main.css +++ b/extensions/yii/debug/assets/main.css @@ -28,12 +28,12 @@ ul.trace { float: right; } -td { +td, th { white-space: pre-line; word-wrap: break-word; } -th { +.detail-grid-view th { white-space: nowrap; } diff --git a/extensions/yii/debug/views/default/panels/db/detail.php b/extensions/yii/debug/views/default/panels/db/detail.php index 826c045..ee5b2a5 100644 --- a/extensions/yii/debug/views/default/panels/db/detail.php +++ b/extensions/yii/debug/views/default/panels/db/detail.php @@ -9,6 +9,7 @@ use yii\grid\GridView; echo GridView::widget([ 'dataProvider' => $dataProvider, 'id' => 'db-panel-detailed-grid', + 'options' => ['class' => 'detail-grid-view'], 'filterModel' => $searchModel, 'filterUrl' => $panel->getUrl(), 'columns' => [ diff --git a/extensions/yii/debug/views/default/panels/log/detail.php b/extensions/yii/debug/views/default/panels/log/detail.php index f3a1cd1..83f9817 100644 --- a/extensions/yii/debug/views/default/panels/log/detail.php +++ b/extensions/yii/debug/views/default/panels/log/detail.php @@ -10,6 +10,7 @@ use yii\log\Logger; echo GridView::widget([ 'dataProvider' => $dataProvider, 'id' => 'log-panel-detailed-grid', + 'options' => ['class' => 'detail-grid-view'], 'filterModel' => $searchModel, 'filterUrl' => $panel->getUrl(), 'rowOptions' => function ($model, $key, $index, $grid) { diff --git a/extensions/yii/debug/views/default/panels/profile/detail.php b/extensions/yii/debug/views/default/panels/profile/detail.php index 842795a..95c50e1 100644 --- a/extensions/yii/debug/views/default/panels/profile/detail.php +++ b/extensions/yii/debug/views/default/panels/profile/detail.php @@ -8,6 +8,7 @@ use yii\helpers\Html; echo GridView::widget([ 'dataProvider' => $dataProvider, 'id' => 'profile-panel-detailed-grid', + 'options' => ['class' => 'detail-grid-view'], 'filterModel' => $searchModel, 'filterUrl' => $panel->getUrl(), 'columns' => [ From e6ddf655b3c297ebe16d8865a830056d2a1328fb Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 13:26:18 +0100 Subject: [PATCH 11/27] reverted 1e4c1eca1077ab23e7d00524b54f09f9158b3617 to get a working debug toolbar --- extensions/yii/debug/assets/main.css | 4 ---- extensions/yii/debug/assets/toolbar.css | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/extensions/yii/debug/assets/main.css b/extensions/yii/debug/assets/main.css index cc38766..dd100e0 100644 --- a/extensions/yii/debug/assets/main.css +++ b/extensions/yii/debug/assets/main.css @@ -1,7 +1,3 @@ -body { - padding-top: 62px; -} - span.indent { color: #ccc; } diff --git a/extensions/yii/debug/assets/toolbar.css b/extensions/yii/debug/assets/toolbar.css index 3c136b5..a853ec5 100644 --- a/extensions/yii/debug/assets/toolbar.css +++ b/extensions/yii/debug/assets/toolbar.css @@ -1,8 +1,4 @@ #yii-debug-toolbar { - position: fixed; - left: 0; - right: 0; - z-index: 1000000; padding: 0; font: 11px Verdana, Arial, sans-serif; text-align: left; @@ -20,15 +16,17 @@ } .yii-debug-toolbar-top { - top: 0; margin: 0 0 20px 0; - height: 42px; border-bottom: 1px solid #e4e4e4; } .yii-debug-toolbar-bottom { + position: fixed; + left: 0; + right: 0; bottom: 0; margin: 0; + z-index: 1000000; border-top: 1px solid #ccc; } From 9a592d38cf06356871f97a27abf9994f010b088b Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 13:29:17 +0100 Subject: [PATCH 12/27] fixed paths in travis.yml --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5aa71e9..17cbe4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,8 @@ install: - tests/unit/data/travis/cubrid-setup.sh # basic application: - composer install --dev --prefer-dist -d apps/basic - - cd apps/basic && php vendor/bin/codecept build && cd ../.. + - cd apps/basic && php vendor/bin/codecept build - cd apps/basic/web && php -S localhost:8080 & - - cd ../../.. before_script: - echo 'elasticsearch version ' && curl http://localhost:9200/ @@ -36,7 +35,7 @@ before_script: script: # - vendor/bin/phpunit --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor - vendor/bin/phpunit --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor - - cd apps/basic && php vendor/bin/codecept run && cd ../.. + - cd apps/basic && php vendor/bin/codecept run #after_script: # - php vendor/bin/coveralls From 9003716f25505ec760427fed1a976bdba3f5e75d Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 14:01:07 +0100 Subject: [PATCH 13/27] added debug toolbar background to have line separators --- extensions/yii/debug/assets/bg.png | Bin 0 -> 163 bytes extensions/yii/debug/assets/toolbar.css | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 extensions/yii/debug/assets/bg.png diff --git a/extensions/yii/debug/assets/bg.png b/extensions/yii/debug/assets/bg.png new file mode 100644 index 0000000000000000000000000000000000000000..459dd788897ac6e4743123bb22018d5f672020bf GIT binary patch literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^j6kfx!3HGlw@oMq2^0spJ29*~C-V}>VN3FMcVYMs zf(!O8p9~b?EbxddW? Date: Sun, 5 Jan 2014 14:07:09 +0100 Subject: [PATCH 14/27] debugging travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 17cbe4d..92fc379 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,14 +21,17 @@ install: - tests/unit/data/travis/memcache-setup.sh - tests/unit/data/travis/cubrid-setup.sh # basic application: + - pwd - composer install --dev --prefer-dist -d apps/basic - cd apps/basic && php vendor/bin/codecept build - cd apps/basic/web && php -S localhost:8080 & + - pwd before_script: - echo 'elasticsearch version ' && curl http://localhost:9200/ - mysql -e 'CREATE DATABASE yiitest;'; - psql -U postgres -c 'CREATE DATABASE yiitest;'; + - pwd - tests/unit/data/travis/sphinx-setup.sh - mongo yii2test --eval 'db.addUser("travis", "test");' From d172e38b201dd96e83e49b9d1bd15536a0908122 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 14:18:00 +0100 Subject: [PATCH 15/27] debugging travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 92fc379..c254f80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,8 @@ install: # basic application: - pwd - composer install --dev --prefer-dist -d apps/basic - - cd apps/basic && php vendor/bin/codecept build + - cd apps/basic && php vendor/bin/codecept build && cd ../.. + - pwd - cd apps/basic/web && php -S localhost:8080 & - pwd From d84aac09de6396a7085ddbf30e341370a54c5bc5 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 14:28:07 +0100 Subject: [PATCH 16/27] fixed basic app travis fixes #1744 --- .travis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c254f80..8134e21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,18 +21,14 @@ install: - tests/unit/data/travis/memcache-setup.sh - tests/unit/data/travis/cubrid-setup.sh # basic application: - - pwd - composer install --dev --prefer-dist -d apps/basic - cd apps/basic && php vendor/bin/codecept build && cd ../.. - - pwd - - cd apps/basic/web && php -S localhost:8080 & - - pwd + - cd apps && php -S localhost:8080 & before_script: - echo 'elasticsearch version ' && curl http://localhost:9200/ - mysql -e 'CREATE DATABASE yiitest;'; - psql -U postgres -c 'CREATE DATABASE yiitest;'; - - pwd - tests/unit/data/travis/sphinx-setup.sh - mongo yii2test --eval 'db.addUser("travis", "test");' From 3d59b19a21d5cd2c6c33e3ec344210a5960976a7 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 14:45:09 +0100 Subject: [PATCH 17/27] added classes to grid, list and detail view to allow specific styling also fixed an issue with gridview sort indicator css. fixes #1000 --- apps/advanced/backend/web/css/site.css | 4 ++++ apps/advanced/frontend/web/css/site.css | 4 ++++ apps/basic/web/css/site.css | 4 ++++ framework/yii/grid/GridView.php | 5 +++++ framework/yii/widgets/DetailView.php | 2 +- framework/yii/widgets/ListView.php | 5 +++++ 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/advanced/backend/web/css/site.css b/apps/advanced/backend/web/css/site.css index f460b45..66be560 100644 --- a/apps/advanced/backend/web/css/site.css +++ b/apps/advanced/backend/web/css/site.css @@ -60,6 +60,10 @@ a.desc:after { content: "\e156"; } +.grid-view th { + white-space: nowrap; +} + .hint-block { display: block; margin-top: 5px; diff --git a/apps/advanced/frontend/web/css/site.css b/apps/advanced/frontend/web/css/site.css index f460b45..66be560 100644 --- a/apps/advanced/frontend/web/css/site.css +++ b/apps/advanced/frontend/web/css/site.css @@ -60,6 +60,10 @@ a.desc:after { content: "\e156"; } +.grid-view th { + white-space: nowrap; +} + .hint-block { display: block; margin-top: 5px; diff --git a/apps/basic/web/css/site.css b/apps/basic/web/css/site.css index f460b45..66be560 100644 --- a/apps/basic/web/css/site.css +++ b/apps/basic/web/css/site.css @@ -60,6 +60,10 @@ a.desc:after { content: "\e156"; } +.grid-view th { + white-space: nowrap; +} + .hint-block { display: block; margin-top: 5px; diff --git a/framework/yii/grid/GridView.php b/framework/yii/grid/GridView.php index 35d89b2..e270974 100644 --- a/framework/yii/grid/GridView.php +++ b/framework/yii/grid/GridView.php @@ -49,6 +49,11 @@ class GridView extends BaseListView */ public $tableOptions = ['class' => 'table table-striped table-bordered']; /** + * @var array the HTML attributes for the container tag of the grid view. + * The "tag" element specifies the tag name of the container element and defaults to "div". + */ + public $options = ['class' => 'grid-view']; + /** * @var array the HTML attributes for the table header row */ public $headerRowOptions = []; diff --git a/framework/yii/widgets/DetailView.php b/framework/yii/widgets/DetailView.php index 8ced307..3a45a4e 100644 --- a/framework/yii/widgets/DetailView.php +++ b/framework/yii/widgets/DetailView.php @@ -90,7 +90,7 @@ class DetailView extends Widget * @var array the HTML attributes for the container tag of this widget. The "tag" option specifies * what container tag should be used. It defaults to "table" if not set. */ - public $options = ['class' => 'table table-striped table-bordered']; + public $options = ['class' => 'table table-striped table-bordered detail-view']; /** * @var array|Formatter the formatter used to format model attribute values into displayable texts. * This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]] diff --git a/framework/yii/widgets/ListView.php b/framework/yii/widgets/ListView.php index c112554..43eaab4 100644 --- a/framework/yii/widgets/ListView.php +++ b/framework/yii/widgets/ListView.php @@ -52,6 +52,11 @@ class ListView extends BaseListView * @var string the HTML code to be displayed between any two consecutive items. */ public $separator = "\n"; + /** + * @var array the HTML attributes for the container tag of the list view. + * The "tag" element specifies the tag name of the container element and defaults to "div". + */ + public $options = ['class' => 'list-view']; /** From 135a191cc668c3297a269d7c4fead0e8c41ddade Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 5 Jan 2014 16:23:24 +0200 Subject: [PATCH 18/27] Default name and title added to GitHub auth client. --- extensions/yii/authclient/clients/GitHub.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/extensions/yii/authclient/clients/GitHub.php b/extensions/yii/authclient/clients/GitHub.php index 57f430d..ed7b6a5 100644 --- a/extensions/yii/authclient/clients/GitHub.php +++ b/extensions/yii/authclient/clients/GitHub.php @@ -73,4 +73,20 @@ class GitHub extends OAuth2 { return $this->api('user', 'GET'); } + + /** + * @inheritdoc + */ + protected function defaultName() + { + return 'github'; + } + + /** + * @inheritdoc + */ + protected function defaultTitle() + { + return 'GitHub'; + } } \ No newline at end of file From 3eaf0021c01861f5f3b8e2e77e418c254ea78754 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 15:23:26 +0100 Subject: [PATCH 19/27] fixes #1606 --- docs/guide/installation.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/guide/installation.md b/docs/guide/installation.md index eab0046..099ebb8 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -81,6 +81,8 @@ If you are using Linux you can create a hard link to make it accessable, using t ln requirements.php ../requirements.php ``` +For the advanded app the `requirements.php` is two levels up so you have to use `ln requirements.php ../../requirements.php`. + Yii 2 requires PHP 5.4.0 or higher. Yii has been tested with the [Apache HTTP server](http://httpd.apache.org/) and [Nginx HTTP server](http://nginx.org/) on Windows and Linux. Yii may also be usable on other web servers and platforms, provided that PHP 5.4 or higher is supported. From e990be9394d3c34e2a21999e543e17f132ce40e9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 5 Jan 2014 16:53:55 +0100 Subject: [PATCH 20/27] #1788 info about retaining the default scenario --- docs/guide/model.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/guide/model.md b/docs/guide/model.md index a02e1ad..643ce5f 100644 --- a/docs/guide/model.md +++ b/docs/guide/model.md @@ -112,6 +112,21 @@ class User extends \yii\db\ActiveRecord } ``` +If you want to keep the default scenario available besides your own scenarios, use inheritance to include it: +```php +class User extends \yii\db\ActiveRecord +{ + public function scenarios() + { + $scenarios = parent::scenarios(); + $scenarios['login'] = ['username', 'password']; + $scenarios['register'] = ['username', 'email', 'password']; + return $scenarios; + } +} +``` + + Sometimes, we want to mark an attribute as not safe for massive assignment (but we still want the attribute to be validated). We may do so by prefixing an exclamation character to the attribute name when declaring it in `scenarios()`. For example: From e050aeacf16ffe71b80b3c3e56fa27097defec70 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 5 Jan 2014 14:08:38 -0500 Subject: [PATCH 21/27] Added back border to debugger toolbar. --- extensions/yii/debug/assets/toolbar.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/yii/debug/assets/toolbar.css b/extensions/yii/debug/assets/toolbar.css index 90b0f3a..5946675 100644 --- a/extensions/yii/debug/assets/toolbar.css +++ b/extensions/yii/debug/assets/toolbar.css @@ -17,7 +17,7 @@ .yii-debug-toolbar-top { margin: 0 0 20px 0; - /*border-bottom: 1px solid #e4e4e4;*/ + border-bottom: 1px solid #e4e4e4; } .yii-debug-toolbar-bottom { From 3814c5c3ef8a8d2684f4c30d1472af65ac09a195 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 23:27:39 +0400 Subject: [PATCH 22/27] improved fixture controller --- .../yii/console/controllers/FixtureController.php | 124 +++++++++++++++++++-- 1 file changed, 116 insertions(+), 8 deletions(-) diff --git a/framework/yii/console/controllers/FixtureController.php b/framework/yii/console/controllers/FixtureController.php index d5aa8e9..08f9fae 100644 --- a/framework/yii/console/controllers/FixtureController.php +++ b/framework/yii/console/controllers/FixtureController.php @@ -10,6 +10,7 @@ namespace yii\console\controllers; use Yii; use yii\console\Controller; use yii\console\Exception; +use yii\helpers\FileHelper; use yii\test\DbTestTrait; use yii\helpers\Console; @@ -53,6 +54,11 @@ use yii\helpers\Console; class FixtureController extends Controller { use DbTestTrait; + + /** + * type of fixture apply to database + */ + const APPLY_ALL = 'all'; /** * @var string controller default action ID. @@ -110,14 +116,43 @@ class FixtureController extends Controller throw new Exception('Fixture manager is not configured properly. Please refer to official documentation for this purposes.'); } - if (!$this->confirmApply($fixtures)) { + $foundFixtures = $this->findFixtures($fixtures); + + if (!$this->needToApplyAll($fixtures[0])) { + $notFoundFixtures = array_diff($fixtures, $foundFixtures); + + if ($notFoundFixtures) { + $this->notifyNotFound($notFoundFixtures); + } + } + + if (!$foundFixtures) { + throw new Exception("No files were found by name: \"" . implode(', ', $fixtures) . "\".\n" + . "Check that fixtures with these name exists, under fixtures path: \n\"" . Yii::getAlias($this->fixturePath) . "\"." + ); + } + + if (!$this->confirmApply($foundFixtures)) { return; } $this->getFixtureManager()->basePath = $this->fixturePath; $this->getFixtureManager()->db = $this->db; - $this->loadFixtures($fixtures); - $this->notifySuccess($fixtures); + + $transaction = Yii::$app->db->beginTransaction(); + + try + { + $this->loadFixtures($foundFixtures); + $transaction->commit(); + + } catch (\Exception $e) + { + $transaction->rollback(); + $this->stdout("Exception occured, transaction rollback. Tables will be in same state.\n", Console::BG_RED); + throw $e; + } + $this->notifySuccess($foundFixtures); } /** @@ -127,14 +162,35 @@ class FixtureController extends Controller * @param array|string $tables */ public function actionClear(array $tables) - { + { + if ($this->needToApplyAll($tables[0])) { + $tables = $this->getDbConnection()->schema->getTableNames(); + } + if (!$this->confirmClear($tables)) { return; } - foreach($tables as $table) { - $this->getDbConnection()->createCommand()->truncateTable($table)->execute(); - $this->stdout("Table \"{$table}\" was successfully cleared. \n", Console::FG_GREEN); + $transaction = Yii::$app->db->beginTransaction(); + + try + { + $this->getDbConnection()->createCommand()->checkIntegrity(false)->execute(); + + foreach($tables as $table) { + $this->getDbConnection()->createCommand()->truncateTable($table)->execute(); + $this->getDbConnection()->createCommand()->resetSequence($table)->execute(); + $this->stdout(" Table \"{$table}\" was successfully cleared. \n", Console::FG_GREEN); + } + + $this->getDbConnection()->createCommand()->checkIntegrity(true)->execute(); + $transaction->commit(); + + } catch (\Exception $e) + { + $transaction->rollback(); + $this->stdout("Exception occured, transaction rollback. Tables will be in same state.\n", Console::BG_RED); + throw $e; } } @@ -180,6 +236,18 @@ class FixtureController extends Controller } /** + * Notifies user that fixtures were not found under fixtures path. + * @param array $fixtures + */ + private function notifyNotFound($fixtures) + { + $this->stdout("Some fixtures were not found under path:\n", Console::BG_RED); + $this->stdout(Yii::getAlias($this->fixturePath) . "\n\n", Console::FG_GREEN); + $this->outputList($fixtures); + $this->stdout("\n"); + } + + /** * Prompts user with confirmation if fixtures should be loaded. * @param array $fixtures * @return boolean @@ -211,7 +279,47 @@ class FixtureController extends Controller private function outputList($data) { foreach($data as $index => $item) { - $this->stdout(($index + 1) . ". {$item}\n", Console::FG_GREEN); + $this->stdout(" " . ($index + 1) . ". {$item}\n", Console::FG_GREEN); } } + + /** + * Checks if needed to apply all fixtures. + * @param string $fixture + * @return bool + */ + public function needToApplyAll($fixture) + { + return $fixture == self::APPLY_ALL; + } + + /** + * Returns array of found fixtures. These may differer from input parameter as not all fixtures may exists. + * @param array $fixtures + */ + private function findFixtures(array $fixtures) + { + $fixturesPath = Yii::getAlias($this->fixturePath); + + $files = []; + + if ($this->needToApplyAll($fixtures[0])) { + $files = FileHelper::findFiles($fixturesPath, ['only' => ['.php']]); + } else { + $filesToSearch = []; + foreach ($fixtures as $fileName) { + $filesToSearch[] = $fileName . '.php'; + } + $files = FileHelper::findFiles($fixturesPath, ['only' => $filesToSearch]); + } + + $foundFixtures = []; + + foreach($files as $fixture) { + $foundFixtures[] = basename($fixture , '.php'); + } + + return $foundFixtures; + } + } From 2eb91acefdd986b2be159995a6b06fe1f4b088ad Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 23:33:11 +0400 Subject: [PATCH 23/27] CS fix --- framework/yii/console/controllers/FixtureController.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/framework/yii/console/controllers/FixtureController.php b/framework/yii/console/controllers/FixtureController.php index 08f9fae..0b400e8 100644 --- a/framework/yii/console/controllers/FixtureController.php +++ b/framework/yii/console/controllers/FixtureController.php @@ -141,13 +141,11 @@ class FixtureController extends Controller $transaction = Yii::$app->db->beginTransaction(); - try - { + try { $this->loadFixtures($foundFixtures); $transaction->commit(); - } catch (\Exception $e) - { + } catch (\Exception $e) { $transaction->rollback(); $this->stdout("Exception occured, transaction rollback. Tables will be in same state.\n", Console::BG_RED); throw $e; @@ -173,8 +171,7 @@ class FixtureController extends Controller $transaction = Yii::$app->db->beginTransaction(); - try - { + try { $this->getDbConnection()->createCommand()->checkIntegrity(false)->execute(); foreach($tables as $table) { @@ -186,8 +183,7 @@ class FixtureController extends Controller $this->getDbConnection()->createCommand()->checkIntegrity(true)->execute(); $transaction->commit(); - } catch (\Exception $e) - { + } catch (\Exception $e) { $transaction->rollback(); $this->stdout("Exception occured, transaction rollback. Tables will be in same state.\n", Console::BG_RED); throw $e; From f9cc750e1af4bdeb18069fc1b46dffb130805605 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 23:43:40 +0400 Subject: [PATCH 24/27] guides fixed/improved --- docs/guide/console-fixture.md | 9 +++++++++ extensions/yii/faker/README.md | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/guide/console-fixture.md b/docs/guide/console-fixture.md index 01b136f..17b7c85 100644 --- a/docs/guide/console-fixture.md +++ b/docs/guide/console-fixture.md @@ -62,6 +62,12 @@ yii fixture users // apply several fixtures to several tables. Note that there should not be any whitespace between ",", it should be one string. yii fixture users,users_profiles +// apply all fixtures +yii fixture/apply all + +// same as above +yii fixture all + // apply fixtures to the table users, but fixtures will be taken from different path. yii fixture users --fixturePath='@app/my/custom/path/to/fixtures' @@ -80,6 +86,9 @@ yii fixture/clear users // clear several tables. Note that there should not be any whitespace between ",", it should be one string. yii fixture/clear users,users_profile + +// clear all tables of current connection in current schema +yii fixture/clear all ``` Configure Command Globally diff --git a/extensions/yii/faker/README.md b/extensions/yii/faker/README.md index 70f5456..38d640f 100644 --- a/extensions/yii/faker/README.md +++ b/extensions/yii/faker/README.md @@ -104,7 +104,7 @@ will be created under the fixtures path (by default ```@tests/unit/fixtures```) You can generate fixtures for all templates by specifying keyword ```all```. ```php -php yii fixture/generate all_fixtures +php yii fixture/generate all ``` This command will generate fixtures for all template files that are stored under template path and From 1654381a3ae38974daa497bcbdd245c1e70a7563 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 5 Jan 2014 14:52:38 -0500 Subject: [PATCH 25/27] support table aliases for ActiveQuery::joinWith(). --- framework/yii/db/ActiveQuery.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/framework/yii/db/ActiveQuery.php b/framework/yii/db/ActiveQuery.php index a9a1b19..dc00661 100644 --- a/framework/yii/db/ActiveQuery.php +++ b/framework/yii/db/ActiveQuery.php @@ -326,19 +326,27 @@ class ActiveQuery extends Query implements ActiveQueryInterface } /** - * Returns the table name used by the specified active query. + * Returns the table alias (or table name) that can be used to prefix column names. * @param ActiveQuery $query - * @return string the table name + * @return string the table alias (or table name) enclosed within double curly brackets. */ - private function getQueryTableName($query) + private function getQueryTableAlias($query) { if (empty($query->from)) { /** @var ActiveRecord $modelClass */ $modelClass = $query->modelClass; - return $modelClass::tableName(); + $tableName = $modelClass::tableName(); } else { - return reset($query->from); + $tableName = reset($query->from); } + + if (preg_match('/^(.*?)\s+({{\w+}}|\w+)$/', $tableName, $matches)) { + $tableName = $matches[2]; + } + if (strpos($tableName, '{{') === false) { + $tableName = '{{' . $tableName . '}}'; + } + return $tableName; } /** @@ -364,15 +372,8 @@ class ActiveQuery extends Query implements ActiveQueryInterface return; } - $parentTable = $this->getQueryTableName($parent); - $childTable = $this->getQueryTableName($child); - if (strpos($parentTable, '{{') === false) { - $parentTable = '{{' . $parentTable . '}}'; - } - if (strpos($childTable, '{{') === false) { - $childTable = '{{' . $childTable . '}}'; - } - + $parentTable = $this->getQueryTableAlias($parent); + $childTable = $this->getQueryTableAlias($child); if (!empty($child->link)) { $on = []; From 60db9518f06c03da1f407bb75d4084d3033fd151 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 22:13:24 +0100 Subject: [PATCH 26/27] console HelpController use correct script name --- .../yii/console/controllers/HelpController.php | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/framework/yii/console/controllers/HelpController.php b/framework/yii/console/controllers/HelpController.php index eee1923..49ee2c8 100644 --- a/framework/yii/console/controllers/HelpController.php +++ b/framework/yii/console/controllers/HelpController.php @@ -42,11 +42,6 @@ class HelpController extends Controller * Displays available commands or the detailed information * about a particular command. For example, * - * ~~~ - * yii help # list available commands - * yii help message # display help info about "message" - * ~~~ - * * @param string $command The name of the command to show help about. * If not provided, all available commands will be displayed. * @return integer the exit status @@ -149,8 +144,9 @@ class HelpController extends Controller foreach ($commands as $command) { echo "- " . $this->ansiFormat($command, Console::FG_YELLOW) . "\n"; } + $scriptName = $this->getScriptName(); $this->stdout("\nTo see the help of each command, enter:\n", Console::BOLD); - echo "\n yii " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' + echo "\n $scriptName " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' . $this->ansiFormat('', Console::FG_CYAN) . "\n\n"; } else { $this->stdout("\nNo commands are found.\n\n", Console::BOLD); @@ -189,8 +185,9 @@ class HelpController extends Controller } echo "\n"; } + $scriptName = $this->getScriptName(); echo "\nTo see the detailed information about individual sub-commands, enter:\n"; - echo "\n yii " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' + echo "\n $scriptName " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' . $this->ansiFormat('', Console::FG_CYAN) . "\n\n"; } } @@ -261,10 +258,11 @@ class HelpController extends Controller } $this->stdout("\nUSAGE\n\n", Console::BOLD); + $scriptName = $this->getScriptName(); if ($action->id === $controller->defaultAction) { - echo 'yii ' . $this->ansiFormat($controller->getUniqueId(), Console::FG_YELLOW); + echo $scriptName . ' ' . $this->ansiFormat($controller->getUniqueId(), Console::FG_YELLOW); } else { - echo 'yii ' . $this->ansiFormat($action->getUniqueId(), Console::FG_YELLOW); + echo $scriptName . ' ' . $this->ansiFormat($action->getUniqueId(), Console::FG_YELLOW); } list ($required, $optional) = $this->getArgHelps($method, isset($tags['param']) ? $tags['param'] : []); foreach ($required as $arg => $description) { @@ -425,4 +423,12 @@ class HelpController extends Controller $name = $required ? "$name (required)" : $name; return $doc === '' ? $name : "$name: $doc"; } + + /** + * @return string the name of the cli script currently running. + */ + protected function getScriptName() + { + return basename(Yii::$app->request->scriptFile); + } } From 4d99677f079a816f0e1d1ed1d1db7f1126b44340 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 22:13:45 +0100 Subject: [PATCH 27/27] fixed div/0 issue in console progress bar --- framework/yii/helpers/BaseConsole.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/yii/helpers/BaseConsole.php b/framework/yii/helpers/BaseConsole.php index c78ed67..307fb00 100644 --- a/framework/yii/helpers/BaseConsole.php +++ b/framework/yii/helpers/BaseConsole.php @@ -861,7 +861,7 @@ class BaseConsole } $width -= mb_strlen($prefix); - $percent = $done / $total; + $percent = ($total == 0) ? 1 : $done / $total; $info = sprintf("%d%% (%d/%d)", $percent * 100, $done, $total); if ($done > $total || $done == 0) {