Update: 2026-07-05 23:31:51
This commit is contained in:
@@ -27,6 +27,33 @@ try {
|
||||
// The bot asks for a task to do
|
||||
$platform = $_GET['platform'] ?? 'facebook';
|
||||
$requestedAccountId = $_GET['account_id'] ?? null;
|
||||
$deviceId = $_GET['device_id'] ?? null;
|
||||
|
||||
// Automatic Plug & Play Device Binding
|
||||
if ($deviceId) {
|
||||
$stmtDev = $con->prepare("SELECT id FROM social_accounts WHERE device_id = ?");
|
||||
$stmtDev->execute([$deviceId]);
|
||||
$acc = $stmtDev->fetch(PDO::FETCH_ASSOC);
|
||||
if ($acc) {
|
||||
$requestedAccountId = $acc['id'];
|
||||
} else {
|
||||
require_once __DIR__ . '/account_manager.php';
|
||||
$am = new AccountManager();
|
||||
// Find an account that doesn't have a device_id yet
|
||||
$stmtFind = $con->prepare("SELECT id FROM social_accounts WHERE platform = ? AND device_id IS NULL AND status = 'active' LIMIT 1");
|
||||
$stmtFind->execute([$platform]);
|
||||
$newAcc = $stmtFind->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($newAcc) {
|
||||
$requestedAccountId = $newAcc['id'];
|
||||
$updateDev = $con->prepare("UPDATE social_accounts SET device_id = ? WHERE id = ?");
|
||||
$updateDev->execute([$deviceId, $requestedAccountId]);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'No available unassigned accounts for this new device']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find a pending task that is scheduled for now or earlier
|
||||
if ($requestedAccountId) {
|
||||
|
||||
Reference in New Issue
Block a user