#2661 Profile education field error

This commit is contained in:
Diatrex 2020-11-23 11:30:09 +03:00
parent b479c89399
commit e405d95fef
2 changed files with 50 additions and 127 deletions

View File

@ -1,64 +0,0 @@
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
class VisiosoftModuleProfileCreateProfessionAndEducationalFields extends Migration
{
public function up()
{
if ($stream = $this->streams()->findBySlugAndNamespace('users', 'users')) {
$fields = [
[
'name' => trans('visiosoft.module.profile::field.education.name'),
'slug' => 'education',
],
[
'name' => trans('visiosoft.module.profile::field.state_of_education.name'),
'slug' => 'state_of_education',
],
[
'name' => trans('visiosoft.module.profile::field.profession.name'),
'slug' => 'profession',
],
];
foreach ($fields as $field) {
$exists = $this->fields()
->newQuery()
->where('slug', $field['slug'])
->where('namespace', 'users')
->first();
if (!$exists) {
$userField = $this->fields()->create([
'name' => $field['name'],
'namespace' => 'users',
'slug' => $field['slug'],
'type' => 'anomaly.field_type.text',
'locked' => 0,
]);
$this->assignments()->create([
'stream_id' => $stream->id,
'field_id' => $userField->id
]);
}
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
/*
* I never go back on my word!
* That's my nindo: my ninja way!
* NARUTO
*/
}
}

View File

@ -1,29 +1,17 @@
<?php namespace Visiosoft\ProfileModule\Seed; <?php namespace Visiosoft\ProfileModule\Seed;
use Anomaly\Streams\Platform\Assignment\AssignmentModelTranslation;
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface; use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface;
use Anomaly\Streams\Platform\Database\Seeder\Seeder; use Anomaly\Streams\Platform\Database\Seeder\Seeder;
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface; use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface;
use Anomaly\Streams\Platform\Field\FieldModelTranslation;
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface; use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface;
use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\Country\CountryModel;
class UsersFieldsSeeder extends Seeder class UsersFieldsSeeder extends Seeder
{ {
/**
* Run the seeder.
* @param FieldRepositoryInterface $fieldRepository
* @param AssignmentRepositoryInterface $assignmentRepository
* @param StreamRepositoryInterface $streamRepository
* @param FieldModelTranslation $fieldModelTranslation
* @param AssignmentModelTranslation $assignmentModelTranslation
*/
public function run( public function run(
FieldRepositoryInterface $fieldRepository, FieldRepositoryInterface $fieldRepository,
AssignmentRepositoryInterface $assignmentRepository, AssignmentRepositoryInterface $assignmentRepository,
StreamRepositoryInterface $streamRepository, StreamRepositoryInterface $streamRepository
FieldModelTranslation $fieldModelTranslation,
AssignmentModelTranslation $assignmentModelTranslation
) )
{ {
$namespace = 'users'; $namespace = 'users';
@ -31,7 +19,7 @@ class UsersFieldsSeeder extends Seeder
$stream = $streamRepository->findBySlugAndNamespace('users', 'users'); $stream = $streamRepository->findBySlugAndNamespace('users', 'users');
$customFields = [ $customFields = [
0 => [ [
'name' => 'File', 'name' => 'File',
'slug' => 'file', 'slug' => 'file',
'type' => 'visiosoft.field_type.singlefile', 'type' => 'visiosoft.field_type.singlefile',
@ -40,7 +28,7 @@ class UsersFieldsSeeder extends Seeder
'mode' => 'upload', 'mode' => 'upload',
] ]
], ],
1 => [ [
'name' => 'Country', 'name' => 'Country',
'slug' => 'country', 'slug' => 'country',
'type' => 'anomaly.field_type.relationship', 'type' => 'anomaly.field_type.relationship',
@ -49,7 +37,7 @@ class UsersFieldsSeeder extends Seeder
"default_value" => 0, "default_value" => 0,
], ],
], ],
2 => [ [
'name' => 'City', 'name' => 'City',
'slug' => 'city', 'slug' => 'city',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -57,7 +45,7 @@ class UsersFieldsSeeder extends Seeder
"options" => [], "options" => [],
] ]
], ],
3 => [ [
'name' => 'District', 'name' => 'District',
'slug' => 'district', 'slug' => 'district',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -65,7 +53,7 @@ class UsersFieldsSeeder extends Seeder
"options" => [], "options" => [],
] ]
], ],
4 => [ [
'name' => 'Neighborhood', 'name' => 'Neighborhood',
'slug' => 'neighborhood', 'slug' => 'neighborhood',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -73,7 +61,7 @@ class UsersFieldsSeeder extends Seeder
"options" => [], "options" => [],
] ]
], ],
5 => [ [
'name' => 'Village', 'name' => 'Village',
'slug' => 'village', 'slug' => 'village',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -81,22 +69,22 @@ class UsersFieldsSeeder extends Seeder
"options" => [], "options" => [],
] ]
], ],
6 => [ [
'name' => 'Gsm Phone', 'name' => 'Gsm Phone',
'slug' => 'gsm_phone', 'slug' => 'gsm_phone',
'type' => 'anomaly.field_type.text', 'type' => 'anomaly.field_type.text',
], ],
7 => [ [
'name' => 'Land Phone', 'name' => 'Land Phone',
'slug' => 'land_phone', 'slug' => 'land_phone',
'type' => 'anomaly.field_type.text', 'type' => 'anomaly.field_type.text',
], ],
8 => [ [
'name' => 'Office Phone', 'name' => 'Office Phone',
'slug' => 'office_phone', 'slug' => 'office_phone',
'type' => 'anomaly.field_type.text', 'type' => 'anomaly.field_type.text',
], ],
9 => [ [
'name' => 'Register Type', 'name' => 'Register Type',
'slug' => 'register_type', 'slug' => 'register_type',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -107,12 +95,12 @@ class UsersFieldsSeeder extends Seeder
], ],
] ]
], ],
10 => [ [
'name' => 'Identification Number', 'name' => 'Identification Number',
'slug' => 'identification_number', 'slug' => 'identification_number',
'type' => 'anomaly.field_type.text', 'type' => 'anomaly.field_type.text',
], ],
11 => [ [
'name' => 'Notified New Updates', 'name' => 'Notified New Updates',
'slug' => 'notified_new_updates', 'slug' => 'notified_new_updates',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -122,7 +110,7 @@ class UsersFieldsSeeder extends Seeder
'separator' => ':', 'separator' => ':',
] ]
], ],
12 => [ [
'name' => 'Notified About Ads', 'name' => 'Notified About Ads',
'slug' => 'notified_about_ads', 'slug' => 'notified_about_ads',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -132,7 +120,7 @@ class UsersFieldsSeeder extends Seeder
'separator' => ':', 'separator' => ':',
] ]
], ],
13 => [ [
'name' => 'Receive Messages Email', 'name' => 'Receive Messages Email',
'slug' => 'receive_messages_email', 'slug' => 'receive_messages_email',
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
@ -142,7 +130,7 @@ class UsersFieldsSeeder extends Seeder
'separator' => ':', 'separator' => ':',
] ]
], ],
14 => [ [
'name' => trans('visiosoft.module.profile::field.birthday.name'), 'name' => trans('visiosoft.module.profile::field.birthday.name'),
'slug' => 'birthday', 'slug' => 'birthday',
'type' => 'anomaly.field_type.datetime', 'type' => 'anomaly.field_type.datetime',
@ -151,50 +139,49 @@ class UsersFieldsSeeder extends Seeder
"picker" => true, "picker" => true,
] ]
], ],
[
'name' => trans('visiosoft.module.profile::field.education.name'),
'slug' => 'education',
'type' => 'anomaly.field_type.text',
],
[
'name' => trans('visiosoft.module.profile::field.state_of_education.name'),
'slug' => 'state_of_education',
'type' => 'anomaly.field_type.text',
],
[
'name' => trans('visiosoft.module.profile::field.profession.name'),
'slug' => 'profession',
'type' => 'anomaly.field_type.text',
],
]; ];
foreach ($customFields as $customField) { foreach ($customFields as $customField) {
$fields = $fieldRepository $field = $fieldRepository
->newQuery() ->newQuery()
->where('slug', $customField['slug']) ->where('slug', $customField['slug'])
->where('namespace', $namespace) ->where('namespace', $namespace)
->get(); ->first();
if ($fields) { if (!$field) {
foreach ($fields as $field) { $data = [
$fieldModelTranslation->newQuery()->where('field_id', $field->id)->delete(); 'name' => $customField['name'],
'namespace' => $namespace,
$assignment = $assignmentRepository 'slug' => $customField['slug'],
->newQuery() 'type' => $customField['type'],
->where('stream_id', $stream->id) 'locked' => $locked
->where('field_id', $field->id) ];
->first(); if (isset($customField['config'])) {
if ($assignment) { $data['config'] = $customField['config'];
$assignmentModelTranslation->newQuery()->where('assignment_id', $assignment->id)->delete();
$assignment->delete();
}
$field->delete();
} }
$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
]);
} }
} }
} }