Skip to content

Commit a435f03

Browse files
author
matt
committed
Make same as live
1 parent 680174e commit a435f03

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

Http/Controllers/UnSubController.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ function ($x) {
118118

119119
if ((isset($opts["https"]) || isset($opts["http"]))) {
120120

121-
try {
122121
$client = new Client(['request.options' => ['exceptions' => false,]]);
123122

124123
$url = isset($opts["https"]) ? 'https:' . $opts["https"] : 'http:' . $opts["http"];
125124
$response = null;
126125

127-
if ("List-Unsubscribe=One-Click" === $unsubPost) {
126+
try {
127+
if ($unsubPost) {
128128
$response = $client->request(
129129
'POST',
130130
$url,
@@ -136,13 +136,16 @@ function ($x) {
136136
$response = $client->request('GET', $url);
137137
}
138138

139+
$code = $response->getStatusCode();
140+
139141

140142
$body = $response->getBody();
141143

142144
$conversation->setMeta("List-Unsubscribe-Submitted", ["status" => $response->getStatusCode(), "reason" => $response->getReasonPhrase()]);
143145

144146
$auth_user = auth()->user();
145-
$created_by_user_id = $auth_user->id;
147+
error_log($auth_user);
148+
$created_by_user_id = (gettype($auth_user) == "object") ? $auth_user->id : $auth_user ;
146149
\App\Thread::create(
147150
$conversation, Thread::TYPE_LINEITEM,
148151
'',
@@ -154,15 +157,20 @@ function ($x) {
154157
'source_type' => \App\Thread::SOURCE_TYPE_WEB,
155158
'body' => $body,
156159
'meta' => [
157-
'code' => $response->getStatusCode(),
160+
'code' => $code,
158161
'message' => $response->getReasonPhrase()
159162
]
160163
]
161164
);
165+
166+
if ($code>=200 && $code <=299) {
167+
$conversation->changeStatus(Conversation::STATUS_CLOSED,$auth_user, false);
168+
}
169+
162170
} catch (ConnectException $e) {
163171

164172
$auth_user = auth()->user();
165-
$created_by_user_id = $auth_user->id;
173+
$created_by_user_id = (gettype($auth_user) == "object") ? $auth_user->id : $auth_user ;
166174
\App\Thread::create(
167175
$conversation, Thread::TYPE_LINEITEM,
168176
'',
@@ -172,17 +180,22 @@ function ($x) {
172180
'action_type' => self::ACTION_TYPE_UNSUBSCRIBE,
173181
'source_via' => \App\Thread::PERSON_USER,
174182
'source_type' => \App\Thread::SOURCE_TYPE_WEB,
175-
'body' => "Something went wrong",
183+
'body' => "Something went wrong. ".print_r([ 'url' => $url, 'opts' => $opts, ]),
176184
'meta' => [
177185
'code' => 501,
178-
'message' => "Sorry, something went wrong: " . $e->getMessage()
186+
'message' => "Sorry, something went wrong: " . $e->getMessage(),
187+
'lineNumber' => $e->getLine(),
188+
'trace'=>$e->getTraceAsString(),
189+
'method' => ($unsubPost) ? 'POST' : "GET",
190+
'url' => $url,
191+
'opts' => $opts,
179192
]
180193
]
181194
);
182195
} catch (\Exception $e) {
183196

184197
$auth_user = auth()->user();
185-
$created_by_user_id = $auth_user->id;
198+
$created_by_user_id = (gettype($auth_user) == "object") ? $auth_user->id : $auth_user ;
186199
\App\Thread::create(
187200
$conversation, Thread::TYPE_LINEITEM,
188201
'',
@@ -195,7 +208,13 @@ function ($x) {
195208
'body' => "Something went wrong",
196209
'meta' => [
197210
'code' => 501,
198-
'message' => "Sorry, something went wrong: " . $e->getMessage()
211+
'message' => "Sorry, something went wrong: " . $e->getMessage(),
212+
'lineNumber' => $e->getLine(),
213+
'trace'=>$e->getTraceAsString(),
214+
'method' => ($unsubPost) ? 'POST' : "GET",
215+
'user' => json_encode($auth_user),
216+
'url' => $url,
217+
'opts' => $opts,
199218
]
200219
]
201220
);
@@ -326,4 +345,4 @@ function ($carry, $key) {
326345
return $headers ?? [];
327346
}
328347

329-
}
348+
}

0 commit comments

Comments
 (0)