登录
首页 >  数据库 >  MySQL

最优方案实现同步数据至HUBSPOT

来源:SegmentFault

时间:2023-01-17 08:42:32 134浏览 收藏

对于一个数据库开发者来说,牢固扎实的基础是十分重要的,golang学习网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《最优方案实现同步数据至HUBSPOT》,主要介绍了MySQL、PHP,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!

需求

需要把数据库中所有符合条件的

## edit updateUserCIM trigger(update user CIM info trigger)
DELIMITER ;;
create trigger updateUserCIM
             after UPDATE on user_cim_details
             for each row
BEGIN
  update hubspot_data SET is_need_update = 1 where user_id = NEW.user_id;
END;;
DELIMITER ;

## create insert_hubspot trigger( insert user trigger)
DROP TRIGGER insert_hubspot;
DELIMITER ;;
create trigger insert_hubspot
             after INSERT on users
             for each row
BEGIN
  REPLACE into hubspot_data(user_id, email,is_need_update) VALUE (NEW.id,NEW.email,1);
END;;
DELIMITER ;

## edit UserStatusUpdateDate trigger(update user's status trigger)
DELIMITER ;;
create trigger UserStatusUpdateDate
     before UPDATE on users
     for each row
IF NOT(NEW.user_status  OLD.user_status) THEN
update hubspot_data
    set is_need_update = CASE
    when new.user_status in ('C','G') then 2 else 1
    end
where user_id = old.id;
END IF;;
DELIMITER ;

结尾

结尾没啥好说的啦,此文不是讲如何对接、调用

/**
 * Create a group of contacts or update them if they already exist.
 *
 * eg:
 * array(
 * array('email'=>'testBatch5@qq.com','param'=>array('firstname'=>'JasonT5','lastname'=>'Zhang5','phone'=>'555-122-2325','ispaid'=>'No')),
 * array('email'=>'testBatch6@qq.com','param'=>array('firstname'=>'JasonT6','lastname'=>'Zhang6','phone'=>'555-122-2326','ispaid'=>'No')),
 * array('email'=>'testBatch7@qq.com','param'=>array('firstname'=>'JasonT7','lastname'=>'Zhang7','phone'=>'555-122-2327','ispaid'=>'No')),
 * array('email'=>'testBatch8@qq.com','param'=>array('firstname'=>'JasonT8','lastname'=>'Zhang8','phone'=>'555-122-2328','ispaid'=>'No')),
 * )
 *
 * @param params: array of properties and property values for new contact, email is required
 *
 * @return Response body with JSON object
 * for created Contact from HTTP POST request
 *
 * @throws HubSpotException
 **/
public function batch_create_or_update($params){
    $endpoint = 'contact/batch/';
    $properties = array();
    foreach ($params as $k => $param) {
        $propertie = array();
        foreach ($param['param'] as $key => $value){
            array_push($propertie, array("property"=>$key,"value"=>$value));
        }
        $properties[$k]['properties'] = $propertie;
        if(!empty($param['vid'])){
            $properties[$k]['vid'] = $param['vid'];
        }elseif (!empty($param['email'])){
            $properties[$k]['email'] = $param['email'];
        }else
            continue;
    }
    $properties = json_encode($properties);
    try{
        return json_decode($this->execute_JSON_post_request($this->get_request_url($endpoint,null),$properties));
    } catch (HubSpotException $e) {
        throw new HubSpotException('Unable to create contact: ' . $e);
    }
}

如果开发过程中遇到任何问题,可以到 hubspot开发者社区寻求帮助,支持github账号登录哦~

本篇关于《最优方案实现同步数据至HUBSPOT》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于数据库的相关知识,请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表