function index() { $synced_files = Sync_model::get_uploaded_data(); // echo "<pre>";print_r($synced_files); foreach ($synced_files as $key => $value) { $id = $value['id']; $facility_code = $value['facility_code']; $zip_file = $value['file_name']; $this->insert_data($zip_file, $facility_code, $id); } }
public function sync() { $facility_code = $this->session->userdata('facility_id'); // echo $facility_code;exit; $all_tables = $this->db->list_tables(); // $fields = $this->db->field_data('dispensing_records'); // echo "<pre>";print_r($fields); $tables_to_be_ignored = array('access_level', 'assignments', 'comments', 'commodities', 'commodity_category', 'commodity_division_details', 'commodity_source', 'commodity_sub_category', 'counties', 'county_drug_store_issues', 'county_drug_store_totals', 'county_drug_store_transaction_table', 'districts', 'drug_commodity_map', 'drug_store_issues', 'drug_store_totals', 'drug_store_transaction_table', 'email_listing', 'email_listing_new', 'facilities', 'git_log', 'issue_type', 'menu', 'malaria_drugs', 'rca_county', 'recepients', 'sub_menu', 'service_points', 'log', 'log_monitor', 'db_sync', 'facility_loggins', 'facility_rollout_status', 'inventory', 'status', 'sync_updates', 'tuberculosis_data', 'commodity_source_sub_category', 'malaria_data', 'update_log'); //add tables to be ignored by database sync foreach ($tables_to_be_ignored as $key => $value) { if (($key = array_search($value, $all_tables)) !== false) { unset($all_tables[$key]); } } // echo "<pre>";print_r($all_tables); $all_tables_amped = array(); $all_tables_data = array(); foreach ($all_tables as $key => $table_name) { $timestamp_column = $this->get_column_by_type($table_name, 'timestamp'); // echo $timestamp_column."<pre>"; $all_tables_data = array($table_name, $timestamp_column); // echo "<pre>";print_r($all_tables_data); array_push($all_tables_amped, $all_tables_data); // $key['timestamp_column'] = $timestamp_column; } // echo "<pre>";print_r($all_tables); exit; // echo "<pre>";print_r($all_tables_amped);exit; // $all_tables = array_values($all_tables);//index reset $latest_sync_time = sync_model::get_latest_timestamp(); $latest_sync_time = empty($latest_sync_time) ? '' : $latest_sync_time; // echo "<pre>";print_r($latest_sync_time);exit; $final_data_from_table = array(); $table_count = count($all_tables); $data_from_table['facility_code'] = $facility_code; $ts = array(); ini_set("memory_limit", "-1"); // $timestamp_column = $this->get_column_by_type('facility_stocks','timestamp'); // echo $timestamp_column;exit; foreach ($all_tables_amped as $key => $table_data) { // $ts[$table_name] = $timestamp_column; $table_name = $table_data[0]; $timestamp_column = $table_data[1]; // echo "<pre>";print_r($timestamp_column); $pulled_data = Sync_model::get_new_data($table_name, $latest_sync_time, $timestamp_column); $data_from_table[$table_name] = json_encode($pulled_data); // echo "<pre>";print_r(json_encode($pulled_data)); } // exit; // echo "<pre>";print_r($data_from_table);exit; // echo "<pre>";print_r($ts);exit; // $write_to_file = $this->receive_data($facility_code,$data_from_table); // echo FCPATH;exit; // echo $write_to_file;exit; /* ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); */ // $stringify = print_r($data_from_table,true); // $queried_data = http_build_query($data_from_table); $data_from_table = json_encode($data_from_table); // echo "<pre>";print_r($data_from_table);exit; // echo "<pre> I reach here ";echo json_encode($data_from_table);exit; $file_write = $this->receive_data($facility_code, $data_from_table); // echo "<pre>";print_r($file_write); $sync_status = isset($file_write) && $file_write == 1 ? 1 : 0; redirect(base_url() . "synchronization/index/" . $sync_status); // $this->index($sync_status); // echo "<pre>";print_r($queried_data);exit; // $url = "41.89.6.209/hcmp_demo/synchronization/receive_data/?facility_code=".$facility_code.'?data='.$queried_data; // $local_url = base_url().'synchronization/receive_post'; // $result = $this->post_data($local_url,$data_from_table); // echo $result;exit; // // echo $url;exit; // $ch = curl_init($url); // $status = curl_exec($ch); // echo "<pre>";print_r($status);exit; // var_dump($data_from_table); }
public function sync() { $facility_code = $this->session->userdata('facility_id'); //echo $facility_code;exit; $all_tables = $this->db->list_tables(); // $fields = $this->db->field_data('dispensing_records'); // echo "<pre>";print_r($fields); // $tables_to_be_ignored = array('commodities','commodity_division_details','facilities');//add tables to be ignored by database sync /*foreach ($tables_to_be_ignored as $key => $value) { if(($key = array_search($value, $all_tables)) !== false) { unset($all_tables[$key]); } }*/ // echo "<pre>";print_r($all_tables); $all_tables_amped = array(); $all_tables_data = array(); foreach ($all_tables as $key => $table_name) { $timestamp_column = $this->get_column_by_type($table_name, 'timestamp'); // echo $key."<pre>"; $all_tables_data = array($table_name, $timestamp_column); array_push($all_tables_amped, $all_tables_data); // $key['timestamp_column'] = $timestamp_column; } // echo "<pre>";print_r($all_tables); exit; // echo "<pre>";print_r($all_tables_amped);exit; // $all_tables = array_values($all_tables);//index reset $latest_sync_time = sync_model::get_latest_timestamp(); $latest_sync_time = empty($latest_sync_time) ? '' : $latest_sync_time; // echo "<pre>";print_r($latest_sync_time);exit; $final_data_from_table = array(); $table_count = count($all_tables); $data_from_table['facility_code'] = $facility_code; $ts = array(); ini_set("memory_limit", "1000M"); // $timestamp_column = $this->get_column_by_type('facility_stocks','timestamp'); // echo $timestamp_column;exit; foreach ($all_tables_amped as $key => $table_data) { // $ts[$table_name] = $timestamp_column; $table_name = $table_data[0]; $timestamp_column = $table_data[1]; // echo "<pre>";print_r($timestamp_column); $data_from_table[$table_name] = Sync_model::get_new_data($table_name, $latest_sync_time, $timestamp_column); // echo "<pre>";print_r($data_from_table); } // echo "<pre>";print_r($data_from_table);exit; // echo "<pre>";print_r($ts);exit; // $write_to_file = $this->receive_data($facility_code,$data_from_table); // echo FCPATH;exit; // echo $write_to_file;exit; /*ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); */ $stringify = print_r($data_from_table, true); $queried_data = http_build_query($data_from_table); $file_write = $this->receive_data($facility_code, $data_from_table); // echo "<pre>";print_r($file_write); $sync_status = isset($file_write) && $file_write == 1 ? 1 : 0; redirect(base_url() . "synchronization/index/" . $sync_status); // $this->index($sync_status); // echo "<pre>";print_r($queried_data);exit; // $url = "41.89.6.209/hcmp_demo/synchronization/receive_data/?facility_code=".$facility_code.'?data='.$queried_data; // $local_url = base_url().'synchronization/receive_post'; // $result = $this->post_data($local_url,$data_from_table); // echo $result;exit; // // echo $url;exit; // $ch = curl_init($url); // $status = curl_exec($ch); // echo "<pre>";print_r($status);exit; // var_dump($data_from_table); }