Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
MigrateCrmUsers
n/a
0 / 0
n/a
0 / 0
6
n/a
0 / 0
 handle
n/a
0 / 0
n/a
0 / 0
6
1<?php
2
3namespace App\Console\Commands;
4
5use App\Lib\MigrateOldData;
6use App\Models\Brand;
7use Illuminate\Console\Command;
8use Illuminate\Support\Facades\DB;
9
10/**
11 * @codeCoverageIgnore
12 */
13class MigrateCrmUsers extends Command
14{
15    /**
16     * The name and signature of the console command.
17     *
18     * @var string
19     */
20    protected $signature = 'migrate:crm';
21
22    /**
23     * The console command description.
24     *
25     * @var string
26     */
27    protected $description = 'Migrate crm users';
28
29
30    /**
31     * Execute the console command.
32     *
33     * @return integer
34     */
35    public function handle(): int
36    {
37        try {
38            $table = $this->ask('What is the tmp table name with users data ?');
39
40            try {
41                DB::connection(config('database.oldDB'))->table($table)->exists();
42            } catch (\Exception $e) {
43                $this->error(sprintf('%s table not found on old crm database', $table));
44                return -1;
45            }
46
47            $brandname = $this->ask('What is the brand name ?');
48            $brand     = Brand::query()->where('name', 'LIKE', "%$brandname%")->first();
49            if (!$brand) {
50                if (!$this->confirm(sprintf('Would you like to use %s ? ', $brandname))) {
51                    $this->info('Command cancelled');
52                    return 0;
53                }
54                if ($this->confirm('Would you like to create a new one ?')) {
55                    $brand       = new Brand();
56                    $brand->name = $brandname;
57                    $brand->save();
58                } else {
59                    $this->info('Command cancelled');
60                    return 0;
61                }
62            }
63
64            $mgOldData = new MigrateOldData();
65            $mgOldData->runMigration($brand, $table);
66        } catch (\Exception $e) {
67            $this->error(sprintf('Failed %s', $e));
68            return -1;
69        } //end try
70        return 0;
71    }
72}