remove command prompt

This commit is contained in:
Diatrex 2020-10-13 09:16:55 +03:00
parent 83f6f9207d
commit 6ee0ce02a9

View File

@ -26,177 +26,175 @@ class UsersFieldsSeeder extends Seeder
AssignmentModelTranslation $assignmentModelTranslation AssignmentModelTranslation $assignmentModelTranslation
) )
{ {
if ($this->command->confirm('This command will remove the old custom fields from the users table! Are you sure you want to continue?')) { $namespace = 'users';
$namespace = 'users'; $locked = 0;
$locked = 0; $stream = $streamRepository->findBySlugAndNamespace('users', 'users');
$stream = $streamRepository->findBySlugAndNamespace('users', 'users');
$customFields = [ $customFields = [
0 => [ 0 => [
'name' => 'File', 'name' => 'File',
'slug' => 'file', 'slug' => 'file',
'type' => 'visiosoft.field_type.singlefile', 'type' => 'visiosoft.field_type.singlefile',
'config' => [ 'config' => [
'folders' => ["images"], 'folders' => ["images"],
'mode' => 'upload', 'mode' => 'upload',
] ]
],
1 => [
'name' => 'Country',
'slug' => 'country',
'type' => 'anomaly.field_type.relationship',
'config' => [
'related' => CountryModel::class,
"default_value" => 0,
], ],
1 => [ ],
'name' => 'Country', 2 => [
'slug' => 'country', 'name' => 'City',
'type' => 'anomaly.field_type.relationship', 'slug' => 'city',
'config' => [ 'type' => 'anomaly.field_type.select',
'related' => CountryModel::class, "config" => [
"default_value" => 0, "options" => [],
]
],
3 => [
'name' => 'District',
'slug' => 'district',
'type' => 'anomaly.field_type.select',
"config" => [
"options" => [],
]
],
4 => [
'name' => 'Neighborhood',
'slug' => 'neighborhood',
'type' => 'anomaly.field_type.select',
"config" => [
"options" => [],
]
],
5 => [
'name' => 'Village',
'slug' => 'village',
'type' => 'anomaly.field_type.select',
"config" => [
"options" => [],
]
],
6 => [
'name' => 'Gsm Phone',
'slug' => 'gsm_phone',
'type' => 'anomaly.field_type.text',
],
7 => [
'name' => 'Land Phone',
'slug' => 'land_phone',
'type' => 'anomaly.field_type.text',
],
8 => [
'name' => 'Office Phone',
'slug' => 'office_phone',
'type' => 'anomaly.field_type.text',
],
9 => [
'name' => 'Register Type',
'slug' => 'register_type',
'type' => 'anomaly.field_type.select',
"config" => [
"options" => [
'1' => trans('visiosoft.module.profile::field.individual.name'),
'2' => trans('visiosoft.module.profile::field.corporate.name')
], ],
], ]
2 => [ ],
'name' => 'City', 10 => [
'slug' => 'city', 'name' => 'Identification Number',
'type' => 'anomaly.field_type.select', 'slug' => 'identification_number',
"config" => [ 'type' => 'anomaly.field_type.text',
"options" => [], ],
] 11 => [
], 'name' => 'Notified New Updates',
3 => [ 'slug' => 'notified_new_updates',
'name' => 'District', 'type' => 'anomaly.field_type.select',
'slug' => 'district', 'config' => [
'type' => 'anomaly.field_type.select', 'default_value' => 1,
"config" => [ 'options' => [0 => 'Active', 1 => 'Passive'],
"options" => [], 'separator' => ':',
] ]
], ],
4 => [ 12 => [
'name' => 'Neighborhood', 'name' => 'Notified About Ads',
'slug' => 'neighborhood', 'slug' => 'notified_about_ads',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
"config" => [ 'config' => [
"options" => [], 'default_value' => 1,
] 'options' => [0 => 'Active', 1 => 'Passive'],
], 'separator' => ':',
5 => [ ]
'name' => 'Village', ],
'slug' => 'village', 13 => [
'type' => 'anomaly.field_type.select', 'name' => 'Receive Messages Email',
"config" => [ 'slug' => 'receive_messages_email',
"options" => [], 'type' => 'anomaly.field_type.select',
] 'config' => [
], 'default_value' => 1,
6 => [ 'options' => [0 => 'Active', 1 => 'Passive'],
'name' => 'Gsm Phone', 'separator' => ':',
'slug' => 'gsm_phone', ]
'type' => 'anomaly.field_type.text', ],
], 14 => [
7 => [ 'name' => trans('visiosoft.module.profile::field.birthday.name'),
'name' => 'Land Phone', 'slug' => 'birthday',
'slug' => 'land_phone', 'type' => 'anomaly.field_type.datetime',
'type' => 'anomaly.field_type.text', 'config' => [
], "mode" => "date",
8 => [ "picker" => true,
'name' => 'Office Phone', ]
'slug' => 'office_phone', ],
'type' => 'anomaly.field_type.text', ];
],
9 => [
'name' => 'Register Type',
'slug' => 'register_type',
'type' => 'anomaly.field_type.select',
"config" => [
"options" => [
'1' => trans('visiosoft.module.profile::field.individual.name'),
'2' => trans('visiosoft.module.profile::field.corporate.name')
],
]
],
10 => [
'name' => 'Identification Number',
'slug' => 'identification_number',
'type' => 'anomaly.field_type.text',
],
11 => [
'name' => 'Notified New Updates',
'slug' => 'notified_new_updates',
'type' => 'anomaly.field_type.select',
'config' => [
'default_value' => 1,
'options' => [0 => 'Active', 1 => 'Passive'],
'separator' => ':',
]
],
12 => [
'name' => 'Notified About Ads',
'slug' => 'notified_about_ads',
'type' => 'anomaly.field_type.select',
'config' => [
'default_value' => 1,
'options' => [0 => 'Active', 1 => 'Passive'],
'separator' => ':',
]
],
13 => [
'name' => 'Receive Messages Email',
'slug' => 'receive_messages_email',
'type' => 'anomaly.field_type.select',
'config' => [
'default_value' => 1,
'options' => [0 => 'Active', 1 => 'Passive'],
'separator' => ':',
]
],
14 => [
'name' => trans('visiosoft.module.profile::field.birthday.name'),
'slug' => 'birthday',
'type' => 'anomaly.field_type.datetime',
'config' => [
"mode" => "date",
"picker" => true,
]
],
];
foreach ($customFields as $customField) { foreach ($customFields as $customField) {
$fields = $fieldRepository $fields = $fieldRepository
->newQuery() ->newQuery()
->where('slug', $customField['slug']) ->where('slug', $customField['slug'])
->where('namespace', $namespace) ->where('namespace', $namespace)
->get(); ->get();
if ($fields) { if ($fields) {
foreach ($fields as $field) { foreach ($fields as $field) {
$fieldModelTranslation->newQuery()->where('field_id', $field->id)->delete(); $fieldModelTranslation->newQuery()->where('field_id', $field->id)->delete();
$assignment = $assignmentRepository $assignment = $assignmentRepository
->newQuery() ->newQuery()
->where('stream_id', $stream->id) ->where('stream_id', $stream->id)
->where('field_id', $field->id) ->where('field_id', $field->id)
->first(); ->first();
if ($assignment) { if ($assignment) {
$assignmentModelTranslation->newQuery()->where('assignment_id', $assignment->id)->delete(); $assignmentModelTranslation->newQuery()->where('assignment_id', $assignment->id)->delete();
$assignment->delete(); $assignment->delete();
}
$field->delete();
} }
$field->delete();
} }
$data = [
'name' => $customField['name'],
'namespace' => $namespace,
'slug' => $customField['slug'],
'type' => $customField['type'],
'locked' => $locked
];
if (isset($customField['config'])) {
$data['config'] = $customField['config'];
}
$field = $fieldRepository->create($data);
$assignmentRepository->create([
'stream_id' => $stream->id,
'field_id' => $field->id
]);
} }
$data = [
'name' => $customField['name'],
'namespace' => $namespace,
'slug' => $customField['slug'],
'type' => $customField['type'],
'locked' => $locked
];
if (isset($customField['config'])) {
$data['config'] = $customField['config'];
}
$field = $fieldRepository->create($data);
$assignmentRepository->create([
'stream_id' => $stream->id,
'field_id' => $field->id
]);
} }
} }
} }