2022-09-30 01:46:42 +02:00
|
|
|
<?php
|
2022-10-05 21:58:12 +02:00
|
|
|
namespace Activitypub\Tools;
|
2022-09-30 01:46:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ActivityPub Migrate DB-Class
|
|
|
|
*
|
|
|
|
* @author Django Doucet
|
|
|
|
*/
|
|
|
|
class Posts {
|
|
|
|
|
|
|
|
/**
|
2022-10-05 21:58:12 +02:00
|
|
|
* Marks ActivityPub Posts for backwards compatibility
|
2022-09-30 01:46:42 +02:00
|
|
|
*/
|
2022-10-05 21:58:12 +02:00
|
|
|
public static function mark_posts_to_migrate() {
|
2022-09-30 01:46:42 +02:00
|
|
|
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
|
|
|
|
$args = array(
|
|
|
|
'numberposts' => -1,
|
|
|
|
'post_type' => $post_types,
|
|
|
|
'order' => 'ASC',
|
|
|
|
);
|
|
|
|
$posts_to_migrate = \get_posts( $args );
|
|
|
|
foreach ( $posts_to_migrate as $post ) {
|
|
|
|
$permalink = \get_permalink( $post->ID );
|
|
|
|
\update_post_meta( $post->ID, '_activitypub_permalink_compat', $permalink );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 21:58:12 +02:00
|
|
|
public static function get_posts_to_migrate() {
|
2022-09-30 01:46:42 +02:00
|
|
|
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
|
|
|
|
$args = array(
|
|
|
|
'numberposts' => -1,
|
|
|
|
'post_type' => $post_types,
|
|
|
|
'meta_key' => '_activitypub_permalink_compat',
|
|
|
|
'order' => 'ASC',
|
|
|
|
);
|
|
|
|
$posts_to_migrate = \get_posts( $args );
|
|
|
|
return $posts_to_migrate;
|
|
|
|
}
|
|
|
|
|
2022-10-05 21:58:12 +02:00
|
|
|
public static function count_posts_to_migrate() {
|
|
|
|
$posts = self::get_posts_to_migrate();
|
2022-09-30 01:46:42 +02:00
|
|
|
return \count( $posts );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* migrate_post
|
2022-10-02 06:49:48 +02:00
|
|
|
* Federate Delete
|
|
|
|
* Federate Announce
|
|
|
|
*
|
|
|
|
* @param str post_url (_activitypub_permalink_compat)
|
|
|
|
* @param str post_author (user_id)
|
|
|
|
*/
|
|
|
|
public static function migrate_post( $post_url, $post_author ) {
|
|
|
|
self::delete_url( $post_url, $post_author );
|
2022-10-05 21:58:12 +02:00
|
|
|
self::announce_url( $post_url, $post_author );
|
2022-10-02 06:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* announce_url
|
|
|
|
* send Announce (obj)
|
2022-09-30 01:46:42 +02:00
|
|
|
*
|
2022-10-02 06:49:48 +02:00
|
|
|
* @param str post_url (post_id)
|
2022-10-05 21:58:12 +02:00
|
|
|
* @param int user_id
|
2022-09-30 01:46:42 +02:00
|
|
|
*/
|
2022-10-05 21:58:12 +02:00
|
|
|
public static function announce_url( $post_url, $user_id ) {
|
|
|
|
\wp_schedule_single_event( \time(), 'activitypub_send_announce_activity', array( $post_url, $user_id ) );
|
2022-10-02 06:49:48 +02:00
|
|
|
}
|
2022-09-30 01:46:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* delete_url
|
|
|
|
* Send a Delete activity to the Fediverse
|
|
|
|
*
|
2022-10-02 06:49:48 +02:00
|
|
|
* @param str post_url (_activitypub_permalink_compat)
|
|
|
|
* @param str post_author (user_id)
|
2022-09-30 01:46:42 +02:00
|
|
|
*/
|
2022-10-02 06:49:48 +02:00
|
|
|
public static function delete_url( $post_url, $post_author ) {
|
|
|
|
\wp_schedule_single_event( \time(), 'activitypub_send_delete_url_activity', array( $post_url, $post_author ) );
|
|
|
|
}
|
2022-09-30 01:46:42 +02:00
|
|
|
}
|