PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.2
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 3 months ago Exceptions 5 years ago Cancel.php 7 months ago CancelUpdate.php 7 months ago Cloning.php 2 weeks ago CloningProcess.php 1 year ago Data.php 7 months ago Database.php 3 months ago Delete.php 4 months ago Directories.php 4 months ago Files.php 1 week ago Finish.php 2 months ago Job.php 2 weeks ago JobExecutable.php 7 months ago Logs.php 3 years ago PreserveDataFirstStep.php 1 month ago PreserveDataSecondStep.php 1 month ago ProcessLock.php 1 year ago Scan.php 4 months ago SearchReplace.php 5 months ago TotalStepsAreNumberOfTables.php 5 years ago Updating.php 2 weeks ago
CloningProcess.php
101 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 /**
22 * @return void
23 */
24 protected function setupMemoryExhaustFile()
25 {
26 $this->memoryExhaustErrorTmpFile = $this->getMemoryExhaustErrorTmpFile(Cloning::WPSTG_REQUEST);
27 }
28
29 protected function initializeDbObjects()
30 {
31 $this->productionDb = WPStaging::getInstance()->get("wpdb");
32
33 if ($this->isExternalDatabase()) {
34 $this->setExternalDatabase();
35 } else {
36 $this->setLocalDatabase();
37 }
38 }
39
40 protected function setLocalDatabase()
41 {
42 $this->stagingDb = WPStaging::getInstance()->get("wpdb");
43 }
44
45 /**
46 * @return bool
47 */
48 protected function setExternalDatabase()
49 {
50 if ($this->options->databaseSsl && !defined('MYSQL_CLIENT_FLAGS')) {
51 // phpcs:disable PHPCompatibility.Constants.NewConstants.mysqli_client_ssl_dont_verify_server_certFound
52 define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
53 }
54
55 $this->stagingDb = new \wpdb($this->options->databaseUser, str_replace("\\\\", "\\", $this->options->databasePassword), $this->options->databaseDatabase, $this->options->databaseServer);
56
57 if (!is_object($this->stagingDb)) {
58 $this->returnException('Can not create database object.');
59 return false;
60 }
61
62 // Check if there were any error when connecting
63 if (
64 property_exists($this->stagingDb, 'error') &&
65 $this->stagingDb->error instanceof \WP_Error
66 ) {
67 /** @var \WP_Error $wp_error */
68 $wp_error = $this->stagingDb->error;
69 if ($wp_error->get_error_code() === 'db_connect_fail') {
70 $this->returnException(sprintf('Can not connect to external database %s. Reason: %s', $this->options->databaseDatabase, $wp_error->get_error_message()));
71 return false;
72 }
73 }
74
75 $this->stagingDb->select($this->options->databaseDatabase);
76 if (!$this->stagingDb->ready) {
77 if (
78 property_exists($this->stagingDb, 'error') &&
79 $this->stagingDb->error instanceof \WP_Error
80 ) {
81 /** @var \WP_Error $wp_error */
82 $wp_error = $this->stagingDb->error;
83 if ($wp_error->get_error_code() === 'db_select_fail') {
84 $this->returnException($wp_error->get_error_message());
85 exit;
86 }
87
88 // Generic error
89 $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));
90 exit;
91 }
92
93 // Generic error
94 $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));
95 exit;
96 }
97
98 return true;
99 }
100 }
101