Projeto

Geral

Perfil

Revisão ab2f5151 app/Console/Commands/Expresso/GetUsersOULdap.php

Ver diferenças:

app/Console/Commands/Expresso/GetUsersOULdap.php
4 4

  
5 5
use App\Commons\Ldap;
6 6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\DB;
8
use Storage;
7
use Illuminate\Support\Facades\File;
9 8

  
10 9
class GetUsersOULdap extends Command
11 10
{
......
14 13
     *
15 14
     * @var string
16 15
     */
17
    protected $signature = 'expresso:get-users-organizations {--ou=} {cmd?}';
16
    protected $signature = 'expresso:get-organization-users {--ou=} {cmd?}';
18 17

  
19 18
    /**
20 19
     * The console command description.
21 20
     *
22 21
     * @var string
23 22
     */
24
    protected $description = 'Lista os usuarios de uma organização ( OU )';
23
    protected $description = 'lista os usuários de uma organizacao ldap ( OU )';
25 24

  
26 25
    /**
27 26
     * Create a new command instance.
......
44 43

  
45 44
        $organization = $this->option('ou') ?? null;
46 45

  
47
        if( isset($arguments['cmd']) && $arguments['cmd'] == 'help' )
48
        {
49
            $this->help();
50

  
51
        } else {
52

  
53
            if( !is_null($organization) ){
54

  
55
                $users      = $this->getUsersOu($organization);
56
                $fileName   = $arguments['cmd'] ?? null;
57

  
58
                if( is_null($fileName) ) {
59
                    foreach( $users as $user )
60
                    {
61
                        $line  = "" ;
62
                        $line .= "cn        : " . ( $user['cn'][0] ?? "" ) . PHP_EOL;
63
                        $line .= "uid       : " . ( $user['uid'][0] ?? "" ) . PHP_EOL ;
64
                        $line .= "uidnumber : " . ( $user['uidnumber'][0] ?? "" ) . PHP_EOL ;
65
                        $line .= "----------------------------------------------------------------------------" . PHP_EOL;
66
                        
67
                        print_r( $line );
68
                    }
69
                }else {
70
                    $this->writeFile( $users, $fileName );
46
        if( !is_null($organization) ){
47

  
48
            $users      = $this->getUsersOu($organization);
49
            $fileName   = $arguments['cmd'] ?? null;
50

  
51
            if( is_null($fileName) ) {
52
                foreach( $users as $user )
53
                {
54
                    $line  = "" ;
55
                    $line .= "cn        : " . ( $user['cn'][0] ?? "" ) . PHP_EOL;
56
                    $line .= "uid       : " . ( $user['uid'][0] ?? "" ) . PHP_EOL ;
57
                    $line .= "uidnumber : " . ( $user['uidnumber'][0] ?? "" ) . PHP_EOL ;
58
                    $line .= "----------------------------------------------------------------------------" . PHP_EOL;
59
                    
60
                    print_r( $line );
71 61
                }
72

  
62
            }else {
63
                $this->writeFile( $users, $fileName );
73 64
            }
74
        }
75 65

  
76
        $this->newLine();
66
        }
67
        
77 68
    }
78 69

  
79 70
    private function getUsersOu( $organization )
......
83 74
        return $result->getUsersOu( $organization );
84 75
    }
85 76

  
86
    private function help()
87
    {
88
        $this->newLine();
89
        $this->info('EXEMPLO DE UTILIZACAO : ');
90
        $this->info('Ex: php artisan get-users-organizations --ou=<ORGANIZATION> { print | file }');
91
        $this->newLine();
92
    }
93

  
94 77
    private function writeFile( array $users, string $fileName )
95 78
    {
96
        $this->newLine();
97
        
98 79
        if( is_array($users) && count($users) > 0 ){
99 80
         
100 81
            $line  = "";
......
104 85
                $line .= ( $user['uid'][0] ?? "" ) . ";" ;
105 86
                $line .= ( $user['uidnumber'][0] ?? "" ) . PHP_EOL ;
106 87

  
107
                Storage::put('/EXPRESSO/'.$fileName, $line );
88
                File::put( $fileName , $line );
108 89
            }
109 90
        }
110 91

  
111
        $this->info('Arquivo gerado com sucesso : /EXPRESSO/'. $fileName );
92
        $this->info('Arquivo gerado com sucesso : ' . $fileName );
112 93
    }
113 94
}

Exportar para Unified diff