@@ -28,46 +28,45 @@ def publish_content_to_wordpress(self, content_id: int, site_integration_id: int
|
||||
Dict with success status and details
|
||||
"""
|
||||
try:
|
||||
from igny8_core.business.content.models import Content
|
||||
from igny8_core.business.integration.models import SiteIntegration
|
||||
from igny8_core.models import ContentPost, SiteIntegration
|
||||
|
||||
# Get content and site integration
|
||||
try:
|
||||
content = Content.objects.get(id=content_id)
|
||||
content = ContentPost.objects.get(id=content_id)
|
||||
site_integration = SiteIntegration.objects.get(id=site_integration_id)
|
||||
except (Content.DoesNotExist, SiteIntegration.DoesNotExist) as e:
|
||||
except (ContentPost.DoesNotExist, SiteIntegration.DoesNotExist) as e:
|
||||
logger.error(f"Content or site integration not found: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
|
||||
# Check if content is ready for publishing
|
||||
if content.sync_status == 'success':
|
||||
if content.wordpress_sync_status == 'success':
|
||||
logger.info(f"Content {content_id} already published to WordPress")
|
||||
return {"success": True, "message": "Already published", "wordpress_post_id": content.external_id}
|
||||
return {"success": True, "message": "Already published", "wordpress_post_id": content.wordpress_post_id}
|
||||
|
||||
if content.sync_status == 'syncing':
|
||||
if content.wordpress_sync_status == 'syncing':
|
||||
logger.info(f"Content {content_id} is currently syncing")
|
||||
return {"success": False, "error": "Content is currently syncing"}
|
||||
|
||||
# Update status to syncing
|
||||
content.sync_status = 'syncing'
|
||||
content.save(update_fields=['sync_status'])
|
||||
content.wordpress_sync_status = 'syncing'
|
||||
content.save(update_fields=['wordpress_sync_status'])
|
||||
|
||||
# Prepare content data for WordPress
|
||||
content_data = {
|
||||
'content_id': content.id,
|
||||
'task_id': task_id,
|
||||
'title': content.title,
|
||||
'content_html': content.content_html,
|
||||
'excerpt': '', # Content model doesn't have brief field
|
||||
'content_html': content.content_html or content.content,
|
||||
'excerpt': content.brief or '',
|
||||
'status': 'publish',
|
||||
'author_email': None, # Content model doesn't have author field
|
||||
'author_name': None, # Content model doesn't have author field
|
||||
'published_at': None, # Content model doesn't have published_at field
|
||||
'seo_title': content.meta_title or '',
|
||||
'seo_description': content.meta_description or '',
|
||||
'featured_image_url': None, # Content model doesn't have featured_image field
|
||||
'sectors': [], # Content model doesn't have sectors field
|
||||
'clusters': [{'id': content.cluster.id, 'name': content.cluster.name}] if content.cluster else [],
|
||||
'author_email': content.author.email if content.author else None,
|
||||
'author_name': content.author.get_full_name() if content.author else None,
|
||||
'published_at': content.published_at.isoformat() if content.published_at else None,
|
||||
'seo_title': getattr(content, 'seo_title', ''),
|
||||
'seo_description': getattr(content, 'seo_description', ''),
|
||||
'featured_image_url': content.featured_image.url if content.featured_image else None,
|
||||
'sectors': [{'id': s.id, 'name': s.name} for s in content.sectors.all()],
|
||||
'clusters': [{'id': c.id, 'name': c.name} for c in content.clusters.all()],
|
||||
'tags': getattr(content, 'tags', []),
|
||||
'focus_keywords': getattr(content, 'focus_keywords', [])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user