library/Garp/Cli/Command/Admin.php
public function make(array $args = array()) {
        $userModel = new Model_User();
        if (!empty($args)) {
            $id = $args[0];
        } else {
            $id = Garp_Cli::prompt('What is the id or email address of the user?');
        }
        $select = $userModel->select();
        if (is_numeric($id)) {
            $filterColumn = 'id';
        } else {
            $filterColumn = 'email';
        }
        $select->where($filterColumn . ' = ?', $id);
        $user = $userModel->fetchRow($select);
        if (!$user) {
            Garp_Cli::errorOut('Error: could not find user with ' . $filterColumn . ' ' . $id);
        } else {
            $user->role = 'admin';
            if ($user->save()) {
                // For completeness sake, check if the user has an AuthLocal
                // record. We disregard the fact wether the user already has any
                // of the other Auth- records.
                $authLocalModel = new Model_AuthLocal();
                $authLocalRecord = $authLocalModel->fetchRow(
                    $authLocalModel->select()->where('user_id = ?', $user->id)
                );
                if (!$authLocalRecord) {
                    $newAuthLocalData = array(
                        'password' => trim(Garp_Cli::prompt('Choose a password:')),
                        'user_id'  => $user->id
                    );
                    $authLocalModel->insert($newAuthLocalData);
                }
                Garp_Cli::lineOut(
                    'User with ' . $filterColumn . ' ' . $id .
                    ' is now administrator'
                );
            } else {
                Garp_Cli::errorOut(
                    'Error: could not make user with ' . $filterColumn . ' ' . $id .
                    ' administrator'
                );
            }
        }
    }
public function make(array $args = array()) {
        $userModel = new Model_User();
        if (!empty($args)) {
            $id = $args[0];
        } else {
            $id = Garp_Cli::prompt('What is the id or email address of the user?');
        }
        $select = $userModel->select();
        if (is_numeric($id)) {
            $filterColumn = 'id';
        } else {
            $filterColumn = 'email';
        }
        $select->where($filterColumn . ' = ?', $id);
        $user = $userModel->fetchRow($select);
        if (!$user) {
            Garp_Cli::errorOut('Error: could not find user with ' . $filterColumn . ' ' . $id);
        } else {
            $user->role = 'admin';
            if ($user->save()) {
                // For completeness sake, check if the user has an AuthLocal
                // record. We disregard the fact wether the user already has any
                // of the other Auth- records.
                $authLocalModel = new Model_AuthLocal();
                $authLocalRecord = $authLocalModel->fetchRow(
                    $authLocalModel->select()->where('user_id = ?', $user->id)
                );
                if (!$authLocalRecord) {
                    $newAuthLocalData = array(
                        'password' => trim(Garp_Cli::prompt('Choose a password:')),
                        'user_id'  => $user->id
                    );
                    $authLocalModel->insert($newAuthLocalData);
                }
                Garp_Cli::lineOut(
                    'User with ' . $filterColumn . ' ' . $id .
                    ' is now administrator'
                );
            } else {
                Garp_Cli::errorOut(
                    'Error: could not make user with ' . $filterColumn . ' ' . $id .
                    ' administrator'
                );
            }
        }
    }
public function make ( array $ args = array ( ) ) { $ userModel = new Model_User ( ) ; if ( ! empty ( $ args ) ) { $ id = $ args [ 0 ] ; } else { $ id = Garp_Cli :: prompt ( 'What is the id or email address of the user?' ) ; } $ select = $ userModel -> select ( ) ; if ( is_numeric ( $ id ) ) { $ filterColumn = 'id' ; } else { $ filterColumn = 'email' ; } $ select -> where ( $ filterColumn . ' = ?' , $ id ) ; $ user = $ userModel -> fetchRow ( $ select ) ; if ( ! $ user ) { Garp_Cli :: errorOut ( 'Error: could not find user with ' . $ filterColumn . ' ' . $ id ) ; } else { $ user -> role = 'admin' ; if ( $ user -> save ( ) ) { // For completeness sake, check if the user has an AuthLocal // record. We disregard the fact wether the user already has any // of the other Auth- records. $ authLocalModel = new Model_AuthLocal ( ) ; $ authLocalRecord = $ authLocalModel -> fetchRow ( $ authLocalModel -> select ( ) -> where ( 'user_id = ?' , $ user -> id ) ) ; if ( ! $ authLocalRecord ) { $ newAuthLocalData = array ( 'password' => trim ( Garp_Cli :: prompt ( 'Choose a password:' ) ) , 'user_id' => $ user -> id ) ; $ authLocalModel -> insert ( $ newAuthLocalData ) ; } Garp_Cli :: lineOut ( 'User with ' . $ filterColumn . ' ' . $ id . ' is now administrator' ) ; } else { Garp_Cli :: errorOut ( 'Error: could not make user with ' . $ filterColumn . ' ' . $ id . ' administrator' ) ; } } }
Make an existing user admin

@param array $args
@return void
Make an existing user admin