From 5971750295a4b03a1b01278f823a6a7d1b3ba8ec Mon Sep 17 00:00:00 2001 From: alorig <220087330+alorig@users.noreply.github.com> Date: Sat, 22 Nov 2025 09:19:44 +0500 Subject: [PATCH] Fix: Integration content types last_structure_fetch path + add test script for manual structure push --- .../igny8_core/modules/integration/views.py | 2 +- backend/test_push_structure.py | 162 ++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 backend/test_push_structure.py diff --git a/backend/igny8_core/modules/integration/views.py b/backend/igny8_core/modules/integration/views.py index 37d6d139..6fc042e3 100644 --- a/backend/igny8_core/modules/integration/views.py +++ b/backend/igny8_core/modules/integration/views.py @@ -313,7 +313,7 @@ class IntegrationViewSet(SiteSectorModelViewSet): summary = { 'post_types': post_types_data, 'taxonomies': taxonomies_data, - 'last_structure_fetch': config.get('last_structure_fetch'), + 'last_structure_fetch': content_types.get('last_structure_fetch'), 'plugin_connection_enabled': config.get('plugin_connection_enabled', True), 'two_way_sync_enabled': config.get('two_way_sync_enabled', True), } diff --git a/backend/test_push_structure.py b/backend/test_push_structure.py new file mode 100644 index 00000000..3f706ea2 --- /dev/null +++ b/backend/test_push_structure.py @@ -0,0 +1,162 @@ +""" +Test Script to Manually Push WordPress Structure to IGNY8 Backend +This simulates what the WordPress plugin would send +""" + +import requests +import json + +# Configuration +API_BASE = "https://api.igny8.com/api/v1" +SITE_ID = 5 # From the URL: https://app.igny8.com/sites/5/settings + +# You need to get an API key from Django admin or use your access token +# For now, this script shows what data should be sent +API_KEY = "YOUR_API_KEY_HERE" # Replace with actual API key + +# Step 1: Get the integration ID for this WordPress site +def get_integration_id(): + url = f"{API_BASE}/integration/integrations/" + params = {"site": SITE_ID, "platform": "wordpress"} + headers = {"Authorization": f"Bearer {API_KEY}"} + + response = requests.get(url, params=params, headers=headers) + print(f"Get Integration Response: {response.status_code}") + print(json.dumps(response.json(), indent=2)) + + if response.status_code == 200: + data = response.json() + # Handle paginated response + if 'results' in data: + integrations = data['results'] + elif isinstance(data, list): + integrations = data + else: + integrations = [data] + + if integrations: + return integrations[0]['id'] + + return None + +# Step 2: Push WordPress structure to backend +def push_structure(integration_id): + url = f"{API_BASE}/integration/integrations/{integration_id}/update-structure/" + headers = { + "Authorization": f"Bearer {API_KEY}", + "Content-Type": "application/json" + } + + # Sample WordPress structure data + payload = { + "post_types": { + "post": { + "label": "Posts", + "count": 150, + "enabled": True, + "fetch_limit": 100 + }, + "page": { + "label": "Pages", + "count": 25, + "enabled": True, + "fetch_limit": 100 + }, + "product": { + "label": "Products", + "count": 89, + "enabled": True, + "fetch_limit": 100 + } + }, + "taxonomies": { + "category": { + "label": "Categories", + "count": 15, + "enabled": True, + "fetch_limit": 100 + }, + "post_tag": { + "label": "Tags", + "count": 234, + "enabled": True, + "fetch_limit": 100 + }, + "product_cat": { + "label": "Product Categories", + "count": 12, + "enabled": True, + "fetch_limit": 100 + } + }, + "timestamp": "2025-11-22T04:20:00+00:00", + "site_url": "https://example.com", + "wordpress_version": "6.4", + "plugin_connection_enabled": True, + "two_way_sync_enabled": True + } + + response = requests.post(url, json=payload, headers=headers) + print(f"\nPush Structure Response: {response.status_code}") + print(json.dumps(response.json(), indent=2)) + + return response.status_code == 200 + +# Step 3: Verify the data was stored +def verify_content_types(integration_id): + url = f"{API_BASE}/integration/integrations/{integration_id}/content-types/" + headers = {"Authorization": f"Bearer {API_KEY}"} + + response = requests.get(url, headers=headers) + print(f"\nGet Content Types Response: {response.status_code}") + print(json.dumps(response.json(), indent=2)) + + return response.status_code == 200 + +# Main execution +if __name__ == "__main__": + print("=== WordPress Structure Push Test ===\n") + print(f"Site ID: {SITE_ID}") + print(f"API Base: {API_BASE}\n") + + if API_KEY == "YOUR_API_KEY_HERE": + print("ERROR: Please set your API_KEY in the script!") + print("\nTo get an API key:") + print("1. Go to Django admin") + print("2. Generate a WordPress API key for your site") + print("3. Replace 'YOUR_API_KEY_HERE' in this script") + exit(1) + + # Step 1 + print("Step 1: Getting Integration ID...") + integration_id = get_integration_id() + + if not integration_id: + print("\nERROR: Could not find WordPress integration for site!") + print("Make sure:") + print("1. The site exists in the database") + print("2. A WordPress integration exists for this site") + print("3. Your API key is valid") + exit(1) + + print(f"\n✓ Found Integration ID: {integration_id}") + + # Step 2 + print("\nStep 2: Pushing WordPress structure...") + if push_structure(integration_id): + print("\n✓ Structure pushed successfully!") + else: + print("\n✗ Failed to push structure!") + exit(1) + + # Step 3 + print("\nStep 3: Verifying content types...") + if verify_content_types(integration_id): + print("\n✓ Content types verified!") + print("\n=== TEST COMPLETE ===") + print("\nNow refresh the frontend page:") + print(f"https://app.igny8.com/sites/{SITE_ID}/settings?tab=content-types") + else: + print("\n✗ Could not verify content types!") + exit(1) +