PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / DonationForms / Migrations / CleanMultipleSlashesOnDB.php

CleanMultipleSlashesOnDB.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/DonationForms/Migrations/CleanMultipleSlashesOnDB.php

79 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonationForms\Migrations;
4
5 use Give\DonationForms\ValueObjects\DonationFormMetaKeys;
6 use Give\Framework\Database\DB;
7 use Give\Framework\Migrations\Contracts\Migration;
8
9 /**
10 * @since 3.2.0
11 */
12 class CleanMultipleSlashesOnDB extends Migration
13 {
14 /**
15 * @since 3.2.0
16 */
17 public function run()
18 {
19 $formMetaTable = DB::prefix('give_formmeta');
20
21 /**
22 * For some reason, these 24 backslashes used in the SQL instruction became 12 when we passed it to the $sql var,
23 * and became 6 when it runs on the database, which represents a sequence of only 3 backslashes as we need 2 of
24 * them to escape just 1 as you can check here: https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
25 */
26 $sql = DB::prepare("SELECT * FROM $formMetaTable as fm
27 WHERE fm.meta_key = 'formBuilderSettings' AND fm.meta_value LIKE '%\\\\\\\\\\\\\\\\\\\\\\\\%'");
28
29 $items = DB::get_results($sql);
30
31 foreach ($items as $item) {
32 $settings = $this->cleanMultipleSlashes(json_decode($item->meta_value, true, JSON_UNESCAPED_SLASHES));
33
34 DB::table('give_formmeta')
35 ->where('form_id', $item->form_id)
36 ->where('meta_key', DonationFormMetaKeys::SETTINGS()->getValue())
37 ->update([
38 'meta_value' => json_encode($settings),
39 ]);
40 }
41 }
42
43 /**
44 * @inheritdoc
45 */
46 public static function id()
47 {
48 return 'donation-forms-clean-multiple-slashes-on-db';
49 }
50
51 /**
52 * @inheritdoc
53 */
54 public static function title()
55 {
56 return 'Clean multiple slashes in the formBuilderSettings meta value';
57 }
58
59 /**
60 * @inheritdoc
61 */
62 public static function timestamp()
63 {
64 return strtotime('2023-11-20');
65 }
66
67 /**
68 * @since 3.2.0
69 */
70 public function cleanMultipleSlashes($var)
71 {
72 if (is_array($var)) {
73 return array_map([$this, 'cleanMultipleSlashes'], $var);
74 } else {
75 return is_string($var) ? deslash($var) : $var;
76 }
77 }
78 }
79