1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Finder\Console\Commands\Prepare; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Telefonica\Models\Actors\Person; |
7
|
|
|
use Finder\Pipelines\Track\PersonTrack; |
8
|
|
|
use Illuminate\Support\Facades\Storage; |
9
|
|
|
use Stalker\Models\Imagen; |
10
|
|
|
|
11
|
|
|
use Rap2hpoutre\FastExcel\FastExcel; |
12
|
|
|
|
13
|
|
|
use Finder\Pipelines\Identify\RespectiveModel; |
14
|
|
|
|
15
|
|
|
use Muleta\Utils\Extratores\FileExtractor; |
16
|
|
|
use Muleta\Utils\Extratores\StringExtractor; |
17
|
|
|
use Muleta\Utils\Modificators\StringModificator; |
18
|
|
|
|
19
|
|
|
class ExcelPrepare extends Command |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The name and signature of the console command. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $signature = 'simport:finder:excell'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The console command description. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $description = 'Importar a porra toda !'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The console command description. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $folder = 'import'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Create a new command instance. |
44
|
|
|
* |
45
|
|
|
* @return void |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
public function __construct() |
48
|
|
|
{ |
49
|
|
|
parent::__construct(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Execute the console command. |
54
|
|
|
* |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public function handle() |
58
|
|
|
{ |
59
|
|
|
$this->importFromFolder($this->folder); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Tirardaqui |
64
|
|
|
*/ |
65
|
|
|
public function importFromFolder($folder) |
66
|
|
|
{ |
67
|
|
|
$files = Storage::allFiles($folder); |
68
|
|
|
foreach ($files as $file) { |
69
|
|
|
|
70
|
|
|
$fileName = FileExtractor::getFileName($file); |
71
|
|
|
$assuntosDaPasta = FileExtractor::returnFoldersInarray($file, $folder); |
72
|
|
|
|
73
|
|
|
$collection = (new FastExcel)->configureCsv(';', '#', '\n', 'gbk') //, 'gbk' |
|
|
|
|
74
|
|
|
// $collections = (new FastExcel) |
75
|
|
|
->import( |
76
|
|
|
storage_path('app/'.$file), |
77
|
|
|
function ($line) use ($fileName, $assuntosDaPasta) { |
78
|
|
|
$modelClass = RespectiveModel::run( |
79
|
|
|
$assuntosDaPasta, |
80
|
|
|
$fileName |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
if (!$modelClass) { |
84
|
|
|
$this->info('Ignorando importação de '.$fileName); |
85
|
|
|
return ; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->info('Importing '.$fileName.' p/ classe '.$modelClass); |
89
|
|
|
return call_user_func( |
90
|
|
|
$modelClass.'::importFromArray', |
91
|
|
|
$line |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
// Imagen::createByMediaFromDisk( |
97
|
|
|
// $this->getDisk(), |
98
|
|
|
// $file, |
99
|
|
|
// $target, |
100
|
|
|
// [ |
101
|
|
|
// 'name' => $fileName, |
102
|
|
|
// 'fingerprint' => $fileName |
103
|
|
|
// ] |
104
|
|
|
// ); |
105
|
|
|
|
106
|
|
|
// $this->count = $this->count + 1; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
// $name = $this->ask('Enter the admin name'); |
112
|
|
|
// $password = $this->secret('Enter admin password'); |
113
|
|
|
// $confirmPassword = $this->secret('Confirm Password'); |
114
|
|
|
|
115
|
|
|
// // Ask for email if there wasnt set one |
116
|
|
|
// if (!$email) { |
117
|
|
|
// $email = $this->ask('Enter the admin email'); |
118
|
|
|
// } |
119
|
|
|
|
120
|
|
|
// // Passwords don't match |
121
|
|
|
// if ($password != $confirmPassword) { |
122
|
|
|
// $this->info("Passwords don't match"); |
123
|
|
|
|
124
|
|
|
// return; |
125
|
|
|
// } |
126
|
|
|
|
127
|
|
|
// $this->info('Creating admin account'); |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.