PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.14.1
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.14.1
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / update / class-hustle-441-migration.php
wordpress-popup / inc / update Last commit date
class-hustle-410-migration.php 5 months ago class-hustle-430-migration.php 3 years ago class-hustle-441-migration.php 3 years ago
class-hustle-441-migration.php
155 lines
1 <?php
2 /**
3 * File for Hustle_441_Migration class.
4 *
5 * @package Hustle
6 * @since 4.4.1
7 */
8
9 /**
10 * Class Hustle_441_Migration.
11 *
12 * This class handles the migration when going to 4.4.1.
13 * The only update here is making the "Triggers" property'
14 * from "behavior" an array instead of a string.
15 *
16 * @since 4.4.1
17 */
18 class Hustle_441_Migration {
19
20 /**
21 * Flag name to mark the migration as "done".
22 *
23 * @since 4.4.1
24 */
25 const MIGRATION_FLAG = '441';
26
27 /**
28 * Run the migration if required.
29 *
30 * @since 4.4.1
31 *
32 * @todo To be abstracted in the base migration class.
33 */
34 public function maybe_migrate() {
35 if ( $this->is_do_migration() ) {
36 $this->do_migration();
37 }
38 }
39
40 /**
41 * Checks whether this migration should be run.
42 *
43 * @since 4.4.1
44 *
45 * @todo To be abstracted in the base migration class.
46 *
47 * @return boolean
48 */
49 private function is_do_migration() {
50 // Bail out if the migration is being forced but it's not 4.4.1.
51 if (
52 filter_input( INPUT_GET, 'run-migration', FILTER_VALIDATE_INT ) &&
53 self::MIGRATION_FLAG !== filter_input( INPUT_GET, 'run-migration', FILTER_SANITIZE_SPECIAL_CHARS )
54 ) {
55 return false;
56 }
57
58 return true;
59 }
60
61 /**
62 * Does the migration to 4.4.1.
63 *
64 * @since 4.4.1
65 */
66 public function do_migration() {
67 global $wpdb;
68
69 $limit = apply_filters( 'hustle_441_migration_limit', 100 );
70
71 do {
72 $offset = get_option( 'hustle_441_migration_offset', 0 );
73 $settings = $this->get_all_hustle_module_behavior_setting( $limit, $offset );
74
75 foreach ( $settings as $meta ) {
76
77 $meta_id = $meta->meta_id;
78 $value = json_decode( $meta->meta_value, true );
79
80 if ( ! empty( $value['triggers'] ) ) {
81
82 // Make the triggers an array to support having multiple.
83 if ( ! is_array( $value['triggers']['trigger'] ) ) {
84
85 if ( 'adblock' === $value['triggers']['trigger'] && '0' === $value['triggers']['on_adblock'] ) {
86 // If "adblock" was selected and "on_adblock" was disabled, disable "adblock".
87 // The old "on_adblock" setting will be unused.
88 $value['triggers']['trigger'] = array();
89
90 } else {
91 // "Trigger" was a string before. We just need to make it an array now.
92 $value['triggers']['trigger'] = array( $value['triggers']['trigger'] );
93 }
94
95 // The on/off setting for delaying the trigger on exit intent will be unused.
96 if ( isset( $value['triggers']['on_exit_intent_delayed'] ) && '0' === $value['triggers']['on_exit_intent_delayed'] ) {
97 $value['triggers']['on_exit_intent_delayed_time'] = '0';
98 }
99
100 // The on/off setting for delaying the trigger on adblock will be unused.
101 if ( isset( $value['triggers']['enable_on_adblock_delay'] ) && '0' === $value['triggers']['enable_on_adblock_delay'] ) {
102 $value['triggers']['on_adblock_delay'] = '0';
103 }
104 }
105 } else {
106 // The default value for 'triggers' was an empty string in old versions.
107 // Remove that troubling value and let the module grab the new defaults.
108 unset( $value['triggers'] );
109 }
110
111 // Save the transformed behavior.
112 $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
113 Hustle_Db::modules_meta_table(),
114 array( 'meta_value' => wp_json_encode( $value ) ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
115 array( 'meta_id' => $meta_id )
116 );
117
118 wp_cache_delete( $meta->module_id, 'hustle_module_meta' );
119 }
120
121 $count_settings = count( $settings );
122 $offset += $limit;
123
124 update_option( 'hustle_441_migration_offset', $offset );
125
126 } while ( $count_settings === $limit );
127
128 Hustle_Migration::migration_passed( self::MIGRATION_FLAG );
129 delete_option( 'hustle_441_migration_offset' );
130 }
131
132 /**
133 * Gets all the stored visibility metas.
134 *
135 * @since 4.1.0
136 *
137 * @param int $limit Query limit.
138 * @param int $offset Query offset.
139 * @return array
140 */
141 private function get_all_hustle_module_behavior_setting( $limit, $offset ) {
142 global $wpdb;
143
144 $modules_table = Hustle_Db::modules_meta_table();
145
146 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
147 $results = $wpdb->get_results(
148 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
149 $wpdb->prepare( "SELECT meta_id, module_id, meta_value FROM {$modules_table} WHERE meta_key = 'settings' LIMIT %d OFFSET %d", intval( $limit ), intval( $offset ) )
150 );
151
152 return $results;
153 }
154 }
155