| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace app\migrations;
- use yii\db\Migration;
- use common\models\rbac\AuthItem;
- /**
- * Class M240627052138QimallRbacAuthItemUpdate
- */
- class M240627052138QimallRbacAuthItemUpdate extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- try {
- // 将id=2823的记录中的name更新为mall/setting
- $record = AuthItem::findOne(2823);
- if ($record !== null) {
- $record->name = 'mall/setting';
- $record->save();
- }
- // 更新name=mall/setting/memory的记录的pid为2823
- AuthItem::updateAll(['pid' => 2823], ['name' => 'mall/setting/memory']);
- // 查找所有name=mall/setting的记录
- $settingRecords = AuthItem::find()
- ->where(['name' => 'mall/setting'])
- ->all();
- // 删除第二个name=mall/setting的记录
- if (count($settingRecords) > 1) {
- $settingRecords[1]->delete();
- }
- } catch (\Exception $e) {
- \Yii::error('更新权限菜单错误:' . $e->getMessage());
- }
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M240627052138QimallRbacAuthItemUpdate cannot be reverted.\n";
- return false;
- }
- /*
- // Use up()/down() to run migration code without a transaction.
- public function up()
- {
- }
- public function down()
- {
- echo "M240627052138QimallRbacAuthItemUpdate cannot be reverted.\n";
- return false;
- }
- */
- }
|