PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
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 / Framework / Database / OptionPreservationHandler.php
wp-staging / Framework / Database Last commit date
Exporter 1 day ago QueryBuilder 1 day ago CustomTable.php 1 day ago DbInfo.php 1 day ago ExcludedTables.php 1 day ago ExternalDatabaseConfiguration.php 1 day ago OptionPreservationHandler.php 1 day ago SearchReplace.php 1 day ago SelectedTables.php 1 day ago TableDto.php 1 day ago TableService.php 1 day ago TablesRenamer.php 1 day ago WpDbInfo.php 1 day ago WpOptionsInfo.php 1 day ago iDbInfo.php 2 years ago
OptionPreservationHandler.php
96 lines
1 <?php
2
3 namespace WPStaging\Framework\Database;
4
5
6
7
8
9 class OptionPreservationHandler
10 {
11 private $productionDb;
12
13
14
15
16
17 public function getLikeStatement(array $optionsNameToPreserve): string
18 {
19 $optionsToPreserveEscaped = esc_sql($optionsNameToPreserve);
20
21 $likeStatement = '';
22 $first = true;
23 foreach ($optionsToPreserveEscaped as $option) {
24 if ($first) {
25 $likeStatement .= " option_name LIKE '$option'";
26 $first = false;
27 } else {
28 $likeStatement .= " OR option_name LIKE '$option'";
29 }
30 }
31
32 return $likeStatement;
33 }
34
35
36
37
38
39
40
41 public function getOptionsDataToPreserve(string $whereCondition, string $optionsTable)
42 {
43 return $this->productionDb->get_results(
44 sprintf(
45 "SELECT * FROM `$optionsTable` WHERE %s",
46 $whereCondition
47 ),
48 ARRAY_A
49 );
50 }
51
52
53
54
55
56
57 public function createInsertQuery(array $optionToPreserveData, string $optionsTableName): string
58 {
59 $sql = '';
60 foreach ($optionToPreserveData as $option) {
61 $sql .= $this->productionDb->prepare(
62 "INSERT INTO `$optionsTableName` ( `option_id`, `option_name`, `option_value`, `autoload` ) VALUES ( NULL , %s, %s, %s );\n",
63 $option['option_name'],
64 $option['option_value'],
65 $option['autoload']
66 );
67 }
68
69 return $sql;
70 }
71
72
73
74
75
76
77 public function deleteFromTable(string $whereCondition, string $tableName)
78 {
79 return $this->productionDb->query(
80 sprintf(
81 "DELETE FROM `$tableName` WHERE %s",
82 $whereCondition
83 )
84 );
85 }
86
87
88
89
90
91 public function setProductionDb($db)
92 {
93 $this->productionDb = $db;
94 }
95 }
96