Implement site structure synchronization between WordPress and IGNY8 backend
- Added a new API endpoint in the `IntegrationViewSet` to update the WordPress site structure, including post types and taxonomies. - Implemented a function to retrieve the site structure and sync it to the IGNY8 backend after establishing a connection. - Scheduled a daily cron job to keep the site structure updated. - Enhanced the WordPress plugin to trigger synchronization upon successful API connection. - Updated relevant files to support the new synchronization feature, improving integration capabilities.
This commit is contained in:
Binary file not shown.
@@ -5,6 +5,7 @@ Phase 6: Site Integration & Multi-Destination Publishing
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from django.utils import timezone
|
||||
|
||||
from igny8_core.api.base import SiteSectorModelViewSet
|
||||
from igny8_core.api.permissions import IsAuthenticatedAndActive, IsEditorOrAbove
|
||||
@@ -169,6 +170,64 @@ class IntegrationViewSet(SiteSectorModelViewSet):
|
||||
|
||||
return success_response(status_data, request=request)
|
||||
|
||||
@action(detail=True, methods=['post'], url_path='update-structure')
|
||||
def update_site_structure(self, request, pk=None):
|
||||
"""
|
||||
Update WordPress site structure (post types, taxonomies, counts).
|
||||
Called by WordPress plugin to push site configuration to backend.
|
||||
|
||||
POST /api/v1/integration/integrations/{id}/update-structure/
|
||||
|
||||
Request body:
|
||||
{
|
||||
"post_types": {
|
||||
"post": {"label": "Posts", "count": 123, "enabled": true, "fetch_limit": 100},
|
||||
"page": {"label": "Pages", "count": 12, "enabled": true, "fetch_limit": 100},
|
||||
"product": {"label": "Products", "count": 456, "enabled": false, "fetch_limit": 50}
|
||||
},
|
||||
"taxonomies": {
|
||||
"category": {"label": "Categories", "count": 25, "enabled": true, "fetch_limit": 100},
|
||||
"post_tag": {"label": "Tags", "count": 102, "enabled": true, "fetch_limit": 100},
|
||||
"product_cat": {"label": "Product Categories", "count": 15, "enabled": false, "fetch_limit": 50}
|
||||
},
|
||||
"plugin_connection_enabled": true,
|
||||
"two_way_sync_enabled": true
|
||||
}
|
||||
"""
|
||||
integration = self.get_object()
|
||||
|
||||
# Update config with new structure
|
||||
config = integration.config_json or {}
|
||||
|
||||
post_types = request.data.get('post_types', {})
|
||||
taxonomies = request.data.get('taxonomies', {})
|
||||
|
||||
if post_types or taxonomies:
|
||||
config['content_types'] = {
|
||||
'post_types': post_types,
|
||||
'taxonomies': taxonomies,
|
||||
'last_structure_fetch': request.data.get('timestamp') or str(timezone.now().isoformat())
|
||||
}
|
||||
config['plugin_connection_enabled'] = request.data.get('plugin_connection_enabled', True)
|
||||
config['two_way_sync_enabled'] = request.data.get('two_way_sync_enabled', True)
|
||||
|
||||
integration.config_json = config
|
||||
integration.save()
|
||||
|
||||
return success_response({
|
||||
'message': 'Site structure updated successfully',
|
||||
'post_types_count': len(post_types),
|
||||
'taxonomies_count': len(taxonomies),
|
||||
'last_structure_fetch': config['content_types']['last_structure_fetch']
|
||||
}, request=request)
|
||||
|
||||
return error_response(
|
||||
'No post types or taxonomies provided',
|
||||
None,
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
request
|
||||
)
|
||||
|
||||
@action(detail=True, methods=['get'], url_path='content-types')
|
||||
def content_types_summary(self, request, pk=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user