PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
jetpack / jetpack_vendor / automattic / jetpack-import / src / endpoints / class-end.php

class-end.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at jetpack_vendor/automattic/jetpack-import/src/endpoints/class-end.php

122 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2 /**
3 * End REST route
4 *
5 * @package automattic/jetpack-import
6 */
7
8 namespace Automattic\Jetpack\Import\Endpoints;
9
10 use WP_Error;
11 use WP_REST_Request;
12 use WP_REST_Response;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 0 );
16 }
17
18 /**
19 * Class End
20 *
21 * This class is used to start the import process.
22 */
23 class End extends \WP_REST_Controller {
24
25 /**
26 * Base class
27 */
28 use Import;
29
30 /**
31 * The Import ID add a new item to the schema.
32 */
33 use Import_ID;
34
35 /**
36 * Constructor.
37 */
38 public function __construct() {
39 $this->rest_base = 'end';
40 }
41
42 /**
43 * Get the register route options.
44 *
45 * @see register_rest_route()
46 *
47 * @return array The options.
48 */
49 protected function get_route_options() {
50 return array(
51 array(
52 'methods' => \WP_REST_Server::CREATABLE,
53 'callback' => array( $this, 'cleanup_database' ),
54 'permission_callback' => array( $this, 'import_permissions_callback' ),
55 'args' => array(),
56 ),
57 'schema' => array( $this, 'get_public_item_schema' ),
58 );
59 }
60
61 /**
62 * Retrieves the start values schema, conforming to JSON Schema.
63 *
64 * @return array Item schema data.
65 */
66 public function get_item_schema() {
67 if ( $this->schema ) {
68 return $this->add_additional_fields_schema( $this->schema );
69 }
70
71 $schema = array(
72 '$schema' => 'http://json-schema.org/draft-04/schema#',
73 'title' => 'import-end',
74 'type' => 'object',
75 'properties' => array(
76 'commentmeta_count' => array(
77 'description' => __( 'Comment meta deleted count.', 'jetpack-import' ),
78 'type' => 'integer',
79 'context' => array( 'view' ),
80 'readonly' => true,
81 ),
82 'postmeta_count' => array(
83 'description' => __( 'Post meta deleted count.', 'jetpack-import' ),
84 'type' => 'integer',
85 'context' => array( 'view' ),
86 'readonly' => true,
87 ),
88 'termmeta_count' => array(
89 'description' => __( 'Term meta deleted count.', 'jetpack-import' ),
90 'type' => 'integer',
91 'context' => array( 'view' ),
92 'readonly' => true,
93 ),
94 ),
95 );
96
97 $this->schema = $schema;
98
99 return $this->add_additional_fields_schema( $this->schema );
100 }
101
102 /**
103 * Delete all meta values from database.
104 *
105 * @param WP_REST_Request $request Full details about the request.
106 * @return WP_REST_Response|WP_Error Response object on success, or error object on failure.
107 *
108 * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
109 */
110 public function cleanup_database( $request ) {
111 global $wpdb;
112
113 $where = array( 'meta_key' => $this->import_id_field_name );
114
115 return array(
116 'commentmeta_count' => $wpdb->delete( $wpdb->commentmeta, $where ),
117 'postmeta_count' => $wpdb->delete( $wpdb->postmeta, $where ),
118 'termmeta_count' => $wpdb->delete( $wpdb->termmeta, $where ),
119 );
120 }
121 }
122