Skip to content

Commit

Permalink
fix: fix duplicated modules on settings page (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Sep 6, 2018
1 parent 8facc8b commit 09b86c6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions database/migrations/2018_09_05_213507_mark_modules_migrated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use App\Models\Account\Account;
use Illuminate\Database\Migrations\Migration;

/**
* This fixes a script that ran in 2.7.0 that duplicated all the modules for each
* user.
*/
class MarkModulesMigrated extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Account::chunk(200, function ($accounts) {
foreach ($accounts as $account) {
$modules = $account->modules;
$uniqueModules = collect([]);
foreach ($modules as $module) {
$deleted = false;
foreach ($uniqueModules as $uniqueModule) {
if ($uniqueModule['translation_key'] == $module->translation_key) {
$module->delete();
$deleted = true;
}
}

if (! $deleted) {
$uniqueModules->push($module);
}
}
}
});
}
}

0 comments on commit 09b86c6

Please sign in to comment.