hostas2/bin/pen.php

88 lines
2.1 KiB
PHP

<?php
require_once('./public/config.php');
require_once('./public/api/v1/database.php');
$note_id = 'https://' . HOSTAS_DOMAIN . '/api/v1/object/' . exec('uuidgen');
$activity_id= 'https://' . HOSTAS_DOMAIN . '/api/v1/object/' . exec('uuidgen');
$published = time();
$preferred_username = readline('Username: ');
$conn = new SQLite3(HOSTAS_DATABASE_PATH);
$actor_query = $conn->prepare("
select * from actor
join object on actor.objectId = object.id
where preferredUsername = :preferred_username
limit 1;
");
$actor_query->bindValue(':preferred_username', $preferred_username);
$actor_result = $actor_query->execute();
$actor = $actor_result->fetchArray();
if(!$actor) {
echo "No actor by the preferred username $preferred_username. Exiting" . PHP_EOL;
$conn->close();
exit(1);
}
$content = readline('Content: ');
$note_result = prepare_and_execute($conn,
"insert into object(id, type, published, attributedTo, content)
values (:id, :type, :published, :attributedTo, :content);",
array(
':id' => $note_id,
':type' => 'Note',
':published' => $published,
':attributedTo' => $actor['id'],
':content' => $content
)
);
if (!$note_result) {
echo 'Failed to create note. Exiting' . PHP_EOL;
$conn->close();
exit();
}
echo "Note created at $note_id" . PHP_EOL;
$activity_object_result = prepare_and_execute($conn,
"insert into object(id, type, published)
values(:id, :type, :published);",
array(
':id' => $activity_id,
':type' => 'Create',
':published' => $published,
)
);
if (!$activity_object_result) {
echo 'Failed to create the activity\'s object. Exiting' . PHP_EOL;
$conn->close();
exit();
}
echo "Object created for Create activity at $activity_id" . PHP_EOL;
$activity_result = prepare_and_execute($conn,
"insert into activity(objectId, actor, object)
values(:objectId, :actor, :object);",
array(
':objectId' => $activity_id,
':actor' => $actor['id'],
':object' => $note_id,
)
);
if (!$activity_result) {
echo 'Failed to create the activity record. Exiting' . PHP_EOL;
$conn->close();
exit();
}
echo "Successfully created activity." . PHP_EOL;
$conn->close();