From 9ae80e3a9477c377e0239163afa0200e6d1e1ab5 Mon Sep 17 00:00:00 2001 From: pana1990 Date: Thu, 9 Jul 2015 18:29:17 +0200 Subject: [PATCH 01/10] Update sintax --- .../migrations/m140506_102106_rbac_init.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/framework/rbac/migrations/m140506_102106_rbac_init.php b/framework/rbac/migrations/m140506_102106_rbac_init.php index b5cda499ff..12e7de3a0b 100644 --- a/framework/rbac/migrations/m140506_102106_rbac_init.php +++ b/framework/rbac/migrations/m140506_102106_rbac_init.php @@ -42,38 +42,38 @@ class m140506_102106_rbac_init extends \yii\db\Migration } $this->createTable($authManager->ruleTable, [ - 'name' => Schema::TYPE_STRING . '(64) NOT NULL', - 'data' => Schema::TYPE_TEXT, - 'created_at' => Schema::TYPE_INTEGER, - 'updated_at' => Schema::TYPE_INTEGER, + 'name' => Schema::string(64)->notNull(), + 'data' => Schema::text(), + 'created_at' => Schema::integer(), + 'updated_at' => Schema::integer(), 'PRIMARY KEY (name)', ], $tableOptions); $this->createTable($authManager->itemTable, [ - 'name' => Schema::TYPE_STRING . '(64) NOT NULL', - 'type' => Schema::TYPE_INTEGER . ' NOT NULL', - 'description' => Schema::TYPE_TEXT, - 'rule_name' => Schema::TYPE_STRING . '(64)', - 'data' => Schema::TYPE_TEXT, - 'created_at' => Schema::TYPE_INTEGER, - 'updated_at' => Schema::TYPE_INTEGER, + 'name' => Schema::string(64)->notNull(), + 'type' => Schema::integer()->notNull(), + 'description' => Schema::text(), + 'rule_name' => Schema::string(64), + 'data' => Schema::text(), + 'created_at' => Schema::integer(), + 'updated_at' => Schema::integer(), 'PRIMARY KEY (name)', 'FOREIGN KEY (rule_name) REFERENCES ' . $authManager->ruleTable . ' (name) ON DELETE SET NULL ON UPDATE CASCADE', ], $tableOptions); $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type'); $this->createTable($authManager->itemChildTable, [ - 'parent' => Schema::TYPE_STRING . '(64) NOT NULL', - 'child' => Schema::TYPE_STRING . '(64) NOT NULL', + 'parent' => Schema::string(64)->notNull(), + 'child' => Schema::string(64)->notNull(), 'PRIMARY KEY (parent, child)', 'FOREIGN KEY (parent) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', 'FOREIGN KEY (child) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', ], $tableOptions); $this->createTable($authManager->assignmentTable, [ - 'item_name' => Schema::TYPE_STRING . '(64) NOT NULL', - 'user_id' => Schema::TYPE_STRING . '(64) NOT NULL', - 'created_at' => Schema::TYPE_INTEGER, + 'item_name' => Schema::string(64)->notNull(), + 'user_id' => Schema::string(64)->notNull(), + 'created_at' => Schema::integer(), 'PRIMARY KEY (item_name, user_id)', 'FOREIGN KEY (item_name) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', ], $tableOptions); From 025845e660f5e913a477da2d1279a94265d4caf9 Mon Sep 17 00:00:00 2001 From: Sebastian Chojniak Date: Thu, 9 Jul 2015 19:22:36 +0200 Subject: [PATCH 02/10] performance: unnecessary (when result is cached) getAuthManager() removed --- framework/web/User.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/web/User.php b/framework/web/User.php index 28ec491bb3..1f565bcecb 100644 --- a/framework/web/User.php +++ b/framework/web/User.php @@ -655,11 +655,10 @@ class User extends Component */ public function can($permissionName, $params = [], $allowCaching = true) { - $auth = $this->getAuthManager(); if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) { return $this->_access[$permissionName]; } - $access = $auth->checkAccess($this->getId(), $permissionName, $params); + $access = $this->getAuthManager()->checkAccess($this->getId(), $permissionName, $params); if ($allowCaching && empty($params)) { $this->_access[$permissionName] = $access; } From 6ee285f3215431f6c02350b33146ba6259993ff0 Mon Sep 17 00:00:00 2001 From: Sebastian Chojniak Date: Thu, 9 Jul 2015 22:20:11 +0200 Subject: [PATCH 03/10] unused imports removed --- framework/db/BaseActiveRecord.php | 1 - framework/log/Target.php | 1 - framework/validators/DateValidator.php | 1 - 3 files changed, 3 deletions(-) diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 545a51a7a0..00645f8f6e 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -8,7 +8,6 @@ namespace yii\db; use yii\base\InvalidConfigException; -use yii\base\Event; use yii\base\Model; use yii\base\InvalidParamException; use yii\base\ModelEvent; diff --git a/framework/log/Target.php b/framework/log/Target.php index 076edb9084..1d0ae583dd 100644 --- a/framework/log/Target.php +++ b/framework/log/Target.php @@ -9,7 +9,6 @@ namespace yii\log; use Yii; use yii\base\Component; -use yii\base\ErrorHandler; use yii\base\InvalidConfigException; use yii\helpers\VarDumper; use yii\web\Request; diff --git a/framework/validators/DateValidator.php b/framework/validators/DateValidator.php index 85874f7aaf..930c8313c1 100644 --- a/framework/validators/DateValidator.php +++ b/framework/validators/DateValidator.php @@ -10,7 +10,6 @@ namespace yii\validators; use DateTime; use IntlDateFormatter; use Yii; -use yii\base\Exception; use yii\base\InvalidConfigException; use yii\helpers\FormatConverter; From 86c2e22a5bab2c992862147225596b8a4a7f701e Mon Sep 17 00:00:00 2001 From: Sebastian Chojniak Date: Thu, 9 Jul 2015 22:50:32 +0200 Subject: [PATCH 04/10] class Event is used in docs --- framework/db/BaseActiveRecord.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 00645f8f6e..545a51a7a0 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -8,6 +8,7 @@ namespace yii\db; use yii\base\InvalidConfigException; +use yii\base\Event; use yii\base\Model; use yii\base\InvalidParamException; use yii\base\ModelEvent; From 3c9e6be413df2b1e74748ac902137d35861d74a0 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 10 Jul 2015 00:21:20 +0300 Subject: [PATCH 05/10] Added schema builder usage to migations guide --- docs/guide/db-migrations.md | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/guide/db-migrations.md b/docs/guide/db-migrations.md index 8b625cf33a..6f2e31dac7 100644 --- a/docs/guide/db-migrations.md +++ b/docs/guide/db-migrations.md @@ -139,6 +139,33 @@ to `Schema::TYPE_STRING` to specify that the column cannot be null. > Info: The mapping between abstract types and physical types is specified by the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. + +Since 2.0.5 schema builder which provides more convenient way defining column schema was introduced so migration above +could be written like the following: + +```php + +use yii\db\Schema; +use yii\db\Migration; + +class m150101_185401_create_news_table extends \yii\db\Migration +{ + public function up() + { + $this->createTable('news', [ + 'id' => Schema::primaryKey(), + 'title' => Schema::string()->notNull(), + 'content' => Schema::text(), + ]); + } + + public function down() + { + $this->dropTable('news'); + } + +} +``` ### Transactional Migrations @@ -163,9 +190,9 @@ class m150101_185401_create_news_table extends Migration public function safeUp() { $this->createTable('news', [ - 'id' => 'pk', - 'title' => Schema::TYPE_STRING . ' NOT NULL', - 'content' => Schema::TYPE_TEXT, + 'id' => Schema::primaryKey(),, + 'title' => Schema::string()->notNull(), + 'content' => Schema::text(), ]); $this->insert('news', [ From 7926b7d4e9be1dd046907d52d836b82c7e95a242 Mon Sep 17 00:00:00 2001 From: lynicidn Date: Fri, 10 Jul 2015 07:32:34 +0300 Subject: [PATCH 06/10] Update EachValidator.php --- framework/validators/EachValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/validators/EachValidator.php b/framework/validators/EachValidator.php index 90875eb638..bb891b5cd5 100644 --- a/framework/validators/EachValidator.php +++ b/framework/validators/EachValidator.php @@ -17,7 +17,7 @@ use yii\base\Model; * ~~~php * class MyModel extends Model * { - * public $arrayAttribute = []; + * public $categoryIDs = []; * * public function rules() * { From 853f5fadaf7ab381e78a11af79354508248baa85 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 10 Jul 2015 12:10:20 +0300 Subject: [PATCH 07/10] Fixes #8798: adjusted inconsistency in guide --- docs/guide/structure-controllers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/structure-controllers.md b/docs/guide/structure-controllers.md index bf2f924b08..8bb6697ece 100644 --- a/docs/guide/structure-controllers.md +++ b/docs/guide/structure-controllers.md @@ -141,10 +141,10 @@ takes the default value `app\controllers`: Controller classes must be [autoloadable](concept-autoloading.md). For this reason, in the above examples, the `article` controller class should be saved in the file whose [alias](concept-aliases.md) -is `@app/controllers/ArticleController.php`; while the `admin/post2-comment` controller should be -in `@app/controllers/admin/Post2CommentController.php`. +is `@app/controllers/ArticleController.php`; while the `admin/post-comment` controller should be +in `@app/controllers/admin/PostCommentController.php`. -> Info: The last example `admin/post2-comment` shows how you can put a controller under a sub-directory +> Info: The last example `admin/post-comment` shows how you can put a controller under a sub-directory of the [[yii\base\Application::controllerNamespace|controller namespace]]. This is useful when you want to organize your controllers into several categories and you do not want to use [modules](structure-modules.md). From 398caaf7fd75dd42bc2c485e09553663601d7eaf Mon Sep 17 00:00:00 2001 From: Ivan Pomortsev Date: Fri, 10 Jul 2015 12:15:55 +0300 Subject: [PATCH 08/10] Fixes #8549: Fixed `yii\caching\FileCache` doesn't lock cache files when reading --- framework/CHANGELOG.md | 2 +- framework/caching/FileCache.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 50ce96c3a8..51a99c7ceb 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -17,6 +17,7 @@ Yii Framework 2 Change Log - Bug #8592: Fixed `yii\db\Command::getRawSql()` unable to parse params specified without colon (':') (klimov-paul) - Bug #8593: Fixed `yii\db\ActiveQuery` produces incorrect SQL for aggregations, when `sql` field is set (klimov-paul) - Bug #8595: Fixed `yii\rbac\DbManager::checkAccessFromCache()` to check against auth items loaded in cache recursively (achretien, qiangxue) +- Bug #8549: Fixed `yii\caching\FileCache` doesn't lock cache files when reading (iworker) - Bug #8606: Fixed `yii\web\Response::xSendFile()` does not reset format (vyants) - Bug #8627: Fixed `yii\db\Migration` produces incorrect results due to table schema caching (klimov-paul) - Bug #8661: Fixed `yii.activeForm.js` scrolling to top (nkovacs) @@ -44,7 +45,6 @@ Yii Framework 2 Change Log - Chg #6354: `ErrorHandler::logException()` will now log the whole exception object instead of only its string representation (cebe) - Chg #8556: Extracted `yii\web\User::getAuthManager()` method (samdark) - 2.0.4 May 10, 2015 ------------------ diff --git a/framework/caching/FileCache.php b/framework/caching/FileCache.php index 8b97bb3352..a96242c1a9 100644 --- a/framework/caching/FileCache.php +++ b/framework/caching/FileCache.php @@ -107,11 +107,19 @@ class FileCache extends Cache protected function getValue($key) { $cacheFile = $this->getCacheFile($key); + if (@filemtime($cacheFile) > time()) { - return @file_get_contents($cacheFile); - } else { - return false; + $fp = @fopen($cacheFile, 'r'); + if ($fp !== false) { + @flock($fp, LOCK_SH); + $cacheValue = @file_get_contents($cacheFile); + @flock($fp, LOCK_UN); + @fclose($fp); + return $cacheValue; + } } + + return false; } /** From aaf931a5e8a76cc25ae404eae657801c47508fe6 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 10 Jul 2015 12:34:09 +0300 Subject: [PATCH 09/10] Fixes #9070: Fixed `ViewAction::resolveViewName()` not to accept `/../` and `/./` --- framework/CHANGELOG.md | 1 + framework/web/ViewAction.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 51a99c7ceb..19c9a6bd14 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -24,6 +24,7 @@ Yii Framework 2 Change Log - Bug #8772: ActiveQuery failed removing duplicate records after join when the resultset did not contain the pk values e.g. after grouping (cebe) - Bug #8900: Fixed determine active menu item with url-alias in route `\yii\widgets\Menu::isItemActive()` (demi) - Bug #9046: Fixed problem with endless error loop when an error occurred after sending a stream or file download response to the user (cebe) +- Bug #9070: Fixed `ViewAction::resolveViewName()` not to accept `/../` and `/./` (thejahweh, samdark) - Bug: Fixed string comparison in `BaseActiveRecord::unlink()` which may result in wrong comparison result for hash valued primary keys starting with `0e` (cebe) - Bug: Pass correct action name to `yii\console\Controller::options()` when default action was requested (cebe) - Bug: Automatic garbage collection in `yii\caching\FileCache` was not triggered (kidol) diff --git a/framework/web/ViewAction.php b/framework/web/ViewAction.php index 8c6a1a6894..3b0df40ae2 100644 --- a/framework/web/ViewAction.php +++ b/framework/web/ViewAction.php @@ -119,9 +119,9 @@ class ViewAction extends Action { $viewName = Yii::$app->request->get($this->viewParam, $this->defaultView); - if (!is_string($viewName) || !preg_match('/^\w[\w\/\-\.]*$/', $viewName)) { + if (!is_string($viewName) || !preg_match('~^\w(?:(?!\/\.{0,2}\/)[\w\/\-\.])*$~', $viewName)) { if (YII_DEBUG) { - throw new NotFoundHttpException("The requested view \"$viewName\" must start with a word character and can contain only word characters, forward slashes, dots and dashes."); + throw new NotFoundHttpException("The requested view \"$viewName\" must start with a word character, must not contain /../ or /./, can contain only word characters, forward slashes, dots and dashes."); } else { throw new NotFoundHttpException(Yii::t('yii', 'The requested view "{name}" was not found.', ['name' => $viewName])); } From d20bc2b0104af4fdfe2b9cf54293a66d1a59f882 Mon Sep 17 00:00:00 2001 From: Johannes la Poutre Date: Fri, 10 Jul 2015 11:42:46 +0200 Subject: [PATCH 10/10] Translated the word 'Update' In general the word 'Update' can be better translated into 'Bewerk' in Dutch. --- framework/messages/nl/yii.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/messages/nl/yii.php b/framework/messages/nl/yii.php index 666288dc90..ca86d37bb9 100644 --- a/framework/messages/nl/yii.php +++ b/framework/messages/nl/yii.php @@ -49,7 +49,7 @@ return [ 'Total {count, number} {count, plural, one{item} other{items}}.' => 'Totaal {count, number} {count, plural, one{item} other{items}}.', 'Unable to verify your data submission.' => 'Het is niet mogelijk uw verstrekte gegevens te verifiëren.', 'Unknown option: --{name}' => 'Onbekende optie: --{name}', - 'Update' => 'Update', + 'Update' => 'Bewerk', 'View' => 'Bekijk', 'Yes' => 'Ja', 'You are not allowed to perform this action.' => 'U bent niet gemachtigd om deze actie uit te voeren.',