hostas2/bin/deluser.php

48 lines
1.2 KiB
PHP

<?php
require_once('./public/config.php');
$preferred_username = readline('Username: ');
$conn = new SQLite3(HOSTAS_DATABASE_PATH);
$person_query = $conn->prepare("
select * from actor where preferredUsername = :preferredUsername
");
$person_query->bindValue(':preferredUsername', $preferred_username);
$person = ($person_query->execute())->fetchArray();
if ($person === null) {
echo "No user by the name $preferred_username was found. Aborting" . PHP_EOL;
die();
}
$objectId = $person['objectId'];
$person_drop_stmt = $conn->prepare("
delete from actor where objectId = :objectId
");
$object_drop_stmt = $conn->prepare("
delete from object where id = :objectId
");
$person_drop_stmt->bindValue(':objectId', $objectId);
$object_drop_stmt->bindValue(':objectId', $objectId);
$person_drop_result = $object_drop_stmt->execute();
if (!$person_drop_stmt->execute()) {
echo "Error: failed to drop person $objectId. No changes made. Aborting." . PHP_EOL;
die();
}
if (!$object_drop_stmt->execute()) {
echo "Error: failed to drop object $objectId. This object has been left without a corresponding actor. Aborting" . PHP_EOL;
die();
}
echo "Successfully dropped actor $preferred_username!" . PHP_EOL;
$conn->close();