diff --git a/composer.json b/composer.json index 991e3b4..94f100f 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "require": { - "singpolyma/openpgp-php": "0.3.*" + "singpolyma/openpgp-php": "0.3.*", + "techcrunch/wp-async-task": "dev-master" } } diff --git a/composer.lock b/composer.lock index e3c440c..4d5bfdb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f89229825d6a5fb0c6b4631f153ace78", + "content-hash": "639c41ba8fc796bb88630bf51bb0ce38", "packages": [ { "name": "phpseclib/phpseclib", @@ -140,12 +140,65 @@ ], "description": "Pure-PHP implementation of the OpenPGP Message Format (RFC 4880)", "time": "2017-04-12T21:23:15+00:00" + }, + { + "name": "techcrunch/wp-async-task", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/techcrunch/wp-async-task.git", + "reference": "9bdbbf9df4ff5179711bb58b9a2451296f6753dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/techcrunch/wp-async-task/zipball/9bdbbf9df4ff5179711bb58b9a2451296f6753dc", + "reference": "9bdbbf9df4ff5179711bb58b9a2451296f6753dc", + "shasum": "" + }, + "require-dev": { + "10up/wp_mock": "dev-master", + "phpunit/phpunit": "*@stable" + }, + "type": "wordpress-plugin", + "autoload": { + "classmap": [ + "wp-async-task.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alex Khadiwala", + "role": "developer" + }, + { + "name": "Nicolas Vincent", + "role": "developer" + }, + { + "name": "Eric Mann", + "email": "eric.mann@10up.com", + "role": "developer" + }, + { + "name": "John P. Bloch", + "email": "john.bloch@10up.com", + "role": "developer" + } + ], + "description": "Run asynchronous tasks for long-running operations in WordPress", + "time": "2016-03-10T17:37:13+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "techcrunch/wp-async-task": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/includes/init.php b/includes/init.php index 56462e1..19d40a5 100644 --- a/includes/init.php +++ b/includes/init.php @@ -7,6 +7,7 @@ require_once plugin_dir_path( __FILE__ ) . 'server/actors.php'; require_once plugin_dir_path( __FILE__ ) . 'schema.php'; require_once plugin_dir_path( __FILE__ ) . 'server/webfinger.php'; require_once plugin_dir_path( __FILE__ ) . 'client/posts.php'; +require_once plugin_dir_path( __FILE__ ) . 'server/async.php'; add_action( 'rest_api_init', function() { \api\register_routes(); @@ -27,6 +28,7 @@ add_action( 'pterotype_init', function() { add_action( 'pterotype_load', function() { \schema\run_migrations(); + \async\init_tasks(); } ); add_action( 'generate_rewrite_rules', '\webfinger\generate_rewrite_rules', 111 ); diff --git a/includes/server/activities/follow.php b/includes/server/activities/follow.php index 0108353..ade8840 100644 --- a/includes/server/activities/follow.php +++ b/includes/server/activities/follow.php @@ -43,10 +43,7 @@ function handle_inbox( $actor_slug, $activity ) { if ( is_wp_error( $accept ) ) { return $accept; } - $res = \outbox\handle_activity( $actor_slug, $accept ); - if ( is_wp_error( $res ) ) { - return $res; - } + do_action( 'pterotype_send_accept', $actor_slug, $accept ); } return $activity; } diff --git a/includes/server/async.php b/includes/server/async.php new file mode 100644 index 0000000..fe90b0d --- /dev/null +++ b/includes/server/async.php @@ -0,0 +1,28 @@ + $actor_slug, 'accept' => $accept ); + } + + protected function run_action() { + $actor_slug = $_POST['actor_slug']; + $accept = $_POST['accept']; + if ( $actor_slug && $accept ) { + sleep( 5 ); + \outbox\handle_activity( $actor_slug, $accept ); + } + } +} + +function init_tasks() { + new Send_Accept_Task(); +} +?> diff --git a/includes/server/outbox.php b/includes/server/outbox.php index 9dce741..6ed999f 100644 --- a/includes/server/outbox.php +++ b/includes/server/outbox.php @@ -24,6 +24,9 @@ require_once plugin_dir_path( __FILE__ ) . 'activities/undo.php'; require_once plugin_dir_path( __FILE__ ) . '../util.php'; function handle_activity( $actor_slug, $activity ) { + \util\log( 'outbox.html', 'Got outbox request', false ); + \util\log_var( 'outbox.html', $actor_slug ); + \util\log_var( 'outbox.html', $activity ); // TODO handle authentication/authorization $activity = \util\dereference_object( $activity ); if ( is_wp_error( $activity ) ) {