/var/www/html_fr/wp-content/plugins/yaymail/src/Controllers/MigrationController.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace YayMail\Controllers;

use 
YayMail\Abstracts\BaseController;
use 
YayMail\Models\MigrationModel;
use 
YayMail\Utils\SingletonTrait;
/**
 * Migration Controller
 *
 * @method static MigrationController get_instance()
 */
class MigrationController extends BaseController {
    use 
SingletonTrait;

    
/** @var MigrationModel */
    
private $model;

    private function 
__construct() {
        
$this->model MigrationModel::get_instance();
        
$this->init_hooks();
    }

    private function 
init_hooks() {
        
register_rest_route(
            
YAYMAIL_REST_NAMESPACE,
            
'/migrations/get-onload-data',
            [
                [
                    
'methods'             => \WP_REST_Server::READABLE,
                    
'callback'            => [ $this'exec_get_onload_data' ],
                    
'permission_callback' => [ $this'permission_callback' ],
                ],
            ]
        );
        
register_rest_route(
            
YAYMAIL_REST_NAMESPACE,
            
'/migrations/migrate',
            [
                [
                    
'methods'             => \WP_REST_Server::EDITABLE,
                    
'callback'            => [ $this'exec_migrate' ],
                    
'permission_callback' => [ $this'permission_callback' ],
                ],
            ]
        );
        
register_rest_route(
            
YAYMAIL_REST_NAMESPACE,
            
'/migrations/reset/(?P<backup_name>[a-zA-Z0-9_-]+)',
            [
                [
                    
'methods'             => \WP_REST_Server::EDITABLE,
                    
'callback'            => [ $this'exec_reset' ],
                    
'permission_callback' => [ $this'permission_callback' ],
                    
'args'                => [
                        
'backup_name' => [
                            
'type'     => 'string',
                            
'required' => true,
                        ],
                    ],
                ],
            ]
        );
    }

    public function 
exec_get_onload_data\WP_REST_Request $request ) {
        return 
$this->exec( [ $this'get_onload_data' ], $request );
    }
    public function 
get_onload_data\WP_REST_Request $request ) {
        return 
$this->model->get_onload_data$request );
    }

    public function 
exec_migrate\WP_REST_Request $request ) {
        return 
$this->exec( [ $this'migrate' ], $request );
    }
    public function 
migrate\WP_REST_Request $request ) {
        
$response $this->model->migrate();
        return 
array_merge( [ 'success' => true ], $response );
    }

    public function 
exec_reset\WP_REST_Request $request ) {
        return 
$this->exec( [ $this'reset' ], $request );
    }
    public function 
reset\WP_REST_Request $request ) {
        
$backup_name sanitize_text_field$request->get_param'backup_name' ) );
        
$response    $this->model->reset$backup_name );
        return 
array_merge( [ 'success' => true ], $response );
    }
}