| Total Complexity | 4 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 8 | class m180429_160926_fix_public_link extends Migration |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * {@inheritdoc} |
||
| 12 | */ |
||
| 13 | public function safeUp() |
||
| 14 | { |
||
| 15 | $accountIds = (new \yii\db\Query()) |
||
| 16 | ->from('account') |
||
| 17 | ->andWhere(['account.monitoring' => 1]) |
||
| 18 | ->andWhere(['account.uid' => null]) |
||
| 19 | ->column(); |
||
| 20 | |||
| 21 | foreach ($accountIds as $accountId) { |
||
| 22 | |||
| 23 | do { |
||
| 24 | $uid = Yii::$app->security->generateRandomString(64); |
||
| 25 | $uidExist = (new \yii\db\Query()) |
||
| 26 | ->from('account') |
||
| 27 | ->andWhere(['account.uid' => $uid]) |
||
| 28 | ->exists(); |
||
| 29 | } while ($uidExist); |
||
| 30 | |||
| 31 | $this->update('account', ['uid' => $uid], ['id' => $accountId]); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc} |
||
| 37 | */ |
||
| 38 | public function safeDown() |
||
| 41 | } |
||
| 42 | |||
| 58 |