Section 3-8 - #MIgration Runs -
Multiple Migfeat: Update publishing terminology and add publishing settings - Changed references from "WordPress" to "Site" across multiple components for consistency. - Introduced a new "Publishing" tab in Site Settings to manage automatic content approval and publishing behavior. - Added publishing settings model to the backend with fields for auto-approval, auto-publish, and publishing limits. - Implemented Celery tasks for scheduling and processing automated content publishing. - Enhanced Writer Dashboard to include metrics for content published to the site and scheduled for publishing.
This commit is contained in:
@@ -1476,11 +1476,36 @@ class AutomationService:
|
||||
|
||||
This stage automatically approves content in 'review' status and
|
||||
marks it as 'approved' (ready for publishing to WordPress).
|
||||
|
||||
Respects PublishingSettings:
|
||||
- If auto_approval_enabled is False, skip approval and keep content in 'review'
|
||||
"""
|
||||
stage_number = 7
|
||||
stage_name = "Review → Approved"
|
||||
start_time = time.time()
|
||||
|
||||
# Check publishing settings for auto-approval
|
||||
from igny8_core.business.integration.models import PublishingSettings
|
||||
publishing_settings, _ = PublishingSettings.get_or_create_for_site(self.site)
|
||||
|
||||
if not publishing_settings.auto_approval_enabled:
|
||||
self.logger.log_stage_progress(
|
||||
self.run.run_id, self.account.id, self.site.id,
|
||||
stage_number, "Auto-approval is disabled for this site - skipping Stage 7"
|
||||
)
|
||||
self.run.stage_7_result = {
|
||||
'ready_for_review': 0,
|
||||
'approved_count': 0,
|
||||
'content_ids': [],
|
||||
'skipped': True,
|
||||
'reason': 'auto_approval_disabled'
|
||||
}
|
||||
self.run.status = 'completed'
|
||||
self.run.completed_at = datetime.now()
|
||||
self.run.save()
|
||||
cache.delete(f'automation_lock_{self.site.id}')
|
||||
return
|
||||
|
||||
# Query content ready for review
|
||||
ready_for_review = Content.objects.filter(
|
||||
site=self.site,
|
||||
@@ -1602,13 +1627,55 @@ class AutomationService:
|
||||
stage_number, approved_count, time_elapsed, 0
|
||||
)
|
||||
|
||||
# Check if auto-publish is enabled and queue approved content for publishing
|
||||
published_count = 0
|
||||
if publishing_settings.auto_publish_enabled and approved_count > 0:
|
||||
self.logger.log_stage_progress(
|
||||
self.run.run_id, self.account.id, self.site.id,
|
||||
stage_number, f"Auto-publish enabled - queuing {len(content_ids)} content items for publishing"
|
||||
)
|
||||
|
||||
# Get WordPress integration for this site
|
||||
from igny8_core.business.integration.models import SiteIntegration
|
||||
wp_integration = SiteIntegration.objects.filter(
|
||||
site=self.site,
|
||||
platform='wordpress',
|
||||
is_active=True
|
||||
).first()
|
||||
|
||||
if wp_integration:
|
||||
from igny8_core.tasks.wordpress_publishing import publish_content_to_wordpress
|
||||
|
||||
for content_id in content_ids:
|
||||
try:
|
||||
# Queue publish task
|
||||
publish_content_to_wordpress.delay(
|
||||
content_id=content_id,
|
||||
site_integration_id=wp_integration.id
|
||||
)
|
||||
published_count += 1
|
||||
except Exception as e:
|
||||
logger.error(f"[AutomationService] Failed to queue publish for content {content_id}: {str(e)}")
|
||||
|
||||
self.logger.log_stage_progress(
|
||||
self.run.run_id, self.account.id, self.site.id,
|
||||
stage_number, f"Queued {published_count} content items for WordPress publishing"
|
||||
)
|
||||
else:
|
||||
self.logger.log_stage_progress(
|
||||
self.run.run_id, self.account.id, self.site.id,
|
||||
stage_number, "No active WordPress integration found - skipping auto-publish"
|
||||
)
|
||||
|
||||
self.run.stage_7_result = {
|
||||
'ready_for_review': total_count,
|
||||
'review_total': total_count,
|
||||
'approved_count': approved_count,
|
||||
'content_ids': content_ids,
|
||||
'time_elapsed': time_elapsed,
|
||||
'in_progress': False
|
||||
'in_progress': False,
|
||||
'auto_published_count': published_count if publishing_settings.auto_publish_enabled else 0,
|
||||
'auto_publish_enabled': publishing_settings.auto_publish_enabled,
|
||||
}
|
||||
self.run.status = 'completed'
|
||||
self.run.completed_at = datetime.now()
|
||||
@@ -1617,7 +1684,8 @@ class AutomationService:
|
||||
# Release lock
|
||||
cache.delete(f'automation_lock_{self.site.id}')
|
||||
|
||||
logger.info(f"[AutomationService] Stage 7 complete: {approved_count} content pieces approved (ready for publishing)")
|
||||
logger.info(f"[AutomationService] Stage 7 complete: {approved_count} content pieces approved" +
|
||||
(f", {published_count} queued for publishing" if published_count > 0 else " (ready for publishing)"))
|
||||
|
||||
def pause_automation(self):
|
||||
"""Pause current automation run"""
|
||||
|
||||
Reference in New Issue
Block a user