PhotosPrepare::getDisk()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 Muleta\Utils\Modificators\StringModificator;
12
13
class PhotosPrepare extends Command
14
{
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'simport:finder:photos';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Importar todas as fotos !';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $folder = 'midia';
35
36
    /**
37
     * Create a new command instance.
38
     *
39
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

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.

Loading history...
40
     */
41
    public function __construct()
42
    {
43
        parent::__construct();
44
    }
45
46
    /**
47
     * Execute the console command.
48
     *
49
     * @return mixed
50
     */
51
    public function handle()
52
    {
53
        $this->midiaFinder($this->folder);
54
    }
55
56
    /**
57
     * Execute the console command.
58
     *
59
     * @return mixed
60
     */
61
    public function midiaFinder($folder)
62
    {
63
        
64
        // $files = Storage::allFiles($folder);
65
        // dd(Storage::files($folder));
66
        // dd(Storage::allFiles($folder));
67
        $directorys = Storage::directories($folder);
68
69
        // dd(
70
        //     Person::all(),
71
        //     $directorys
72
        // );
73
74
        foreach ($directorys as $directory) {
75
            $directoryName = explode('/', $directory);
76
            $personName = StringModificator::cleanCodeSlug($directoryName[count($directoryName)-1]);
77
78
            if ($personName=='git') {
79
                continue;
80
            }
81
82
            // dd(
83
            //     $directoryName,
84
            //     $personName,
85
            //     StringModificator::cleanCodeSlug($personName)
86
            // );
87
88
            $person = Person::createIfNotExistAndReturn($personName);
89
            $this->info('[Importing] Importando fotos de usuário '.$person->name);
90
            $this->importFromFolder($person, $directory);
91
        }
92
    }
93
94
    /**
95
     * Tirardaqui @todo
96
     */
97
    public function getDisk()
98
    {
99
        // @todo usar config
100
        return \Illuminate\Support\Facades\Config::get('facilitador.storage.disk', \Illuminate\Support\Facades\Config::get('filesystems.default'));
101
    }
102
103
    /**
104
     * Tirardaqui @todo
105
     */
106
    public function importFromFolder(Person $target, string $folder)
107
    {
108
        $files = Storage::allFiles($folder);
109
        // dd('oi', $files);
110
        foreach ($files as $file) {
111
112
            $fileName = explode('/', $file);
113
            $fileName = $fileName[count($fileName)-1];
114
115
            Imagen::createByMediaFromDisk(
116
                $this->getDisk(),
117
                $file,
118
                $target,
119
                [
120
                    'name' => $fileName,
121
                    'fingerprint' => $fileName
122
                ]
123
            );
124
125
            // $this->count = $this->count + 1;
126
        }
127
    }
128
}
129