diff options
Diffstat (limited to 'plugins/jetpack/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php')
-rw-r--r-- | plugins/jetpack/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/plugins/jetpack/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php b/plugins/jetpack/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php new file mode 100644 index 00000000..da71873f --- /dev/null +++ b/plugins/jetpack/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php @@ -0,0 +1,68 @@ +<?php +/** + * IXR_ClientMulticall + * + * @package automattic/jetpack-connection + * + * @since 1.5 + * @since 7.7 Moved to the jetpack-connection package. + */ + +/** + * A Jetpack implementation of the WordPress core IXR client, capable of multiple calls in a single request. + */ +class Jetpack_IXR_ClientMulticall extends Jetpack_IXR_Client { + /** + * Storage for the IXR calls. + * + * @var array + */ + public $calls = array(); + + /** + * Add a IXR call to the client. + * First argument is the method name. + * The rest of the arguments are the params specified to the method. + */ + public function addCall() { + $args = func_get_args(); + $method_name = array_shift( $args ); + $struct = array( + 'methodName' => $method_name, + 'params' => $args, + ); + $this->calls[] = $struct; + } + + /** + * Perform the IXR multicall request. + * + * @return bool True if request succeeded, false otherwise. + */ + public function query() { + usort( $this->calls, array( $this, 'sort_calls' ) ); + + // Prepare multicall, then call the parent::query() method. + return parent::query( 'system.multicall', $this->calls ); + } + + /** + * Sort the IXR calls. + * Make sure syncs are always done first. + * + * @param array $a First call in the sorting iteration. + * @param array $b Second call in the sorting iteration. + * @return int Result of the sorting iteration. + */ + public function sort_calls( $a, $b ) { + if ( 'jetpack.syncContent' === $a['methodName'] ) { + return -1; + } + + if ( 'jetpack.syncContent' === $b['methodName'] ) { + return 1; + } + + return 0; + } +} |