Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix duplicated modules on settings page #1786

Merged
merged 2 commits into from
Sep 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: fix duplicated modules on settings page
  • Loading branch information
djaiss committed Sep 6, 2018
commit 2e3792600f7421294163dd8ec17c836f7d63cc9f
42 changes: 42 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,42 @@
<?php

use App\Models\Account\Account;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
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);
}
}
}
});
}
}