96 lines
3.4 KiB
PHP
96 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
class WrenchUserContacts extends BaseController
|
|
{
|
|
|
|
/*
|
|
CREATE TABLE members_contacts_import (
|
|
id SERIAL,
|
|
uid uuid DEFAULT uuid_generate_v4(),
|
|
member_id INT REFERENCES members(id) NOT NULL,
|
|
member_uid VARCHAR(150) NOT NULL,
|
|
raw_contacts TEXT,
|
|
status INT DEFAULT 0,
|
|
added timestamp without time zone DEFAULT now(),
|
|
updated timestamp without time zone DEFAULT now()
|
|
);
|
|
ALTER TABLE ONLY members_contacts_import
|
|
ADD CONSTRAINT members_contacts_import_id_key UNIQUE (id);
|
|
|
|
* this.usrData = {action:22010,
|
|
member_id: this.sessionDataProviderService.member_id,
|
|
uid: this.sessionDataProviderService.member_uid,
|
|
sessionid: this.sessionDataProviderService.session ,
|
|
raw_contacts: contactResult }
|
|
*/
|
|
public function usersContacts(){
|
|
log_message('critical', "*********** WrenchUserContacts::usersContacts() 0000 ");
|
|
$raw_json = file_get_contents('php://input');
|
|
$in = json_decode($raw_json, true);
|
|
$out =[];
|
|
// log_message('critical', "*********** WrenchUserContacts::usersContacts() 0001 ".serialize($in));
|
|
$in["action"] = WRENCHBOARD_ACCOUNT_CONTACTIMPORT;
|
|
|
|
if (isset($in["uid"]) && $in["uid"] !='' ){
|
|
$in["member_uid"]=$in["uid"];
|
|
}
|
|
$time_to_save = false;
|
|
$endpoint = "CONTACTS_IMPORT_ACTION-". $in["uid"];
|
|
$outC = $this->getCache($endpoint); // try find in cache
|
|
if ( $in["mmode"] == 0 ){
|
|
$this->deleteCache($endpoint);
|
|
$this->saveCache($endpoint,$in,1300);
|
|
}
|
|
else
|
|
{
|
|
$outC = $this->getCache($endpoint); // try find in cache
|
|
log_message('critical', "CACHE READ ***** WrenchUserContacts::usersContacts() ----**> ".$outC["raw_contacts"]);
|
|
$in["raw_contacts"] = $in["raw_contacts"].$outC["raw_contacts"];
|
|
$this->deleteCache($endpoint);
|
|
$this->saveCache($endpoint,$in,5300);
|
|
/*
|
|
Determine if this is the last
|
|
Fire process events
|
|
save to the backend database;
|
|
*/
|
|
if ($in["csize"] >= $in["pcount"]){
|
|
$time_to_save = true;
|
|
}
|
|
}
|
|
|
|
///=== cache game gere
|
|
|
|
if($time_to_save){
|
|
$in["raw_contacts"] = serialize($in['raw_contacts']);
|
|
$ret = $this->wrenchboard->wrenchboard_api($in, $out);
|
|
$out['internal_return'] = $ret;
|
|
}
|
|
else{
|
|
$out["status_msg"] = "Received and cached";
|
|
}
|
|
// log_message('critical', "*********** WrenchUserContacts::usersContacts() 0001 ".serialize($out) );
|
|
return $this->summaryReturnData($in,$out); //json_encode( $final_out );
|
|
}
|
|
|
|
private function processContacts( $in ){
|
|
log_message('critical', "************************ cachecontacts 0001 ".serialize($in));
|
|
|
|
$inx =[];
|
|
$inx["member_id"] = $in["member_id"];
|
|
$inx["uid"] = $in["uid"];
|
|
$inx["sessionid"] = $in["sessionid"];
|
|
$raw_contacts = $in["raw_contacts"];
|
|
|
|
foreach ( $raw_contacts["contacts"] as $rows){
|
|
$firstname = $rows["name"]["given"];
|
|
$lastname = $rows["name"]["family"];
|
|
$contactid = $rows["contactId"];
|
|
log_message('critical', "************************ $firstname $lastname $contactid");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |