source: pro-violet-viettel/sourcecode/application/modules/services/controllers/sync.php @ 742

Last change on this file since 742 was 721, checked in by namnd, 10 years ago
File size: 4.5 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class Sync extends MX_Controller
4{
5        public function __construct()
6        {
7                parent::__construct();
8        }
9       
10        public function collaborator ()
11        {
12                if($this->input->is_cli_request()){
13                        error_reporting(E_ALL);
14                        $this->load->model('Services_model');
15                        $totalpage = 1;
16                       
17                        $default = $this->Services_model->getCollaborator(2,1,5000);
18                        $data = mb_convert_encoding($default, 'UTF-8', 'ISO-8859-1');
19                        if($data){
20                                $xml = simplexml_load_string($data);
21                                $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
22                                $xml = $xml->xpath('//S:Body');
23                                $xml = $xml[0];
24                                $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
25                                $totalpage = $xml->xpath('//return//totalpage');
26                                $totalpage = (int)$totalpage[0];
27                        }
28                       
29                        for ($i=1; $i<=$totalpage; $i++){
30                                $result = $this->Services_model->getCollaborator(2,$i,500);
31                                $data = mb_convert_encoding($result, 'UTF-8', 'ISO-8859-1');
32                                if($data && $data != -1){
33                                        $xml = simplexml_load_string($data);
34                                        $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
35                                        $xml = $xml->xpath('//S:Body');
36                                        $xml = $xml[0];
37                                        $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
38                                        $lst = $xml->xpath('//return//lst');
39                                        foreach($lst as $item){
40                                                $item = (array)$item;
41                               
42                                                $data = array(
43                                                                'address'=> (string)$item['address'],
44                                                                'code'=>(string)$item['code'],
45                                                                'district'=>(string)$item['district'],
46                                                                'email'=>(string)$item['email'],
47                                                                'id'=>(int)$item['id'],
48                                                                'full_name'=>(string)$item['name'],
49                                                                'cellphone'=>(string)$item['phone'],
50                                                                'precinct'=>(string)$item['precinct'],
51                                                                'province'=>(string)$item['province'],
52                                                                'created_time'=>date('Y-m-d H:i:s'),
53                                                                'updated_time'=>date('Y-m-d H:i:s')
54                                                        );
55                                                write_file('./log/sync_collaborator.log', var_export($data, TRUE), FOPEN_WRITE_CREATE);
56                                                if ((string)$item['phone']){
57                                                        $this->Services_model->syncCollaborator($data);
58                                                }
59                                        }
60                                }else{
61                                        $logMsg = date('Y-m-d H:i:s') . " Result is null \n";
62                                        write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
63                                }
64                        }
65                }else{
66                        show_404();
67                }
68        }
69       
70        public function deleteCollaborator ()
71        {
72               
73                if($this->input->is_cli_request()){
74                        error_reporting(E_ALL);
75                        $this->load->model('Services_model');
76                        $totalpage = 1;
77       
78                        $default = $this->Services_model->getCollaborator(2,1,5000);
79                        $data = mb_convert_encoding($default, 'UTF-8', 'ISO-8859-1');
80                        if($data){
81                                $xml = simplexml_load_string($data);
82                                $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");         
83                                $xml = $xml->xpath('//S:Body');
84                                $xml = $xml[0];
85                                $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");       
86                                $totalpage = $xml->xpath('//return//totalpage');
87                                $totalpage = (int)$totalpage[0];
88                        }
89
90                        $collaboratorIds = array();
91                       
92                        $logMsg = "Start XML Process: " . date('Y-m-d H:i:s') . "\n";
93                        write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
94                       
95                        for ($i=1; $i<$totalpage; $i++){
96                                $result = $this->Services_model->getCollaborator(2,$i,5000);
97                                $data = mb_convert_encoding($result, 'UTF-8', 'ISO-8859-1');
98                                if($data && $data != -1){
99                                        $xml = simplexml_load_string($data);
100                                        $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
101                                        $xml = $xml->xpath('//S:Body');
102                                        $xml = $xml[0];
103                                        $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
104                                        $lst = $xml->xpath('//return//lst');
105                                        foreach($lst as $item){
106                                                $item = (array)$item;
107                                                if ((string)$item['phone']){
108                                                        array_push($collaboratorIds, (int)$item['id']);
109                                                }
110                                        }
111                                }else{
112                                        $logMsg = date('Y-m-d H:i:s') . " Result is null \n";
113                                        write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
114                                }
115                        }
116                       
117                        $logMsg = "Finish XML Process: " . date('Y-m-d H:i:s') . "\n";
118                        write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
119                       
120                        $collaboratorIdsSync = $this->Services_model->getAllCollaboratorID();
121                       
122                        if ($collaboratorIdsSync){
123                                foreach($collaboratorIdsSync as $collaborator){
124                                        $id = (int)$collaborator->id;
125                                        if (in_array($id, $collaboratorIds) == false){
126                                                $this->Services_model->deleteCollaborator($id);
127                                        }
128                                }
129                        }
130                }else{
131                        show_404();
132                }
133
134        }
135}
Note: See TracBrowser for help on using the repository browser.