Commit 41177b02 by Carsten Brandt

Update UPGRADE.md

fixed indentation
parent b90f8865
...@@ -77,50 +77,50 @@ Upgrade from Yii 2.0 Beta ...@@ -77,50 +77,50 @@ Upgrade from Yii 2.0 Beta
* `\yii\rbac\PhpManager` now stores data in three separate files instead of one. In order to convert old file to * `\yii\rbac\PhpManager` now stores data in three separate files instead of one. In order to convert old file to
new ones save the following code as `convert.php` that should be placed in the same directory your `rbac.php` is in: new ones save the following code as `convert.php` that should be placed in the same directory your `rbac.php` is in:
```php ```php
<?php <?php
$oldFile = 'rbac.php'; $oldFile = 'rbac.php';
$itemsFile = 'items.php'; $itemsFile = 'items.php';
$assignmentsFile = 'assignments.php'; $assignmentsFile = 'assignments.php';
$rulesFile = 'rules.php'; $rulesFile = 'rules.php';
$oldData = include $oldFile; $oldData = include $oldFile;
function saveToFile($data, $fileName) { function saveToFile($data, $fileName) {
$out = var_export($data, true); $out = var_export($data, true);
$out = "<?php\nreturn " . $out . ";"; $out = "<?php\nreturn " . $out . ";";
$out = str_replace(['array (', ')'], ['[', ']'], $out); $out = str_replace(['array (', ')'], ['[', ']'], $out);
file_put_contents($fileName, $out); file_put_contents($fileName, $out);
} }
$items = []; $items = [];
$assignments = []; $assignments = [];
if (isset($oldData['items'])) { if (isset($oldData['items'])) {
foreach ($oldData['items'] as $name => $data) { foreach ($oldData['items'] as $name => $data) {
if (isset($data['assignments'])) { if (isset($data['assignments'])) {
foreach ($data['assignments'] as $userId => $assignmentData) { foreach ($data['assignments'] as $userId => $assignmentData) {
$assignments[$userId] = $assignmentData['roleName']; $assignments[$userId] = $assignmentData['roleName'];
} }
unset($data['assignments']); unset($data['assignments']);
} }
$items[$name] = $data; $items[$name] = $data;
} }
} }
$rules = []; $rules = [];
if (isset($oldData['rules'])) { if (isset($oldData['rules'])) {
$rules = $oldData['rules']; $rules = $oldData['rules'];
} }
saveToFile($items, $itemsFile); saveToFile($items, $itemsFile);
saveToFile($assignments, $assignmentsFile); saveToFile($assignments, $assignmentsFile);
saveToFile($rules, $rulesFile); saveToFile($rules, $rulesFile);
echo "Done!\n"; echo "Done!\n";
``` ```
Run it once, delete `rbac.php`. If you've configured `authFile` property, remove the line from config and instead Run it once, delete `rbac.php`. If you've configured `authFile` property, remove the line from config and instead
configure `itemFile`, `assignmentFile` and `ruleFile`. configure `itemFile`, `assignmentFile` and `ruleFile`.
* Static helper `yii\helpers\Security` has been converted into an application component. You should change all usage of * Static helper `yii\helpers\Security` has been converted into an application component. You should change all usage of
its methods to a new syntax, for example: instead of `yii\helpers\Security::hashData()` use `Yii::$app->getSecurity()->hashData()`. its methods to a new syntax, for example: instead of `yii\helpers\Security::hashData()` use `Yii::$app->getSecurity()->hashData()`.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment