PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.0.6
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.0.6
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backend / Modules / Jobs / CloningProcess.php
wp-staging / Backend / Modules / Jobs Last commit date
Cleaners 5 years ago Exceptions 5 years ago Cancel.php 3 years ago CancelUpdate.php 4 years ago Cloning.php 3 years ago CloningProcess.php 3 years ago Data.php 3 years ago Database.php 3 years ago Delete.php 3 years ago Directories.php 2 years ago Files.php 2 years ago Finish.php 2 years ago Job.php 2 years ago JobExecutable.php 3 years ago Logs.php 3 years ago PreserveDataFirstStep.php 3 years ago PreserveDataSecondStep.php 3 years ago ProcessLock.php 3 years ago Scan.php 2 years ago SearchReplace.php 3 years ago TotalStepsAreNumberOfTables.php 5 years ago Updating.php 3 years ago Verify.php 3 years ago
CloningProcess.php
87 lines
1 <?php
2
3 namespace WPStaging\Backend\Modules\Jobs;
4
5 use WPStaging\Core\WPStaging;
6
7 abstract class CloningProcess extends JobExecutable
8 {
9 /**
10 * Can be local or external \wpdb object
11 * @var \wpdb
12 */
13 protected $stagingDb;
14
15 /**
16 * Always be the local \wpdb object
17 * @var \wpdb
18 */
19 protected $productionDb;
20
21 protected function initializeDbObjects()
22 {
23 $this->productionDb = WPStaging::getInstance()->get("wpdb");
24
25 if ($this->isExternalDatabase()) {
26 $this->setExternalDatabase();
27 } else {
28 $this->setLocalDatabase();
29 }
30 }
31
32 protected function setLocalDatabase()
33 {
34 $this->stagingDb = WPStaging::getInstance()->get("wpdb");
35 }
36
37 /**
38 * @return bool
39 */
40 protected function setExternalDatabase()
41 {
42 if ($this->options->databaseSsl && !defined('MYSQL_CLIENT_FLAGS')) {
43 // phpcs:disable PHPCompatibility.Constants.NewConstants.mysqli_client_ssl_dont_verify_server_certFound
44 define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
45 }
46
47 $this->stagingDb = new \wpdb($this->options->databaseUser, str_replace("\\\\", "\\", $this->options->databasePassword), $this->options->databaseDatabase, $this->options->databaseServer);
48
49 // Check if there were any error when connecting
50 if (
51 property_exists($this->stagingDb, 'error') &&
52 $this->stagingDb->error instanceof \WP_Error
53 ) {
54 /** @var \WP_Error $wp_error */
55 $wp_error = $this->stagingDb->error;
56 if ($wp_error->get_error_code() === 'db_connect_fail') {
57 $this->returnException(sprintf('Can not connect to external database %s. Reason: %s', $this->options->databaseDatabase, $wp_error->get_error_message()));
58 return false;
59 }
60 }
61
62 $this->stagingDb->select($this->options->databaseDatabase);
63 if (!$this->stagingDb->ready) {
64 if (
65 property_exists($this->stagingDb, 'error') &&
66 $this->stagingDb->error instanceof \WP_Error
67 ) {
68 /** @var \WP_Error $wp_error */
69 $wp_error = $this->stagingDb->error;
70 if ($wp_error->get_error_code() === 'db_select_fail') {
71 $this->returnException($wp_error->get_error_message());
72 exit;
73 }
74
75 // Generic error
76 $this->returnException(sprintf('Error: Can\'t select database %s. Either it does not exist or you don\'t have privileges to access it.', $this->options->databaseDatabase));
77 exit;
78 }
79
80 // Generic error
81 $this->returnException(sprintf('Error: Can\'t select database %s. Either it does not exist or you don\'t have privileges to access it.', $this->options->databaseDatabase));
82 exit;
83 }
84 return true;
85 }
86 }
87