From 2de0e35645a748bf792dafb7d041827da2c198ab Mon Sep 17 00:00:00 2001 From: btruong Date: Wed, 21 Sep 2016 19:50:24 -0700 Subject: [PATCH] Since our CMS Drupal does occsioanlly assign the value zero to userID, we need to allow segment calls to still validate when the userId is zero, so instead using not empty, using isset would allow the call to validate if the userId value happens to be zero --- lib/Segment.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Segment.php b/lib/Segment.php index 482b872..f90e4bb 100644 --- a/lib/Segment.php +++ b/lib/Segment.php @@ -57,7 +57,7 @@ public static function identify(array $message) { public static function group(array $message) { self::checkClient(); $groupId = !empty($message["groupId"]); - $userId = !empty($message["userId"]); + $userId = !(array_key_exists('userID', $message) && strlen((string) $message['userID']) > 0); self::assert($groupId && $userId, "Segment::group() expects userId and groupId"); return self::$client->group($message); } @@ -94,8 +94,8 @@ public static function screen(array $message) { */ public static function alias(array $message) { self::checkClient(); - $userId = !empty($message["userId"]); - $previousId = !empty($message["previousId"]); + $userId = !(array_key_exists('userID', $message) && strlen((string) $message['userID']) > 0); + $previousId = !(array_key_exists('previousId', $message) && strlen((string) $message['previousId']) > 0); self::assert($userId && $previousId, "Segment::alias() requires both userId and previousId"); return self::$client->alias($message); } @@ -107,7 +107,7 @@ public static function alias(array $message) { * @param string $type */ public static function validate($msg, $type){ - $userId = !empty($msg["userId"]); + $userId = !(array_key_exists('userID', $msg) && strlen((string) $msg['userID']) > 0); $anonId = !empty($msg["anonymousId"]); self::assert($userId || $anonId, "Segment::$type() requires userId or anonymousId"); }