fixing issues of integration with wordpress plugin
This commit is contained in:
@@ -217,6 +217,7 @@ class IntegrationService:
|
||||
dict: Connection test result with detailed health status
|
||||
"""
|
||||
import requests
|
||||
from django.utils import timezone
|
||||
|
||||
config = integration.config_json
|
||||
|
||||
@@ -324,13 +325,6 @@ class IntegrationService:
|
||||
health_checks['plugin_has_api_key']
|
||||
)
|
||||
|
||||
# Save site_url to config if successful and not already set
|
||||
if is_healthy and not config.get('site_url'):
|
||||
config['site_url'] = site_url
|
||||
integration.config_json = config
|
||||
integration.save(update_fields=['config_json'])
|
||||
logger.info(f"[IntegrationService] Saved site_url to integration {integration.id} config: {site_url}")
|
||||
|
||||
# Build response message
|
||||
if is_healthy:
|
||||
message = "✅ WordPress integration is connected and authenticated via API key"
|
||||
@@ -347,6 +341,28 @@ class IntegrationService:
|
||||
else:
|
||||
message = "❌ WordPress connection failed"
|
||||
|
||||
# Update integration status based on connection test result
|
||||
if is_healthy:
|
||||
integration.sync_status = 'success'
|
||||
integration.sync_error = None
|
||||
integration.last_sync_at = timezone.now()
|
||||
logger.info(f"[IntegrationService] Connection test passed, set sync_status to 'success' for integration {integration.id}")
|
||||
else:
|
||||
integration.sync_status = 'failed'
|
||||
integration.sync_error = message
|
||||
logger.warning(f"[IntegrationService] Connection test failed, set sync_status to 'failed' for integration {integration.id}")
|
||||
|
||||
# Save site_url to config if successful and not already set
|
||||
if is_healthy and not config.get('site_url'):
|
||||
config['site_url'] = site_url
|
||||
integration.config_json = config
|
||||
|
||||
# Save all changes to integration
|
||||
integration.save()
|
||||
|
||||
if is_healthy and not config.get('site_url'):
|
||||
logger.info(f"[IntegrationService] Saved site_url to integration {integration.id} config: {site_url}")
|
||||
|
||||
return {
|
||||
'success': is_healthy,
|
||||
'fully_functional': is_healthy,
|
||||
|
||||
Reference in New Issue
Block a user