| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | use BitCode\BitForm\Core\Database\FormEntryModel; |
| 11 | 11 | use BitCode\BitForm\Core\Database\FormModel; |
| 12 | 12 | use BitCode\BitForm\Core\Util\ApiResponse; |
| 13 | +use BitCode\BitForm\Core\Util\IpTool; | |
| 13 | 14 | use BitCode\BitForm\Core\Util\Log; |
| 14 | 15 | use BitCode\BitForm\Core\Util\SmartTags; |
| 15 | 16 | use BitCode\BitForm\Core\Util\Utilities; |
| 16 | 17 | /** |
| @@ -194,13 +195,17 @@ | ||
| 194 | 195 | if (!is_string($integrationIDStr)) { |
| 195 | 196 | return; |
| 196 | 197 | } |
| 197 | 198 | $currentFieldValues = $baseFieldValues; |
| 198 | - $integrationID = intval(json_decode($integrationIDStr)->id, 10); | |
| 199 | + $integrationID = intval(Utilities::jsonObj($integrationIDStr)->id ?? 0, 10); | |
| 199 | 200 | if (!empty($integrationID) && is_int($integrationID)) { |
| 200 | 201 | $integrationResult |
| 201 | 202 | = $integrationHandler->getAIntegration($integrationID); |
| 202 | 203 | $integrationDetails = is_wp_error($integrationResult) ? null : $integrationResult[0]; |
| 204 | + // Honor enable/disable: a disabled integration is never executed. | |
| 205 | + if (!is_null($integrationDetails) && isset($integrationDetails->status) && empty($integrationDetails->status)) { | |
| 206 | + continue; | |
| 207 | + } | |
| 203 | 208 | $integrationName = is_null($integrationDetails) ? null : ucfirst(str_replace(' ', '', $integrationDetails->integration_type)); |
| 204 | 209 | if ('Brevo(SendinBlue)' === $integrationName) { |
| 205 | 210 | $integrationName = 'SendinBlue'; |
| 206 | 211 | } |
| @@ -214,9 +219,27 @@ | ||
| 214 | 219 | if (isset($integDetails->field_map)) { |
| 215 | 220 | $sptagData = self::specialTagFields($integDetails->field_map); |
| 216 | 221 | $currentFieldValues = $currentFieldValues + $sptagData; |
| 217 | 222 | } |
| 218 | - $handler->execute($integrationHandler, $integrationDetails, $currentFieldValues, $entryID, $logID); | |
| 223 | + // fresh time budget per handler: a chain of slow integrations (30s HTTP | |
| 224 | + // timeout each) must not be killed by max_execution_time mid-loop | |
| 225 | + if (\function_exists('set_time_limit') && false === strpos((string) ini_get('disable_functions'), 'set_time_limit')) { | |
| 226 | + set_time_limit(60); | |
| 227 | + } | |
| 228 | + try { | |
| 229 | + $handler->execute($integrationHandler, $integrationDetails, $currentFieldValues, $entryID, $logID); | |
| 230 | + } catch (\Throwable $executionError) { | |
| 231 | + // one failing integration must not abort the remaining ones | |
| 232 | + Log::debug_log('[+] Integration execution threw: ' . $executionError->getMessage()); | |
| 233 | + $logResponse->apiResponse( | |
| 234 | + $logID, | |
| 235 | + $integrationID, | |
| 236 | + ['type' => 'record', 'type_name' => $integrationName ?: 'Integration'], | |
| 237 | + 'errors', | |
| 238 | + $executionError->getMessage(), | |
| 239 | + $entryDetails | |
| 240 | + ); | |
| 241 | + } | |
| 219 | 242 | } else { |
| 220 | 243 | do_action('bitform_integration_run_failure', $integrationID, $formID); |
| 221 | 244 | |
| 222 | 245 | $errorMsg = apply_filters('bitform_filter_integration_run_failure_message', __('Integration execution failed', 'bit-form'), $integrationID, $formID); |
| @@ -275,9 +298,11 @@ | ||
| 275 | 298 | wp_json_encode($appConfig->details) : $appConfig->details; |
| 276 | 299 | } |
| 277 | 300 | $connectionCategory = 'connected_integration_apps'; |
| 278 | 301 | |
| 279 | - $integrationHandler = new IntegrationHandler(0); | |
| 302 | + // saveIntegration reads user_details['id'|'ip'|'time']; without them the insert | |
| 303 | + // raises null-offset warnings and stores null user_id/created_at | |
| 304 | + $integrationHandler = new IntegrationHandler(0, IpTool::getUserDetail()); | |
| 280 | 305 | |
| 281 | 306 | return $integrationHandler->saveIntegration($connectionName, $connectionType, $connectionDetails, $connectionCategory); |
| 282 | 307 | } |
| 283 | 308 | |
| @@ -311,6 +336,14 @@ | ||
| 311 | 336 | { |
| 312 | 337 | $integrationHandler = new IntegrationHandler(0); |
| 313 | 338 | |
| 314 | 339 | return $integrationHandler->deleteIntegration($appId); |
| 340 | + } | |
| 341 | + | |
| 342 | + public function renameConnectedApp($appId, $name) | |
| 343 | + { | |
| 344 | + // User details carry the time renameConnectedApp() stamps into updated_at. | |
| 345 | + $integrationHandler = new IntegrationHandler(0, IpTool::getUserDetail()); | |
| 346 | + | |
| 347 | + return $integrationHandler->renameConnectedApp($appId, $name); | |
| 315 | 348 | } |
| 316 | 349 | } |