PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.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 2 years ago CancelUpdate.php 2 years ago Cloning.php 2 years ago CloningProcess.php 2 years ago Data.php 2 years ago Database.php 2 years ago Delete.php 2 years ago Directories.php 2 years ago Files.php 2 years ago Finish.php 1 year ago Job.php 2 years ago JobExecutable.php 2 years ago Logs.php 3 years ago PreserveDataFirstStep.php 3 years ago PreserveDataSecondStep.php 2 years ago ProcessLock.php 2 years ago Scan.php 2 years ago SearchReplace.php 2 years ago TotalStepsAreNumberOfTables.php 5 years ago Updating.php 2 years ago
CloningProcess.php
96 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 // Check if there were any error when connecting
58 if (
59 property_exists($this->stagingDb, 'error') &&
60 $this->stagingDb->error instanceof \WP_Error
61 ) {
62 /** @var \WP_Error $wp_error */
63 $wp_error = $this->stagingDb->error;
64 if ($wp_error->get_error_code() === 'db_connect_fail') {
65 $this->returnException(sprintf('Can not connect to external database %s. Reason: %s', $this->options->databaseDatabase, $wp_error->get_error_message()));
66 return false;
67 }
68 }
69
70 $this->stagingDb->select($this->options->databaseDatabase);
71 if (!$this->stagingDb->ready) {
72 if (
73 property_exists($this->stagingDb, 'error') &&
74 $this->stagingDb->error instanceof \WP_Error
75 ) {
76 /** @var \WP_Error $wp_error */
77 $wp_error = $this->stagingDb->error;
78 if ($wp_error->get_error_code() === 'db_select_fail') {
79 $this->returnException($wp_error->get_error_message());
80 exit;
81 }
82
83 // Generic error
84 $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));
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 return true;
94 }
95 }
96