Projeto

Geral

Perfil

Estatísticas
| Branch: | Revisão:

expressolivretools / app / Console / Commands / Expresso / SieveGetUid.php @ 68c328a2

Histórico | Ver | Anotar | Baixar (3,07 KB)

1 3e379cec Alexandre Correia
<?php
2
3
namespace App\Console\Commands\Expresso;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\DB;
7
use Storage;
8
9
class SieveGetUid extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'expresso:sieve-get {--u|uid=} {cmd?}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Lista os scripts sieve do usuario';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $arguments = $this->arguments();
43
44
        $uid = $this->option('uid') ?? null;
45
46
        if( isset($arguments['cmd']) && $arguments['cmd'] == 'help' )
47
        {
48
            $this->help();
49
50
        } else {
51
52
            if( !is_null($uid) ){
53
54
                $sieveRules = $this->getSieveRules($uid);
55
                
56
                if( isset($arguments['cmd']) && $arguments['cmd'] == 'print' )
57
                {
58
                    $rules      = [];
59
                    foreach( $sieveRules as $key => $sieve ){
60
                        $rules[$key]['regra']       = unserialize( $sieve->rule );
61
                        $rules[$key]['habilitada']  = $sieve->is_enabled;
62
                        $rules[$key]['dt_criacao']  = date('d/m/Y', strtotime($sieve->created_dt));
63
                        
64
                        print_r( $rules[$key] );
65
                    }
66
                }
67
68
                if( isset($arguments['cmd']) && $arguments['cmd'] == 'file' )
69
                {
70
                    $lines = "Usuario : " . $uid . PHP_EOL;
71
72
                    foreach( $sieveRules as $key => $sieve ){
73
                        $lines .= "regra      : " . $sieve->rule . PHP_EOL;
74
                        $lines .= "habilitada : " . $sieve->is_enabled . PHP_EOL;
75
                        $lines .= "dt_criacao : " . date('d/m/Y', strtotime($sieve->created_dt)) . PHP_EOL;
76
                        $lines .= "************************************************************************" . PHP_EOL . PHP_EOL;
77
                    }
78
79
                    Storage::put('file/file_'.$uid.'.txt', $lines );
80
                }
81
82
                if( isset($arguments['cmd']) && $arguments['cmd'] == 'fileSogo' )
83
                {
84
                    print_r( storage_path('fileSogo') );
85
                }
86
            }
87
        }
88
89
        $this->newLine();
90
    }
91
92
    private function getSieveRules( $user )
93
    {
94
        $sieveRules = DB::connection('pgsql-expresso')
95
                            ->table('phpgw_sieve_rules')
96
                            ->where('fk_sieve_owner', $user )
97
                            ->get();
98
99
        return $sieveRules;
100
    }
101
102
    private function help()
103
    {
104
        $this->newLine();
105
        $this->info('EXEMPLO DE UTILIZACAO : ');
106
        $this->info('Ex: php artisan expresso:sieve-get --uid=<000000> { print | file | fileSogo }');
107
        $this->newLine();
108
    }
109
}