updated plugin ActivityPub version 3.3.3

This commit is contained in:
2024-10-09 12:44:17 +00:00
committed by Gitium
parent fb4b27bbc6
commit c54fa007bd
106 changed files with 7070 additions and 2918 deletions

View File

@ -1,8 +1,12 @@
<?php
/**
* Migration class file.
*
* @package Activitypub
*/
namespace Activitypub;
use Activitypub\Activitypub;
use Activitypub\Model\Blog;
use Activitypub\Collection\Followers;
/**
@ -12,7 +16,7 @@ use Activitypub\Collection\Followers;
*/
class Migration {
/**
* Initialize the class, registering WordPress hooks
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action( 'activitypub_migrate', array( self::class, 'async_migration' ) );
@ -43,8 +47,6 @@ class Migration {
/**
* Locks the database migration process to prevent simultaneous migrations.
*
* @return void
*/
public static function lock() {
\update_option( 'activitypub_migration_lock', \time() );
@ -52,8 +54,6 @@ class Migration {
/**
* Unlocks the database migration process.
*
* @return void
*/
public static function unlock() {
\delete_option( 'activitypub_migration_lock' );
@ -110,13 +110,13 @@ class Migration {
$version_from_db = self::get_version();
// check for inital migration
// Check for inital migration.
if ( ! $version_from_db ) {
self::add_default_settings();
$version_from_db = self::get_target_version();
}
// schedule the async migration
// Schedule the async migration.
if ( ! \wp_next_scheduled( 'activitypub_migrate', $version_from_db ) ) {
\wp_schedule_single_event( \time(), 'activitypub_migrate', array( $version_from_db ) );
}
@ -132,6 +132,9 @@ class Migration {
if ( version_compare( $version_from_db, '2.3.0', '<' ) ) {
self::migrate_from_2_2_0();
}
if ( version_compare( $version_from_db, '3.0.0', '<' ) ) {
self::migrate_from_2_6_0();
}
update_option( 'activitypub_db_version', self::get_target_version() );
@ -151,15 +154,15 @@ class Migration {
/**
* Updates the custom template to use shortcodes instead of the deprecated templates.
*
* @return void
*/
private static function migrate_from_0_16() {
// Get the custom template.
$old_content = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
// If the old content exists but is a blank string, we're going to need a flag to updated it even
// after setting it to the default contents.
/*
* If the old content exists but is a blank string, we're going to need a flag to updated it even
* after setting it to the default contents.
*/
$need_update = false;
// If the old contents is blank, use the defaults.
@ -187,12 +190,10 @@ class Migration {
}
/**
* Updates the DB-schema of the followers-list
*
* @return void
* Updates the DB-schema of the followers-list.
*/
public static function migrate_from_0_17() {
// migrate followers
// Migrate followers.
foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
$followers = get_user_meta( $user_id, 'activitypub_followers', true );
@ -207,9 +208,7 @@ class Migration {
}
/**
* Clear the cache after updating to 1.3.0
*
* @return void
* Clear the cache after updating to 1.3.0.
*/
private static function migrate_from_1_2_0() {
$user_ids = \get_users(
@ -225,9 +224,7 @@ class Migration {
}
/**
* Unschedule Hooks after updating to 2.0.0
*
* @return void
* Unschedule Hooks after updating to 2.0.0.
*/
private static function migrate_from_2_0_0() {
wp_clear_scheduled_hook( 'activitypub_send_post_activity' );
@ -246,42 +243,84 @@ class Migration {
/**
* Add the ActivityPub capability to all users that can publish posts
* Delete old meta to store followers
*
* @return void
* Delete old meta to store followers.
*/
private static function migrate_from_2_2_0() {
// add the ActivityPub capability to all users that can publish posts
// Add the ActivityPub capability to all users that can publish posts.
self::add_activitypub_capability();
}
/**
* Set the defaults needed for the plugin to work
* Rename DB fields.
*/
private static function migrate_from_2_6_0() {
wp_cache_flush();
self::update_usermeta_key( 'activitypub_user_description', 'activitypub_description' );
self::update_options_key( 'activitypub_blog_user_description', 'activitypub_blog_description' );
self::update_options_key( 'activitypub_blog_user_identifier', 'activitypub_blog_identifier' );
}
/**
* Set the defaults needed for the plugin to work.
*
* * Add the ActivityPub capability to all users that can publish posts
*
* @return void
* Add the ActivityPub capability to all users that can publish posts.
*/
public static function add_default_settings() {
self::add_activitypub_capability();
}
/**
* Add the ActivityPub capability to all users that can publish posts
*
* @return void
* Add the ActivityPub capability to all users that can publish posts.
*/
private static function add_activitypub_capability() {
// get all WP_User objects that can publish posts
// Get all WP_User objects that can publish posts.
$users = \get_users(
array(
'capability__in' => array( 'publish_posts' ),
)
);
// add ActivityPub capability to all users that can publish posts
// Add ActivityPub capability to all users that can publish posts.
foreach ( $users as $user ) {
$user->add_cap( 'activitypub' );
}
}
/**
* Rename meta keys.
*
* @param string $old_key The old comment meta key.
* @param string $new_key The new comment meta key.
*/
private static function update_usermeta_key( $old_key, $new_key ) {
global $wpdb;
$wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->usermeta,
array( 'meta_key' => $new_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
array( 'meta_key' => $old_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
array( '%s' ),
array( '%s' )
);
}
/**
* Rename option keys.
*
* @param string $old_key The old option key.
* @param string $new_key The new option key.
*/
private static function update_options_key( $old_key, $new_key ) {
global $wpdb;
$wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->options,
array( 'option_name' => $new_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
array( 'option_name' => $old_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
array( '%s' ),
array( '%s' )
);
}
}