assertAdmin(); $file = $request->str( 'file' ); $path = Library::path( $file ); if ( null === $path ) { throw new HttpException( 'om_backup_not_found', esc_html__( 'That backup no longer exists.', 'migratex' ), 404 ); } clearstatcache( true, $path ); $size = (int) filesize( $path ); try { $made = $this->auth()->create( home_url(), array( 'file' => $file, 'size' => $size, 'mtime' => (int) filemtime( $path ), 'chunk_size' => (int) MIGRATEX_REMOTE_CHUNK_SIZE, // the ceiling; the destination may ask for smaller pieces at the handshake. ), get_current_user_id() ); } catch ( \RuntimeException $e ) { throw new HttpException( 'om_remote_insecure', esc_html( $e->getMessage() ), 400 ); } return Response::data( array( 'key' => $made['key'], 'expires_in' => Auth::TTL, 'file' => $file, 'size_human' => Format::bytes( $size ), ) ); } public function revoke( Request $request ): Response { $this->assertAdmin(); $this->auth()->revoke(); return Response::data( array( 'active' => false ) ); } public function status( Request $request ): Response { $this->assertAdmin(); $status = $this->auth()->status(); return Response::data( array( 'active' => null !== $status, 'expires_in' => null === $status ? 0 : $status['expires_in'], 'file' => null === $status ? '' : $status['file'], 'connected' => null !== $status && $status['connected'], 'last_denied' => null === $status ? null : $status['last_denied'], ) ); } public function pull( Request $request ): Response { $this->assertAdmin(); $this->assertNoResetRunning(); return Response::job( PullJob::start( $request->str( 'key' ), get_current_user_id(), $this->store, $this->customRules( $request ) ) ); } /** * @throws HttpException */ private function assertAdmin(): void { if ( ! current_user_can( 'manage_options' ) ) { throw new HttpException( 'om_forbidden', esc_html__( 'You do not have permission to do that.', 'migratex' ), 403 ); } } private function auth(): Auth { return new Auth( new OptionStore() ); } }