"; // Establish a direct database connection for setup $pdo = db(); // 1. Get the first person from the database $stmt = $pdo->query("SELECT id FROM people LIMIT 1"); $person = $stmt->fetch(PDO::FETCH_ASSOC); if (!$person) { die("Error: No people found in the database. Please run `db_setup.php` or ensure the database is seeded correctly.
"); } $personId = $person['id']; echo "Prerequisite check: Using person with ID $personId.
"; // 2. Get the first process definition from the database $stmt = $pdo->query("SELECT id FROM process_definitions LIMIT 1"); $process = $stmt->fetch(PDO::FETCH_ASSOC); if (!$process) { die("Error: No process definitions found in the database. Please run `db_setup.php` or ensure the database is seeded correctly.
"); } $processDefinitionId = $process['id']; echo "Prerequisite check: Using process definition with ID $processDefinitionId.
"; $engine = new WorkflowEngine(); $userId = $personId; echo "Attempting to get or create instance with personId: $personId and processDefinitionId: $processDefinitionId
"; try { $instance = $engine->getOrCreateInstanceByDefId($personId, $processDefinitionId, $userId); if ($instance) { echo "Success! Successfully got or created instance:
"; echo "
";
        print_r($instance);
        echo "
"; } else { echo "Error: Failed to get or create instance, but no exception was thrown.
"; echo "This might happen if the process definition exists, but `startProcess` fails internally.
"; echo "Check PHP error logs for more details.
"; } } catch (Exception $e) { echo "An exception occurred: " . $e->getMessage() . "
"; echo "Stack trace:
" . $e->getTraceAsString() . "
"; }