wp plugin refacotr
This commit is contained in:
@@ -174,9 +174,11 @@ class WordPressAdapter(BaseAdapter):
|
||||
optional_fields.append('secondary_keywords')
|
||||
if hasattr(content, 'cluster') and content.cluster:
|
||||
content_data['cluster_id'] = content.cluster.id
|
||||
content_data['cluster_name'] = content.cluster.name # NEW: Send cluster name for taxonomy creation
|
||||
optional_fields.append('cluster_id')
|
||||
if hasattr(content, 'sector') and content.sector:
|
||||
content_data['sector_id'] = content.sector.id
|
||||
content_data['sector_name'] = content.sector.name # NEW: Send sector name for taxonomy creation
|
||||
optional_fields.append('sector_id')
|
||||
|
||||
# STEP: Get categories from taxonomy_terms
|
||||
@@ -288,6 +290,12 @@ class WordPressAdapter(BaseAdapter):
|
||||
if response.status_code == 201:
|
||||
wp_data = response.json().get('data', {})
|
||||
logger.info(f"[WordPressAdapter._publish_via_api_key] ✅ Success! WordPress post created: post_id={wp_data.get('post_id')}, url={wp_data.get('post_url')}")
|
||||
|
||||
# NEW: Extract term_ids from WordPress response
|
||||
term_ids = wp_data.get('term_ids', {})
|
||||
if term_ids:
|
||||
logger.info(f"[WordPressAdapter._publish_via_api_key] 🏷️ Term IDs received: {term_ids}")
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'external_id': str(wp_data.get('post_id')),
|
||||
@@ -295,7 +303,8 @@ class WordPressAdapter(BaseAdapter):
|
||||
'published_at': datetime.now(),
|
||||
'metadata': {
|
||||
'post_id': wp_data.get('post_id'),
|
||||
'status': destination_config.get('status', 'publish')
|
||||
'status': destination_config.get('status', 'publish'),
|
||||
'term_ids': term_ids # NEW: Save term ID mappings for future reference
|
||||
}
|
||||
}
|
||||
else:
|
||||
|
||||
@@ -170,7 +170,17 @@ class PublisherService:
|
||||
content.status = 'published'
|
||||
content.external_id = result.get('external_id')
|
||||
content.external_url = result.get('url')
|
||||
content.save(update_fields=['status', 'external_id', 'external_url', 'updated_at'])
|
||||
|
||||
# NEW: Save term_ids to external_metadata if available
|
||||
if result.get('metadata') and result['metadata'].get('term_ids'):
|
||||
if not content.external_metadata:
|
||||
content.external_metadata = {}
|
||||
content.external_metadata['wordpress_term_ids'] = result['metadata']['term_ids']
|
||||
logger.info(f"[PublisherService._publish_to_destination] 🏷️ Saved term_ids to external_metadata: {result['metadata']['term_ids']}")
|
||||
content.save(update_fields=['status', 'external_id', 'external_url', 'external_metadata', 'updated_at'])
|
||||
else:
|
||||
content.save(update_fields=['status', 'external_id', 'external_url', 'updated_at'])
|
||||
|
||||
logger.info(f"[PublisherService._publish_to_destination] ✅ Updated content status to 'published'")
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user