expressolivretools / app / Console / Commands / Expresso / SieveGetUid.php @ master
Histórico | Ver | Anotar | Baixar (2,62 KB)
1 |
<?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:get-user-sieve-filters-by-line {--u|uid=} {cmd?}'; |
17 |
|
18 |
/**
|
19 |
* The console command description.
|
20 |
*
|
21 |
* @var string
|
22 |
*/
|
23 |
protected $description = 'lista os filtros de usuários ( entrada: usuários separados por vírgula )'; |
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 |
|
47 |
if( !is_null($uid) ){ |
48 |
|
49 |
$sieveRules = $this->getSieveRules($uid); |
50 |
|
51 |
if( isset($arguments['cmd']) && $arguments['cmd'] == 'print' ) |
52 |
{ |
53 |
$rules = [];
|
54 |
foreach( $sieveRules as $key => $sieve ){ |
55 |
$rules[$key]['regra'] = unserialize( $sieve->rule ); |
56 |
$rules[$key]['habilitada'] = $sieve->is_enabled; |
57 |
$rules[$key]['dt_criacao'] = date('d/m/Y', strtotime($sieve->created_dt)); |
58 |
|
59 |
print_r( $rules[$key] ); |
60 |
} |
61 |
} |
62 |
|
63 |
if( isset($arguments['cmd']) && $arguments['cmd'] == 'file' ) |
64 |
{ |
65 |
$lines = "Usuario : " . $uid . PHP_EOL; |
66 |
|
67 |
foreach( $sieveRules as $key => $sieve ){ |
68 |
$lines .= "regra : " . $sieve->rule . PHP_EOL; |
69 |
$lines .= "habilitada : " . $sieve->is_enabled . PHP_EOL; |
70 |
$lines .= "dt_criacao : " . date('d/m/Y', strtotime($sieve->created_dt)) . PHP_EOL; |
71 |
$lines .= "************************************************************************" . PHP_EOL . PHP_EOL; |
72 |
} |
73 |
|
74 |
Storage::put('file/file_'.$uid.'.txt', $lines ); |
75 |
} |
76 |
|
77 |
if( isset($arguments['cmd']) && $arguments['cmd'] == 'fileSogo' ) |
78 |
{ |
79 |
print_r( storage_path('fileSogo') ); |
80 |
} |
81 |
} |
82 |
} |
83 |
|
84 |
private function getSieveRules( $user ) |
85 |
{ |
86 |
$sieveRules = DB::connection('pgsql-expresso') |
87 |
->table('phpgw_sieve_rules')
|
88 |
->where('fk_sieve_owner', $user ) |
89 |
->get(); |
90 |
|
91 |
return $sieveRules; |
92 |
} |
93 |
} |