| 14681 |
anikendra |
1 |
<?php
|
|
|
2 |
class SaholiccheckerShell extends AppShell {
|
|
|
3 |
public $uses = array('User','UserAccount');
|
|
|
4 |
|
|
|
5 |
public function main() {
|
| 14685 |
anikendra |
6 |
Configure::load('live');
|
|
|
7 |
$conditions = array('UserAccount.account_key' => -1);
|
|
|
8 |
$userAccounts = $this->UserAccount->find('all',array('conditions' => $conditions,'recursive'=>-1));
|
|
|
9 |
if(!empty($userAccounts)) {
|
|
|
10 |
foreach($userAccounts AS $account) {
|
|
|
11 |
$sql = "DELETE FROM user_accounts WHERE user_id =".$account['UserAccount']['user_id'];
|
|
|
12 |
$this->out($sql);
|
|
|
13 |
$this->UserAccount->query($sql);
|
|
|
14 |
}
|
|
|
15 |
}
|
| 14681 |
anikendra |
16 |
$apihost = Configure::read('saholicapihost');
|
|
|
17 |
$users = $this->User->find('all',array('fields'=>array('id','email'),'recursive'=>-1));
|
| 14685 |
anikendra |
18 |
foreach ($users as $key => $user) {
|
| 14681 |
anikendra |
19 |
$userId = $user['User']['id'];
|
|
|
20 |
$email = $user['User']['email'];
|
|
|
21 |
$options = array('conditions'=>array('user_id' => $userId,'account_type' => 'saholic'),'recursive'=>-1);
|
|
|
22 |
$exists = $this->UserAccount->find('count',$options);
|
|
|
23 |
if(!$exists){
|
| 14685 |
anikendra |
24 |
$url = $apihost."register?email=$email&from=profitmandi";
|
| 14681 |
anikendra |
25 |
$response = $this->make_request($url,null);
|
| 14685 |
anikendra |
26 |
$this->out('response '.print_r($response,1));
|
| 14681 |
anikendra |
27 |
if(!empty($response)) {
|
| 14685 |
anikendra |
28 |
if($response['userId']<1)return;
|
| 14681 |
anikendra |
29 |
$data = array('account_type'=>'saholic','user_id'=>$userId,'account_key'=>$response['userId']);
|
|
|
30 |
$this->UserAccount->create();
|
|
|
31 |
$this->UserAccount->save($data);
|
|
|
32 |
$data = array('account_type'=>'cartId','user_id'=>$userId,'account_key'=>$response['cartId']);
|
|
|
33 |
$this->UserAccount->create();
|
|
|
34 |
$this->UserAccount->save($data);
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
}
|
| 14685 |
anikendra |
39 |
|
|
|
40 |
function make_request($url,$fields,$format='json'){
|
|
|
41 |
$this->out("[url] $url");
|
|
|
42 |
$this->out("[fields] ".print_r($fields,1));
|
|
|
43 |
$fields_string = '';
|
|
|
44 |
//open connection
|
|
|
45 |
$ch = curl_init();
|
|
|
46 |
//set the url, number of POST vars, POST data
|
|
|
47 |
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
48 |
curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
|
|
|
49 |
if(!empty($fields)) {
|
|
|
50 |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
|
|
|
51 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
52 |
'Content-Type: application/json',
|
|
|
53 |
// 'Content-Length: ' . sizeof($fields))
|
|
|
54 |
'Content-Length: ' . strlen($fields))
|
|
|
55 |
);
|
|
|
56 |
}
|
|
|
57 |
//execute post
|
|
|
58 |
$result = curl_exec($ch);
|
|
|
59 |
$this->log("[response] ".print_r($result,1),'api');
|
|
|
60 |
//close connection
|
|
|
61 |
curl_close($ch);
|
|
|
62 |
switch($format){
|
|
|
63 |
case 'json':
|
|
|
64 |
$response = json_decode($result,1);
|
|
|
65 |
break;
|
|
|
66 |
}
|
|
|
67 |
return $response;
|
|
|
68 |
}
|
| 14681 |
anikendra |
69 |
}
|