Prefix tables with just pterotype

This commit is contained in:
Jeremy Dormitzer 2018-09-19 17:33:20 -04:00
parent 227360f86e
commit a49d554256
9 changed files with 44 additions and 47 deletions

View File

@ -4,7 +4,7 @@ namespace activities;
function get_activity( $id ) {
global $wpdb;
$activity_json = $wpdb->get_var( $wpdb->prepare(
'SELECT activity FROM pterotype_activitypub_activities WHERE id = %d', $id
'SELECT activity FROM pterotype_activities WHERE id = %d', $id
) );
if ( is_null( $activity_json ) ) {
return new \WP_Error(
@ -18,7 +18,7 @@ function get_activity( $id ) {
function get_activity_by_activitypub_id( $activitypub_id ) {
global $wpdb;
$activity_json = $wpdb->get_var( $wpdb->prepare(
'SELECT activity FROM pterotype_activitypub_activities WHERE id = %s', $activitypub_id
'SELECT activity FROM pterotype_activities WHERE id = %s', $activitypub_id
) );
if ( is_null( $activity_json ) ) {
return new \WP_Error(
@ -49,7 +49,7 @@ function persist_activity( $activity ) {
);
}
$activitypub_id = $activity['id'];
$wpdb->insert( 'pterotype_activitypub_activities', array(
$wpdb->insert( 'pterotype_activities', array(
'activitypub_id' => $activitypub_id,
'activity' => wp_json_encode( $activity )
) );
@ -58,7 +58,7 @@ function persist_activity( $activity ) {
function create_local_activity( $activity ) {
global $wpdb;
$res = $wpdb->insert( 'pterotype_activitypub_activities', array(
$res = $wpdb->insert( 'pterotype_activities', array(
'activity' => wp_json_encode( $activity )
) );
if ( !$res ) {
@ -70,7 +70,7 @@ function create_local_activity( $activity ) {
$activity_url = get_rest_url( null, sprintf( '/pterotype/v1/activity/%d', $id ) );
$activity['id'] = $activity_url;
$res = $wpdb->replace(
'pterotype_activitypub_activities',
'pterotype_activities',
array(
'id' => $activity_id,
'activitypub_id' => $activity_url,

View File

@ -4,7 +4,7 @@ namespace actors;
function get_actor( $id ) {
global $wpdb;
$row = $wpdb->get_row( $wpdb->prepare(
'SELECT * FROM pterotype_activitypub_actors WHERE id = %d', $id
'SELECT * FROM pterotype_actors WHERE id = %d', $id
) );
return get_user_from_row( $row );
}
@ -12,7 +12,7 @@ function get_actor( $id ) {
function get_actor_by_slug ( $slug ) {
global $wpdb;
$row = $wpdb->get_row( $wpdb->prepare(
'SELECT * FROM pterotype_activitypub_actors WHERE slug = %s', $slug
'SELECT * FROM pterotype_actors WHERE slug = %s', $slug
) );
return get_actor_from_row( $row );
}
@ -20,7 +20,7 @@ function get_actor_by_slug ( $slug ) {
function get_actor_id( $slug ) {
global $wpdb;
return $wpdb->get_var( $wpdb->prepare(
"SELECT slug FROM pterotype_activitypub_actors WHERE slug = %s", $slug
"SELECT slug FROM pterotype_actors WHERE slug = %s", $slug
) );
}
@ -78,7 +78,7 @@ function initialize_user_actors() {
function create_actor_from_user( $user_slug ) {
global $wpdb;
$wpdb->query( $wpdb->prepare(
"INSERT IGNORE INTO pterotype_activitypub_actors(slug, type) VALUES(%s, 'user')", $user_slug
"INSERT IGNORE INTO pterotype_actors(slug, type) VALUES(%s, 'user')", $user_slug
) );
}
?>

View File

@ -10,7 +10,7 @@ get ignored
function create_block( $actor_id, $blocked_actor_url ) {
global $wpdb;
$res = $wpdb->insert(
'pterotype_activitypub_blocks',
'pterotype_blocks',
array( 'actor_id' => $actor_id, 'blocked_actor_url' => $blocked_actor_url )
);
if ( !$res ) {

View File

@ -7,7 +7,7 @@ $FOLLOWING = 'FOLLOWING';
function request_follow( $actor_id, $object_id ) {
global $wpdb;
return $wpdb->insert(
'pterotype_activitypub_following',
'pterotype_following',
array( 'actor_id' => $actor_id,
'object_id' => wp_json_encode( $object ),
'state' => $PENDING

View File

@ -65,12 +65,12 @@ function create_inbox_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS pterotype_activitypub_inbox(
CREATE TABLE IF NOT EXISTS pterotype_inbox(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
actor_id UNSIGNED INT NOT NULL,
activity_id INT UNSIGNED NOT NULL,
FOREIGN KEY inbox_activity_fk(activity_id)
REFERENCES pterotype_activitypub_activities(id)
REFERENCES pterotype_activities(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

View File

@ -4,7 +4,7 @@ namespace likes;
function create_like( $actor_id, $object_id ) {
global $wpdb;
return $wpdb->insert(
'pterotype_activitypub_likes', array( 'actor_id' => $actor_id, 'object_id' => $object_id )
'pterotype_likes', array( 'actor_id' => $actor_id, 'object_id' => $object_id )
);
}
?>

View File

@ -25,7 +25,7 @@ function migration_0_0_1() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_activities (
CREATE TABLE pterotype_activities (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
activitypub_id VARCHAR(255) UNIQUE NOT NULL,
activity TEXT NOT NULL
@ -36,12 +36,12 @@ function migration_0_0_1() {
$wpdb->query(
"
CREATE UNIQUE INDEX ACTIVITIES_ACTIVITYPUB_ID_INDEX
ON pterotype_activitypub_activities (activitypub_id);
ON pterotype_activities (activitypub_id);
"
);
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_objects (
CREATE TABLE pterotype_objects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
activitypub_id VARCHAR(255) UNIQUE NOT NULL,
object TEXT NOT NULL
@ -52,24 +52,24 @@ function migration_0_0_1() {
$wpdb->query(
"
CREATE UNIQUE INDEX OBJECT_ACTIVITYPUB_ID_INDEX
ON pterotype_activitypub_objects (activitypub_id);
ON pterotype_objects (activitypub_id);
"
);
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_outbox (
CREATE TABLE pterotype_outbox (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
actor_id INT UNSIGNED NOT NULL,
activity_id INT UNSIGNED NOT NULL,
FOREIGN KEY outbox_activity_fk(activity_id)
REFERENCES pterotype_activitypub_activities(id)
REFERENCES pterotype_activities(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"
);
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_actors(
CREATE TABLE pterotype_actors(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
slug VARCHAR(64) UNIQUE NOT NULL,
type VARCHAR(64) NOT NULL
@ -79,40 +79,40 @@ function migration_0_0_1() {
);
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_likes (
CREATE TABLE pterotype_likes (
actor_id INT UNSIGNED NOT NULL,
object_id INT UNSIGNED NOT NULL,
PRIMARY KEY (actor_id, object_id),
FOREIGN KEY likes_actor_fk(actor_id)
REFERENCES pterotype_activitypub_actors(id),
REFERENCES pterotype_actors(id),
FOREIGN KEY likes_object_fk(object_id)
REFERENCES pterotype_activitypub_objects(id)
REFERENCES pterotype_objects(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"
);
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_following(
CREATE TABLE pterotype_following(
actor_id INT UNSIGNED NOT NULL,
object_id INT UNSIGNED NOT NULL,
state VARCHAR(64) NOT NULL,
PRIMARY KEY (actor_id, object_id),
FOREIGN KEY following_actor_fk(actor_id)
REFERENCES pterotype_activitypub_actors(id),
REFERENCES pterotype_actors(id),
FOREIGN KEY following_object_fk(object_id)
REFERENCES pterotype_activitypub_objects(id)
REFERENCES pterotype_objects(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"
);
$wpdb->query(
"
CREATE TABLE pterotype_activitypub_blocks(
CREATE TABLE pterotype_blocks(
actor_id INT UNSIGNED NOT NULL,
blocked_actor_url TEXT NOT NULL,
FOREIGN KEY blocks_actor_fk(actor_id)
REFERENCES pterotype_activitypub_actors(id)
REFERENCES pterotype_actors(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

View File

@ -6,7 +6,7 @@ namespace objects;
function create_local_object( $object ) {
global $wpdb;
$res = $wpdb->insert( 'pterotype_activitypub_objects', array(
$res = $wpdb->insert( 'pterotype_objects', array(
'object' => wp_json_encode( $object )
) );
if ( !$res ) {
@ -18,7 +18,7 @@ function create_local_object( $object ) {
$object_url = get_rest_url( null, sprintf( '/pterotype/v1/object/%d', $object_id ) );
$object['id'] = $object_url;
$res = $wpdb->replace(
'pterotype_activitypub_objects',
'pterotype_objects',
array (
'id' => $object_id,
'activitypub_id' => $object_url,
@ -44,12 +44,12 @@ function upsert_object( $object ) {
);
}
$row = $wpdb->get_row( $wpdb->prepare(
'SELECT * FROM pterotype_activitypub_objects WHERE activitypub_url = %s', $object['id']
'SELECT * FROM pterotype_objects WHERE activitypub_url = %s', $object['id']
) );
$res = true;
if ( $row === null ) {
$res = $wpdb->insert(
'pterotype_activitypub_objects',
'pterotype_objects',
array(
'activitypub_id' => $object['id'],
'object' => wp_json_encode( $object )
@ -57,7 +57,7 @@ function upsert_object( $object ) {
);
} else {
$res = $wpdb->replace(
'pterotype_activitypub_objects',
'pterotype_objects',
array(
'id' => $row->id,
'activitypub_id' => $object['id'],
@ -103,7 +103,7 @@ function update_object( $object ) {
function get_object( $id ) {
global $wpdb;
$object_json = $wpdb->get_var( $wpdb->prepare(
'SELECT object FROM pterotype_activitypub_objects WHERE id = %d', $id
'SELECT object FROM pterotype_objects WHERE id = %d', $id
) );
if ( is_null( $object_json ) ) {
return new \WP_Error(
@ -116,7 +116,7 @@ function get_object( $id ) {
function get_object_by_activitypub_id( $activitypub_id ) {
global $wpdb;
$object_json = $wpdb->get_var( $wpdb->prepare(
'SELECT object FROM pterotype_activitypub_objects WHERE activitypub_id = %s', $activitypub_id
'SELECT object FROM pterotype_objects WHERE activitypub_id = %s', $activitypub_id
) );
if ( is_null( $object_json ) ) {
return new \WP_Error(
@ -136,7 +136,7 @@ function delete_object( $object ) {
);
}
$activitypub_id = $object['id'];
$res = $wpdb->delete( 'pterotype_activitypub_objects', array( 'activitypub_id' => $id ), '%s' );
$res = $wpdb->delete( 'pterotype_objects', array( 'activitypub_id' => $id ), '%s' );
if ( !$res ) {
return new \WP_Error( 'db_error', __( 'Error deleting object', 'pterotype' ) );
}

View File

@ -91,15 +91,12 @@ function get_outbox( $actor_slug ) {
// TODO what sort of joins should these be?
$results = $wpdb->get_results( $wpdb->prepare(
"
SELECT pterotype_activitypub_activities.activity
FROM pterotype_activitypub_outbox
JOIN pterotype_activitypub_actors
ON pterotype_activitypub_actors.id
= pterotype_activitypub_outbox.actor_id
JOIN pterotype_activitypub_activities
ON pterotype_activitypub_activities.id
= pterotype_activitypub_outbox.activity_id
WHERE pterotype_pterotype_activitypub_outbox.actor_id = %d
SELECT pterotype_activities.activity FROM pterotype_outbox
JOIN pterotype_actors
ON pterotype_actors.id = pterotype_outbox.actor_id
JOIN pterotype_activities
ON pterotype_activities.id = pterotype_outbox.activity_id
WHERE pterotype_pterotype_outbox.actor_id = %d
",
$actor_id
) );
@ -123,7 +120,7 @@ function persist_activity( $actor_slug, $activity ) {
$activity = \activities\create_local_activity( $activity );
$activity_id = $wpdb->insert_id;
$actor_id = \actors\get_actor_id( $actor_slug );
$wpdb->insert( 'pterotype_activitypub_outbox', array(
$wpdb->insert( 'pterotype_outbox', array(
'actor_id' => $actor_id,
'activity_id' => $activity_id,
) );