Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

UPGRADE.md 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. Upgrading Instructions for Yii Framework v2
  2. ===========================================
  3. !!!IMPORTANT!!!
  4. The following upgrading instructions are cumulative. That is,
  5. if you want to upgrade from version A to version C and there is
  6. version B between A and C, you need to follow the instructions
  7. for both A and B.
  8. Make sure you have global install of latest version of composer asset plugin as well as a stable version of composer:
  9. ```
  10. php composer.phar self-update
  11. php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
  12. ```
  13. Upgrade from Yii 2.0.8
  14. ----------------------
  15. * Part of code from `yii\web\User::loginByCookie()` method was moved to new `getIdentityAndDurationFromCookie()`
  16. and `removeIdentityCookie()` methods. If you override `loginByCookie()` method, update it in order use new methods.
  17. * Fixture console command syntax was changed from `yii fixture "*" -User` to `yii fixture "*, -User"`. Upgrade your
  18. scripts if necessary.
  19. Upgrade from Yii 2.0.7
  20. ----------------------
  21. * The signature of `yii\helpers\BaseArrayHelper::index()` was changed. The method has got an extra optional parameter
  22. `$groups`.
  23. * `yii\helpers\BaseArrayHelper` methods `isIn()` and `isSubset()` throw `\yii\base\InvalidParamException`
  24. instead of `\InvalidArgumentException`. If you wrap calls of these methods in try/catch block, change expected
  25. exception class.
  26. * `yii\rbac\ManagerInterface::canAddChild()` method was added. If you have custom backend for RBAC you need to implement
  27. it.
  28. * The signature of `yii\web\User::loginRequired()` was changed. The method has got an extra optional parameter
  29. `$checkAcceptHeader`.
  30. * The signature of `yii\db\ColumnSchemaBuilder::__construct()` was changed. The method has got an extra optional
  31. parameter `$db`. In case you are instantiating this class yourself and using the `$config` parameter, you will need to
  32. move it to the right by one.
  33. * String types in the MSSQL column schema map were upgraded to Unicode storage types. This will have no effect on
  34. existing columns, but any new columns you generate via the migrations engine will now store data as Unicode.
  35. * Output buffering was introduced in the pair of `yii\widgets\ActiveForm::init()` and `::run()`. If you override any of
  36. these methods, make sure that output buffer handling is not corrupted. If you call the parent implementation, when
  37. overriding, everything should work fine. You should be doing that anyway.
  38. Upgrade from Yii 2.0.6
  39. ----------------------
  40. * Added new requirement: ICU Data version >= 49.1. Please, ensure that your environment has ICU data installed and
  41. up to date to prevent unexpected behavior or crashes. This may not be the case on older systems e.g. running Debian Wheezy.
  42. > Tip: Use Yii2 Requirements checker for easy and fast check. Look for `requirements.php` in root of Basic and Advanced
  43. templates (howto-comment is in head of the script).
  44. * The signature of `yii\helpers\BaseInflector::transliterate()` was changed. The method is now public and has an
  45. extra optional parameter `$transliterator`.
  46. * In `yii\web\UrlRule` the `pattern` matching group names are being replaced with the placeholders on class
  47. initialization to support wider range of allowed characters. Because of this change:
  48. - You are required to flush your application cache to remove outdated `UrlRule` serialized objects.
  49. See the [Cache Flushing Guide](http://www.yiiframework.com/doc-2.0/guide-caching-data.html#cache-flushing)
  50. - If you implement `parseRequest()` or `createUrl()` and rely on parameter names, call `substitutePlaceholderNames()`
  51. in order to replace temporary IDs with parameter names after doing matching.
  52. * The context of `yii.confirm` JavaScript function was changed from `yii` object to the DOM element which triggered
  53. the event.
  54. - If you overrode the `yii.confirm` function and accessed the `yii` object through `this`, you must access it
  55. with global variable `yii` instead.
  56. * Traversable objects are now formatted as arrays in XML response to support SPL objects and Generators. Previous
  57. behavior could be turned on by setting `XmlResponseFormatter::$useTraversableAsArray` to `false`.
  58. * If you've implemented `yii\rbac\ManagerInterface` you need to implement additional method `getUserIdsByRole($roleName)`.
  59. * If you're using ApcCache with APCu, set `useApcu` to `true` in the component config.
  60. * The `yii\behaviors\SluggableBehavior` class has been refactored to make it more reusable.
  61. Added new `protected` methods:
  62. - `isSlugNeeded()`
  63. - `makeUnique()`
  64. The visibility of the following Methods has changed from `private` to `protected`:
  65. - `validateSlug()`
  66. - `generateUniqueSlug()`
  67. * The `yii\console\controllers\MessageController` class has been refactored to be better configurable and now also allows
  68. setting a lot of configuration options via command line. If you extend from this class, make sure it works as expected after
  69. these changes.
  70. Upgrade from Yii 2.0.5
  71. ----------------------
  72. * The signature of the following methods in `yii\console\controllers\MessageController` has changed. They have an extra parameter `$markUnused`.
  73. - `saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)`
  74. - `saveMessagesToPHP($messages, $dirName, $overwrite, $removeUnused, $sort, $markUnused)`
  75. - `saveMessagesCategoryToPHP($messages, $fileName, $overwrite, $removeUnused, $sort, $category, $markUnused)`
  76. - `saveMessagesToPO($messages, $dirName, $overwrite, $removeUnused, $sort, $catalog, $markUnused)`
  77. Upgrade from Yii 2.0.4
  78. ----------------------
  79. Upgrading from 2.0.4 to 2.0.5 does not require any changes.
  80. Upgrade from Yii 2.0.3
  81. ----------------------
  82. * Updated dependency to `cebe/markdown` to version `1.1.x`.
  83. If you need stick with 1.0.x, you can specify that in your `composer.json` by
  84. adding the following line in the `require` section:
  85. ```json
  86. "cebe/markdown": "~1.0.0",
  87. ```
  88. Upgrade from Yii 2.0.2
  89. ----------------------
  90. Starting from version 2.0.3 Yii `Security` component relies on OpenSSL crypto lib instead of Mcrypt. The reason is that
  91. Mcrypt is abandoned and isn't maintained for years. Therefore your PHP should be compiled with OpenSSL support. Most
  92. probably there's nothing to worry because it is quite typical.
  93. If you've extended `yii\base\Security` to override any of the config constants you have to update your code:
  94. - `MCRYPT_CIPHER` — now encoded in `$cipher` (and hence `$allowedCiphers`).
  95. - `MCRYPT_MODE` — now encoded in `$cipher` (and hence `$allowedCiphers`).
  96. - `KEY_SIZE` — now encoded in `$cipher` (and hence `$allowedCiphers`).
  97. - `KDF_HASH` — now `$kdfHash`.
  98. - `MAC_HASH` — now `$macHash`.
  99. - `AUTH_KEY_INFO` — now `$authKeyInfo`.
  100. Upgrade from Yii 2.0.0
  101. ----------------------
  102. * Upgraded Twitter Bootstrap to [version 3.3.x](http://blog.getbootstrap.com/2014/10/29/bootstrap-3-3-0-released/).
  103. If you need to use an older version (i.e. stick with 3.2.x) you can specify that in your `composer.json` by
  104. adding the following line in the `require` section:
  105. ```json
  106. "bower-asset/bootstrap": "3.2.*",
  107. ```
  108. Upgrade from Yii 2.0 RC
  109. -----------------------
  110. * If you've implemented `yii\rbac\ManagerInterface` you need to add implementation for new method `removeChildren()`.
  111. * The input dates for datetime formatting are now assumed to be in UTC unless a timezone is explicitly given.
  112. Before, the timezone assumed for input dates was the default timezone set by PHP which is the same as `Yii::$app->timeZone`.
  113. This causes trouble because the formatter uses `Yii::$app->timeZone` as the default values for output so no timezone conversion
  114. was possible. If your timestamps are stored in the database without a timezone identifier you have to ensure they are in UTC or
  115. add a timezone identifier explicitly.
  116. * `yii\bootstrap\Collapse` is now encoding labels by default. `encode` item option and global `encodeLabels` property were
  117. introduced to disable it. Keys are no longer used as labels. You need to remove keys and use `label` item option instead.
  118. * The `yii\base\View::beforeRender()` and `yii\base\View::afterRender()` methods have two extra parameters `$viewFile`
  119. and `$params`. If you are overriding these methods, you should adjust the method signature accordingly.
  120. * If you've used `asImage` formatter i.e. `Yii::$app->formatter->asImage($value, $alt);` you should change it
  121. to `Yii::$app->formatter->asImage($value, ['alt' => $alt]);`.
  122. * Yii now requires `cebe/markdown` 1.0.0 or higher, which includes breaking changes in its internal API. If you extend the markdown class
  123. you need to update your implementation. See <https://github.com/cebe/markdown/releases/tag/1.0.0-rc> for details.
  124. If you just used the markdown helper class there is no need to change anything.
  125. * If you are using CUBRID DBMS, make sure to use at least version 9.3.0 as the server and also as the PDO extension.
  126. Quoting of values is broken in prior versions and Yii has no reliable way to work around this issue.
  127. A workaround that may have worked before has been removed in this release because it was not reliable.
  128. Upgrade from Yii 2.0 Beta
  129. -------------------------
  130. * If you are using Composer to upgrade Yii, you should run the following command first (once for all) to install
  131. the composer-asset-plugin, *before* you update your project:
  132. ```
  133. php composer.phar global require "fxp/composer-asset-plugin:~1.0.0"
  134. ```
  135. You also need to add the following code to your project's `composer.json` file:
  136. ```json
  137. "extra": {
  138. "asset-installer-paths": {
  139. "npm-asset-library": "vendor/npm",
  140. "bower-asset-library": "vendor/bower"
  141. }
  142. }
  143. ```
  144. It is also a good idea to upgrade composer itself to the latest version if you see any problems:
  145. ```
  146. php composer.phar self-update
  147. ```
  148. * If you used `clearAll()` or `clearAllAssignments()` of `yii\rbac\DbManager`, you should replace
  149. them with `removeAll()` and `removeAllAssignments()` respectively.
  150. * If you created RBAC rule classes, you should modify their `execute()` method by adding `$user`
  151. as the first parameter: `execute($user, $item, $params)`. The `$user` parameter represents
  152. the ID of the user currently being access checked. Previously, this is passed via `$params['user']`.
  153. * If you override `yii\grid\DataColumn::getDataCellValue()` with visibility `protected` you have
  154. to change visibility to `public` as visibility of the base method has changed.
  155. * If you have classes implementing `yii\web\IdentityInterface` (very common), you should modify
  156. the signature of `findIdentityByAccessToken()` as
  157. `public static function findIdentityByAccessToken($token, $type = null)`. The new `$type` parameter
  158. will contain the type information about the access token. For example, if you use
  159. `yii\filters\auth\HttpBearerAuth` authentication method, the value of this parameter will be
  160. `yii\filters\auth\HttpBearerAuth`. This allows you to differentiate access tokens taken by
  161. different authentication methods.
  162. * If you are sharing the same cache across different applications, you should configure
  163. the `keyPrefix` property of the cache component to use some unique string.
  164. Previously, this property was automatically assigned with a unique string.
  165. * If you are using `dropDownList()`, `listBox()`, `activeDropDownList()`, or `activeListBox()`
  166. of `yii\helpers\Html`, and your list options use multiple blank spaces to format and align
  167. option label texts, you need to specify the option `encodeSpaces` to be true.
  168. * If you are using `yii\grid\GridView` and have configured a data column to use a PHP callable
  169. to return cell values (via `yii\grid\DataColumn::value`), you may need to adjust the signature
  170. of the callable to be `function ($model, $key, $index, $widget)`. The `$key` parameter was newly added
  171. in this release.
  172. * `yii\console\controllers\AssetController` is now using hashes instead of timestamps. Replace all `{ts}` with `{hash}`.
  173. * The database table of the `yii\log\DbTarget` now needs a `prefix` column to store context information.
  174. You can add it with `ALTER TABLE log ADD COLUMN prefix TEXT AFTER log_time;`.
  175. * The `fileinfo` PHP extension is now required by Yii. If you use `yii\helpers\FileHelper::getMimeType()`, make sure
  176. you have enabled this extension. This extension is [builtin](http://www.php.net/manual/en/fileinfo.installation.php) in php above `5.3`.
  177. * Please update your main layout file by adding this line in the `<head>` section: `<?= Html::csrfMetaTags() ?>`.
  178. This change is needed because `yii\web\View` no longer automatically generates CSRF meta tags due to issue #3358.
  179. * If your model code is using the `file` validation rule, you should rename its `types` option to `extensions`.
  180. * `MailEvent` class has been moved to the `yii\mail` namespace. You have to adjust all references that may exist in your code.
  181. * The behavior and signature of `ActiveRecord::afterSave()` has changed. `ActiveRecord::$isNewRecord` will now always be
  182. false in afterSave and also dirty attributes are not available. This change has been made to have a more consistent and
  183. expected behavior. The changed attributes are now available in the new parameter of afterSave() `$changedAttributes`.
  184. `$changedAttributes` contains the old values of attributes that had changed and were saved.
  185. * `ActiveRecord::updateAttributes()` has been changed to not trigger events and not respect optimistic locking anymore to
  186. differentiate it more from calling `update(false)` and to ensure it can be used in `afterSave()` without triggering infinite
  187. loops.
  188. * If you are developing RESTful APIs and using an authentication method such as `yii\filters\auth\HttpBasicAuth`,
  189. you should explicitly configure `yii\web\User::enableSession` in the application configuration to be false to avoid
  190. starting a session when authentication is performed. Previously this was done automatically by authentication method.
  191. * `mail` component was renamed to `mailer`, `yii\log\EmailTarget::$mail` was renamed to `yii\log\EmailTarget::$mailer`.
  192. Please update all references in the code and config files.
  193. * `yii\caching\GroupDependency` was renamed to `TagDependency`. You should create such a dependency using the code
  194. `new \yii\caching\TagDependency(['tags' => 'TagName'])`, where `TagName` is similar to the group name that you
  195. previously used.
  196. * If you are using the constant `YII_PATH` in your code, you should rename it to `YII2_PATH` now.
  197. * You must explicitly configure `yii\web\Request::cookieValidationKey` with a secret key. Previously this is done automatically.
  198. To do so, modify your application configuration like the following:
  199. ```php
  200. return [
  201. // ...
  202. 'components' => [
  203. 'request' => [
  204. 'cookieValidationKey' => 'your secret key here',
  205. ],
  206. ],
  207. ];
  208. ```
  209. > Note: If you are using the `Advanced Project Template` you should not add this configuration to `common/config`
  210. or `console/config` because the console application doesn't have to deal with CSRF and uses its own request that
  211. doesn't have `cookieValidationKey` property.
  212. * `yii\rbac\PhpManager` now stores data in three separate files instead of one. In order to convert old file to
  213. new ones save the following code as `convert.php` that should be placed in the same directory your `rbac.php` is in:
  214. ```php
  215. <?php
  216. $oldFile = 'rbac.php';
  217. $itemsFile = 'items.php';
  218. $assignmentsFile = 'assignments.php';
  219. $rulesFile = 'rules.php';
  220. $oldData = include $oldFile;
  221. function saveToFile($data, $fileName) {
  222. $out = var_export($data, true);
  223. $out = "<?php\nreturn " . $out . ";";
  224. $out = str_replace(['array (', ')'], ['[', ']'], $out);
  225. file_put_contents($fileName, $out);
  226. }
  227. $items = [];
  228. $assignments = [];
  229. if (isset($oldData['items'])) {
  230. foreach ($oldData['items'] as $name => $data) {
  231. if (isset($data['assignments'])) {
  232. foreach ($data['assignments'] as $userId => $assignmentData) {
  233. $assignments[$userId][] = $assignmentData['roleName'];
  234. }
  235. unset($data['assignments']);
  236. }
  237. $items[$name] = $data;
  238. }
  239. }
  240. $rules = [];
  241. if (isset($oldData['rules'])) {
  242. $rules = $oldData['rules'];
  243. }
  244. saveToFile($items, $itemsFile);
  245. saveToFile($assignments, $assignmentsFile);
  246. saveToFile($rules, $rulesFile);
  247. echo "Done!\n";
  248. ```
  249. Run it once, delete `rbac.php`. If you've configured `authFile` property, remove the line from config and instead
  250. configure `itemFile`, `assignmentFile` and `ruleFile`.
  251. * Static helper `yii\helpers\Security` has been converted into an application component. You should change all usage of
  252. its methods to a new syntax, for example: instead of `yii\helpers\Security::hashData()` use `Yii::$app->getSecurity()->hashData()`.
  253. The `generateRandomKey()` method now produces not an ASCII compatible output. Use `generateRandomString()` instead.
  254. Default encryption and hash parameters has been upgraded. If you need to decrypt/validate data that was encrypted/hashed
  255. before, use the following configuration of the 'security' component:
  256. ```php
  257. return [
  258. 'components' => [
  259. 'security' => [
  260. 'derivationIterations' => 1000,
  261. ],
  262. // ...
  263. ],
  264. // ...
  265. ];
  266. ```
  267. * If you are using query caching, you should modify your relevant code as follows, as `beginCache()` and `endCache()` are
  268. replaced by `cache()`:
  269. ```php
  270. $db->cache(function ($db) {
  271. // ... SQL queries that need to use query caching
  272. }, $duration, $dependency);
  273. ```
  274. * Due to significant changes to security you need to upgrade your code to use `\yii\base\Security` component instead of
  275. helper. If you have any data encrypted it should be re-encrypted. In order to do so you can use old security helper
  276. [as explained by @docsolver at github](https://github.com/yiisoft/yii2/issues/4461#issuecomment-50237807).
  277. * [[yii\helpers\Url::to()]] will no longer prefix base URL to relative URLs. For example, `Url::to('images/logo.png')`
  278. will return `images/logo.png` directly. If you want a relative URL to be prefix with base URL, you should make use
  279. of the alias `@web`. For example, `Url::to('@web/images/logo.png')` will return `/BaseUrl/images/logo.png`.
  280. * The following properties are now taking `false` instead of `null` for "don't use" case:
  281. - `yii\bootstrap\NavBar::$brandLabel`.
  282. - `yii\bootstrap\NavBar::$brandUrl`.
  283. - `yii\bootstrap\Modal::$closeButton`.
  284. - `yii\bootstrap\Modal::$toggleButton`.
  285. - `yii\bootstrap\Alert::$closeButton`.
  286. - `yii\widgets\LinkPager::$nextPageLabel`.
  287. - `yii\widgets\LinkPager::$prevPageLabel`.
  288. - `yii\widgets\LinkPager::$firstPageLabel`.
  289. - `yii\widgets\LinkPager::$lastPageLabel`.
  290. * The format of the Faker fixture template is changed. For an example, please refer to the file
  291. `apps/advanced/common/tests/templates/fixtures/user.php`.
  292. * The signature of all file downloading methods in `yii\web\Response` is changed, as summarized below:
  293. - `sendFile($filePath, $attachmentName = null, $options = [])`
  294. - `sendContentAsFile($content, $attachmentName, $options = [])`
  295. - `sendStreamAsFile($handle, $attachmentName, $options = [])`
  296. - `xSendFile($filePath, $attachmentName = null, $options = [])`
  297. * The signature of callbacks used in `yii\base\ArrayableTrait::fields()` is changed from `function ($field, $model) {`
  298. to `function ($model, $field) {`.
  299. * `Html::radio()`, `Html::checkbox()`, `Html::radioList()`, `Html::checkboxList()` no longer generate the container
  300. tag around each radio/checkbox when you specify labels for them. You should manually render such container tags,
  301. or set the `item` option for `Html::radioList()`, `Html::checkboxList()` to generate the container tags.
  302. * The formatter class has been refactored to have only one class regardless whether PHP intl extension is installed or not.
  303. Functionality of `yii\base\Formatter` has been merged into `yii\i18n\Formatter` and `yii\base\Formatter` has been
  304. removed so you have to replace all usage of `yii\base\Formatter` with `yii\i18n\Formatter` in your code.
  305. Also the API of the Formatter class has changed in many ways.
  306. The signature of the following Methods has changed:
  307. - `asDate`
  308. - `asTime`
  309. - `asDatetime`
  310. - `asSize` has been split up into `asSize` and `asShortSize`
  311. - `asCurrency`
  312. - `asDecimal`
  313. - `asPercent`
  314. - `asScientific`
  315. The following methods have been removed, this also means that the corresponding format which may be used by a
  316. GridView or DetailView is not available anymore:
  317. - `asNumber`
  318. - `asDouble`
  319. Also due to these changes some formatting defaults have changes so you have to check all your GridView and DetailView
  320. configuration and make sure the formatting is displayed correctly.
  321. The configuration for `asSize()` has changed. It now uses the configuration for the number formatting from intl
  322. and only the base is configured using `$sizeFormatBase`.
  323. The specification of the date and time formats is now using the ICU pattern format even if PHP intl extension is not installed.
  324. You can prefix a date format with `php:` to use the old format of the PHP `date()`-function.
  325. * The DateValidator has been refactored to use the same format as the Formatter class now (see previous change).
  326. When you use the DateValidator and did not specify a format it will now be what is configured in the formatter class instead of 'Y-m-d'.
  327. To get the old behavior of the DateValidator you have to set the format explicitly in your validation rule:
  328. ```php
  329. ['attributeName', 'date', 'format' => 'php:Y-m-d'],
  330. ```
  331. * `beforeValidate()`, `beforeValidateAll()`, `afterValidate()`, `afterValidateAll()`, `ajaxBeforeSend()` and `ajaxComplete()`
  332. are removed from `ActiveForm`. The same functionality is now achieved via JavaScript event mechanism like the following:
  333. ```js
  334. $('#myform').on('beforeValidate', function (event, messages, deferreds) {
  335. // called when the validation is triggered by submitting the form
  336. // return false if you want to cancel the validation for the whole form
  337. }).on('beforeValidateAttribute', function (event, attribute, messages, deferreds) {
  338. // before validating an attribute
  339. // return false if you want to cancel the validation for the attribute
  340. }).on('afterValidateAttribute', function (event, attribute, messages) {
  341. // ...
  342. }).on('afterValidate', function (event, messages) {
  343. // ...
  344. }).on('beforeSubmit', function () {
  345. // after all validations have passed
  346. // you can do ajax form submission here
  347. // return false if you want to stop form submission
  348. });
  349. ```
  350. * The signature of `View::registerJsFile()` and `View::registerCssFile()` has changed. The `$depends` and `$position`
  351. paramaters have been merged into `$options`. The new signatures are as follows:
  352. - `registerJsFile($url, $options = [], $key = null)`
  353. - `registerCssFile($url, $options = [], $key = null)`