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', [ 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). diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 508ac20831..bdb9793efa 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) @@ -24,6 +25,7 @@ Yii Framework 2 Change Log - 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 #9063: Workaround over MySQL create index bug and table name change to lowercase. (sebathi) +- 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) @@ -45,7 +47,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; } /** 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/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.', 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); 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; 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() * { 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; } 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])); }