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