106 lines
4.0 KiB
PHP
106 lines
4.0 KiB
PHP
<?php
|
|
// ============================================================
|
|
// marketing_engine/services/ContentWorkflow.php
|
|
// Orchestrates the entire content generation pipeline
|
|
// ============================================================
|
|
|
|
require_once __DIR__ . '/AIVideoGenerator.php';
|
|
require_once __DIR__ . '/../../core/bootstrap.php';
|
|
|
|
class ContentWorkflow {
|
|
private $generator;
|
|
private $con;
|
|
|
|
public function __construct() {
|
|
$this->generator = new AIVideoGenerator();
|
|
$this->con = Database::get('main');
|
|
}
|
|
|
|
/**
|
|
* Executes the next pending step in the content pipeline
|
|
*/
|
|
public function processPipeline() {
|
|
// 1. Check for pending topics to generate scripts
|
|
$this->processPendingScripts();
|
|
|
|
// 2. Check for generated scripts to create voice
|
|
$this->processPendingVoices();
|
|
|
|
// 3. Check for generated voices to render video
|
|
$this->processPendingVideos();
|
|
|
|
// 4. Check for rendered videos to queue marketing tasks
|
|
$this->queueUploadTasks();
|
|
}
|
|
|
|
private function processPendingScripts() {
|
|
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'pending' LIMIT 1");
|
|
$stmt->execute();
|
|
$job = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($job) {
|
|
$result = $this->generator->generateScript($job['topic']);
|
|
if ($result['status'] === 'success') {
|
|
$update = $this->con->prepare("UPDATE content_pipeline SET script_text = ?, status = 'script_generated' WHERE id = ?");
|
|
$update->execute([$result['script'], $job['id']]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function processPendingVoices() {
|
|
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'script_generated' LIMIT 1");
|
|
$stmt->execute();
|
|
$job = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($job) {
|
|
$result = $this->generator->generateVoice($job['script_text']);
|
|
if ($result['status'] === 'success') {
|
|
$update = $this->con->prepare("UPDATE content_pipeline SET voice_url = ?, status = 'voice_generated' WHERE id = ?");
|
|
$update->execute([$result['audio_url'], $job['id']]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function processPendingVideos() {
|
|
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'voice_generated' LIMIT 1");
|
|
$stmt->execute();
|
|
$job = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($job) {
|
|
$result = $this->generator->renderVideo($job['script_text'], $job['voice_url']);
|
|
if ($result['status'] === 'success') {
|
|
$update = $this->con->prepare("UPDATE content_pipeline SET video_url = ?, status = 'video_rendered' WHERE id = ?");
|
|
$update->execute([$result['video_url'], $job['id']]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function queueUploadTasks() {
|
|
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'video_rendered' LIMIT 1");
|
|
$stmt->execute();
|
|
$job = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($job) {
|
|
// Create upload tasks for TikTok and YouTube Shorts
|
|
$insert = $this->con->prepare("
|
|
INSERT INTO marketing_tasks (platform, type, content_text, media_url, status)
|
|
VALUES
|
|
('tiktok', 'upload_video', ?, ?, 'pending'),
|
|
('youtube', 'upload_video', ?, ?, 'pending')
|
|
");
|
|
|
|
// Provide a short caption based on the script
|
|
$caption = substr($job['script_text'], 0, 100) . "... #Siro #RideHailing";
|
|
|
|
$insert->execute([
|
|
$caption, $job['video_url'],
|
|
$caption, $job['video_url']
|
|
]);
|
|
|
|
// Mark job as published (or handed off to bots)
|
|
$update = $this->con->prepare("UPDATE content_pipeline SET status = 'published' WHERE id = ?");
|
|
$update->execute([$job['id']]);
|
|
}
|
|
}
|
|
}
|