Improve check data account id checks

This commit is contained in:
Hillel Coren 2017-01-01 20:36:02 +02:00
parent f71adbc388
commit 9cfdfe3099

View File

@ -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;