diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 9b5bbad58eef..002fa55749d3 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -2,6 +2,7 @@ use DB; use Mail; +use Utils; use Carbon; use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; @@ -142,20 +143,26 @@ class CheckData extends Command { ENTITY_VENDOR, ENTITY_INVOICE, ENTITY_USER + ], + 'products' => [ + ENTITY_USER, + ], + 'expense_categories' => [ + ENTITY_USER, + ], + 'projects' => [ + ENTITY_USER, + ENTITY_CLIENT, ] ]; foreach ($tables as $table => $entityTypes) { foreach ($entityTypes as $entityType) { + $tableName = Utils::pluralizeEntityType($entityType); $records = DB::table($table) - ->join("{$entityType}s", "{$entityType}s.id", '=', "{$table}.{$entityType}_id"); - - if ($entityType != ENTITY_CLIENT) { - $records = $records->join('clients', 'clients.id', '=', "{$table}.client_id"); - } - - $records = $records->where("{$table}.account_id", '!=', DB::raw("{$entityType}s.account_id")) - ->get(["{$table}.id", 'clients.account_id', 'clients.user_id']); + ->join($tableName, "{$tableName}.id", '=', "{$table}.{$entityType}_id") + ->where("{$table}.account_id", '!=', DB::raw("{$tableName}.account_id")) + ->get(["{$table}.id"]); if (count($records)) { $this->isValid = false;