62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once('./public/config.php');
|
||
|
|
||
|
echo 'Creating new actor. Please fill out the following prompts:' . PHP_EOL;
|
||
|
|
||
|
$name = readline('Name: ');
|
||
|
$preferred_username = readline('Username: ');
|
||
|
$summary = readline('Summary: ');
|
||
|
|
||
|
// We use this link as the user's ID because in ActivityStreams, all IDs
|
||
|
// must be dereferenceable
|
||
|
$id = "https://" . HOSTAS_DOMAIN . "/api/v1/actor/$preferred_username";
|
||
|
|
||
|
$url = readline('Canonical URL (hit enter to generate one): ');
|
||
|
if ($url === '') {
|
||
|
$url = $id;
|
||
|
echo 'Canonical URL: ' . $url . PHP_EOL;
|
||
|
}
|
||
|
|
||
|
$icon_url = readline('Icon URL (hit enter for none): ');
|
||
|
$icon_url = $icon_url === '' ? null : $icon_url;
|
||
|
|
||
|
$conn = new SQLite3(HOSTAS_DATABASE_PATH);
|
||
|
|
||
|
$object_creation_stmt = $conn->prepare("
|
||
|
insert into object(id, type, name, summary, url, icon)
|
||
|
values (:id, 'Person', :name, :summary, :url, :icon);
|
||
|
");
|
||
|
|
||
|
$person_creation_stmt = $conn->prepare("
|
||
|
insert into actor(objectId, preferredUsername)
|
||
|
values (:objectId, :preferredUsername);
|
||
|
");
|
||
|
|
||
|
$object_creation_stmt->bindValue(':id', $id);
|
||
|
$object_creation_stmt->bindValue(':name', $name);
|
||
|
$object_creation_stmt->bindValue(':summary', $summary);
|
||
|
$object_creation_stmt->bindValue(':url', $url);
|
||
|
$object_creation_stmt->bindValue(':icon', $icon_url);
|
||
|
|
||
|
$object_creation_result = $object_creation_stmt->execute();
|
||
|
|
||
|
if (!$object_creation_result) {
|
||
|
echo 'Error: failed to insert object.' . PHP_EOL;
|
||
|
die();
|
||
|
}
|
||
|
|
||
|
$person_creation_stmt->bindValue(':objectId', $id);
|
||
|
$person_creation_stmt->bindValue(':preferredUsername', $preferred_username);
|
||
|
|
||
|
$person_creation_result = $person_creation_stmt->execute();
|
||
|
|
||
|
if (!$person_creation_result) {
|
||
|
echo 'Error: failed to insert person.' . PHP_EOL;
|
||
|
die();
|
||
|
}
|
||
|
|
||
|
echo "Actor with ID $id created successfully!" . PHP_EOL;
|
||
|
|
||
|
$conn->close();
|