Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Backup_Importer
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 preprocess
n/a
0 / 0
n/a
0 / 0
0
 process_files
n/a
0 / 0
n/a
0 / 0
0
 recreate_database
n/a
0 / 0
n/a
0 / 0
0
 postprocess_database
n/a
0 / 0
n/a
0 / 0
0
 clean_up
n/a
0 / 0
n/a
0 / 0
0
 verify_site_integrity
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Backup_Importer file.
4 *
5 * @package wpcomsh
6 */
7
8namespace Imports;
9
10use WP_Error;
11
12/**
13 * Abstract class representing a backup importer.
14 *
15 * This class provides a common interface for all backup importers.
16 */
17abstract class Backup_Importer {
18    /**
19     * The path to the ZIP or TAR file to be imported.
20     *
21     * @var string
22     */
23    protected $zip_or_tar_file_path;
24
25    /**
26     * The path where the backup will be imported.
27     *
28     * @var string
29     */
30    protected $destination_path;
31
32    /**
33     * The table prefix to use when generating database temporary tables.
34     *
35     * @var string
36     */
37    protected $tmp_prefix;
38
39    /**
40     * The temporary database name.
41     *
42     * @var string
43     */
44    protected $tmp_database;
45
46    /**
47     * Constructor.
48     *
49     * @param string $zip_or_tar_file_path The path to the ZIP or TAR file to be imported.
50     * @param string $destination_path The path where the backup will be imported.
51     * @param string $tmp_prefix       The table prefix to use when importing the database.
52     */
53    public function __construct( string $zip_or_tar_file_path, string $destination_path, string $tmp_prefix ) {
54        $this->zip_or_tar_file_path = $zip_or_tar_file_path;
55        $this->destination_path     = trailingslashit( $destination_path );
56        $this->tmp_prefix           = $tmp_prefix;
57    }
58
59    /**
60     * Preprocess the backup before importing.
61     *
62     * This method should be implemented by subclasses to perform any necessary preprocessing.
63     *
64     * @return bool|WP_Error True on success, or a WP_Error on failure.
65     */
66    abstract public function preprocess();
67
68    /**
69     * Process the files in the backup.
70     *
71     * This method should be implemented by subclasses to process the files in the backup.
72     *
73     * @return bool|WP_Error True on success, or a WP_Error on failure.
74     */
75    abstract public function process_files();
76
77    /**
78     * Recreate the database from the backup.
79     *
80     * This method should be implemented by subclasses to recreate the database from the backup.
81     *
82     * @return bool|WP_Error True on success, or a WP_Error on failure.
83     */
84    abstract public function recreate_database();
85
86    /**
87     * Postprocess the database after importing.
88     *
89     * This method should be implemented by subclasses to perform any necessary postprocessing.
90     *
91     * @return bool|WP_Error True on success, or a WP_Error on failure.
92     */
93    abstract public function postprocess_database();
94
95    /**
96     * Clean up after the import.
97     *
98     * This method should be implemented by subclasses to clean up any temporary files or data.
99     *
100     * @return bool|WP_Error True on success, or a WP_Error on failure.
101     */
102    abstract public function clean_up();
103
104    /**
105     * Verify the integrity of the site after importing.
106     *
107     * This method should be implemented by subclasses to verify the integrity of the site after importing.
108     *
109     * @return bool|WP_Error True on success, or a WP_Error on failure.
110     */
111    abstract public function verify_site_integrity();
112}