Subversion Repositories SmartDukaan

Rev

Rev 18594 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
class UserpusherShell extends AppShell {
    public $uses = array('User');

    public function main() {
                Configure::load('live');
                $options = array('conditions'=>array('activated'=>1),'recursive'=>-1);
                $users = $this->User->find('all',$options);
                $pmaurl = Configure::read('pmaurl');
                if(!empty($users)) {
                        foreach($users AS $user) {
                                $data = array('id'=>$user['User']['id'],'email'=>$user['User']['email'],'mobilenumber'=>$user['User']['mobile_number'],'name'=>$user['User']['first_name'],'referral_code'=>$user['User']['referrer']);
                                $this->make_request($pmaurl.'/identify',$data); 
                        }
                }
    }

    private function make_request($url,$fields,$format='json'){
                //$this->out("[url] $url");
                //$this->out("[fields] ".print_r($fields,1));
                //$this->log("[url] $url",'api');
                //$this->log("[fields] ".print_r($fields,1),'api');
                $fields_string = '';
                //open connection
                $ch = curl_init();
                //execute post
                foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
                rtrim($fields_string, '&');
                //set the url, number of POST vars, POST data
                curl_setopt($ch,CURLOPT_URL, $url);
                curl_setopt($ch,CURLOPT_POST, count($fields));
                curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
                $result = curl_exec($ch);
                $this->out("[response] ".print_r($result,1));
                //close connection
                curl_close($ch);
                switch($format){
                        case 'json':
                        $response = json_decode($result,1);
                        break;
                }
                return $response;       
        }
}