PluginProbe ʕ •ᴥ•ʔ
Meta for WooCommerce / 1.11.3
Meta for WooCommerce v1.11.3
3.7.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.5.0 2.5.1 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.18 2.6.19 2.6.2 2.6.20 2.6.21 2.6.22 2.6.23 2.6.24 2.6.25 2.6.26 2.6.27 2.6.28 2.6.29 2.6.3 2.6.30 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.4.0 3.4.1 3.4.10 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.10 3.5.11 3.5.12 3.5.13 3.5.14 3.5.15 3.5.16 3.5.17 3.5.18 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0
facebook-for-woocommerce / includes / Lifecycle.php
facebook-for-woocommerce / includes Last commit date
Integrations 6 years ago Products 6 years ago Utilities 6 years ago test 6 years ago AJAX.php 6 years ago Admin.php 6 years ago Lifecycle.php 6 years ago Products.php 6 years ago fbasync.php 6 years ago fbbackground.php 6 years ago fbgraph.php 6 years ago fbinfobanner.php 6 years ago fbproduct.php 6 years ago fbproductfeed.php 6 years ago fbutils.php 6 years ago fbwpml.php 6 years ago
Lifecycle.php
238 lines
1 <?php
2 /**
3 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
4 *
5 * This source code is licensed under the license found in the
6 * LICENSE file in the root directory of this source tree.
7 *
8 * @package FacebookCommerce
9 */
10
11 namespace SkyVerge\WooCommerce\Facebook;
12
13 use SkyVerge\WooCommerce\PluginFramework\v5_5_4 as Framework;
14
15 defined( 'ABSPATH' ) or exit;
16
17 /**
18 * The Facebook for WooCommerce plugin lifecycle handler.
19 *
20 * @since 1.10.0
21 *
22 * @method \WC_Facebookcommerce get_plugin()
23 */
24 class Lifecycle extends Framework\Plugin\Lifecycle {
25
26
27 /**
28 * Lifecycle constructor.
29 *
30 * @since 1.10.0
31 *
32 * @param Framework\SV_WC_Plugin $plugin
33 */
34 public function __construct( $plugin ) {
35
36 parent::__construct( $plugin );
37
38 $this->upgrade_versions = [
39 '1.10.0',
40 '1.10.1',
41 '1.11.0',
42 '1.11.3',
43 ];
44 }
45
46
47 /**
48 * Migrates options from previous versions of the plugin, which did not use the Framework.
49 *
50 * @since 1.10.0
51 */
52 protected function install() {
53
54 /**
55 * Versions prior to 1.10.0 did not set a version option, so the upgrade method needs to be called manually.
56 * We do this by checking first if an old option exists, but a new one doesn't.
57 */
58 if ( get_option( 'woocommerce_facebookcommerce_settings' ) && ! get_option( 'wc_facebook_page_access_token' ) ) {
59
60 $this->upgrade( '1.9.15' );
61 }
62 }
63
64
65 /**
66 * Upgrades to version 1.10.0.
67 *
68 * @since 1.10.0
69 */
70 protected function upgrade_to_1_10_0() {
71
72 $this->migrate_1_9_settings();
73 }
74
75
76 /**
77 * Migrates Facebook for WooCommerce options used in version 1.9.x to the options and settings used in 1.10.x.
78 *
79 * Some users who upgraded from 1.9.x to 1.10.0 ended up with an incomplete upgrade and could have configured the plugin from scratch after that.
80 * This routine will update the options and settings only if a previous value does not exists.
81 *
82 * @since 1.10.1
83 */
84 private function migrate_1_9_settings() {
85
86 $values = get_option( 'woocommerce_facebookcommerce_settings', [] );
87
88 // preserve legacy values
89 if ( false === get_option( 'woocommerce_facebookcommerce_legacy_settings' ) ) {
90 update_option( 'woocommerce_facebookcommerce_legacy_settings', $values );
91 }
92
93 // migrate options from woocommerce_facebookcommerce_settings
94 $options = [
95 'fb_api_key' => \WC_Facebookcommerce_Integration::OPTION_PAGE_ACCESS_TOKEN,
96 'fb_product_catalog_id' => \WC_Facebookcommerce_Integration::OPTION_PRODUCT_CATALOG_ID,
97 'fb_external_merchant_settings_id' => \WC_Facebookcommerce_Integration::OPTION_EXTERNAL_MERCHANT_SETTINGS_ID,
98 'fb_feed_id' => \WC_Facebookcommerce_Integration::OPTION_FEED_ID,
99 'facebook_jssdk_version' => \WC_Facebookcommerce_Integration::OPTION_JS_SDK_VERSION,
100 'pixel_install_time' => \WC_Facebookcommerce_Integration::OPTION_PIXEL_INSTALL_TIME,
101 ];
102
103 foreach ( $options as $old_index => $new_option_name ) {
104
105 if ( isset( $values[ $old_index ] ) && false === get_option( $new_option_name ) ) {
106
107 $new_value = $values[ $old_index ];
108
109 if ( 'pixel_install_time' === $old_index ) {
110
111 // convert to UTC timestamp
112 try {
113 $pixel_install_time = \DateTime::createFromFormat( 'Y-m-d G:i:s', $new_value, new \DateTimeZone( wc_timezone_string() ) );
114 } catch ( \Exception $e ) {
115 $pixel_install_time = false;
116 }
117
118 $new_value = $pixel_install_time instanceof \DateTime ? $pixel_install_time->getTimestamp() : null;
119 }
120
121 update_option( $new_option_name, $new_value );
122 }
123 }
124
125 $new_settings = get_option( 'woocommerce_' . \WC_Facebookcommerce::INTEGRATION_ID . '_settings', [] );
126
127 // migrate settings from woocommerce_facebookcommerce_settings
128 $settings = [
129 'fb_page_id' => \WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PAGE_ID,
130 'fb_pixel_id' => \WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PIXEL_ID,
131 'fb_pixel_use_pii' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_ADVANCED_MATCHING,
132 'is_messenger_chat_plugin_enabled' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_MESSENGER,
133 'msger_chat_customization_locale' => \WC_Facebookcommerce_Integration::SETTING_MESSENGER_LOCALE,
134 'msger_chat_customization_greeting_text_code' => \WC_Facebookcommerce_Integration::SETTING_MESSENGER_GREETING,
135 'msger_chat_customization_theme_color_code' => \WC_Facebookcommerce_Integration::SETTING_MESSENGER_COLOR_HEX,
136 ];
137
138 foreach ( $settings as $old_index => $new_index ) {
139
140 if ( isset( $values[ $old_index ] ) && ! isset( $new_settings[ $new_index ] ) ) {
141 $new_settings[ $new_index ] = $values[ $old_index ];
142 }
143 }
144
145 // migrate settings from standalone options
146 if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) {
147
148 $product_sync_enabled = empty( get_option( 'fb_disable_sync_on_dev_environment', 0 ) );
149
150 $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no';
151 }
152
153 if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_PRODUCT_DESCRIPTION_MODE ] ) ) {
154 $new_settings[ \WC_Facebookcommerce_Integration::SETTING_PRODUCT_DESCRIPTION_MODE ] = ! empty( get_option( 'fb_sync_short_description', 0 ) ) ? \WC_Facebookcommerce_Integration::PRODUCT_DESCRIPTION_MODE_SHORT : \WC_Facebookcommerce_Integration::PRODUCT_DESCRIPTION_MODE_STANDARD;
155 }
156
157 if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] ) ) {
158
159 $autosync_time = get_option( 'woocommerce_fb_autosync_time' );
160 $parsed_time = ! empty( $autosync_time ) ? strtotime( $autosync_time ) : false;
161 $resync_offset = null;
162
163 if ( false !== $parsed_time ) {
164
165 $midnight = ( new \DateTime() )->setTimestamp( $parsed_time )->setTime( 0, 0, 0 );
166
167 $resync_offset = $parsed_time - $midnight->getTimestamp();
168 }
169
170 $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] = $resync_offset;
171 }
172
173 // maybe remove old settings entries
174 $old_indexes = array_merge( array_keys( $options ), array_keys( $settings ), [ 'fb_settings_heading', 'fb_upload_id', 'upload_end_time' ] );
175
176 foreach ( $old_indexes as $old_index ) {
177 unset( $new_settings[ $old_index ] );
178 }
179
180 update_option( 'woocommerce_' . \WC_Facebookcommerce::INTEGRATION_ID . '_settings', $new_settings );
181
182 // schedule the next product resync action
183 if ( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] && 'yes' === $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) {
184
185 $integration = $this->get_plugin()->get_integration();
186
187 if ( ! $integration->is_resync_scheduled() ) {
188 $integration->schedule_resync( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] );
189 }
190 }
191 }
192
193
194 /**
195 * Upgrades to version 1.10.1.
196 *
197 * @since 1.10.1
198 */
199 protected function upgrade_to_1_10_1() {
200
201 $this->migrate_1_9_settings();
202 }
203
204
205 /**
206 * Upgrades to version 1.11.0.
207 *
208 * @since 1.11.0
209 */
210 protected function upgrade_to_1_11_0() {
211
212 $settings = get_option( 'woocommerce_' . \WC_Facebookcommerce::INTEGRATION_ID . '_settings', [] );
213
214 // moves the upload ID to a standalone option
215 if ( ! empty( $settings['fb_upload_id'] ) ) {
216 $this->get_plugin()->get_integration()->update_upload_id( $settings['fb_upload_id'] );
217 }
218 }
219
220
221 /**
222 * Upgrades to version 1.11.3.
223 *
224 * @since 1.11.3-dev.2
225 */
226 protected function upgrade_to_1_11_3() {
227
228 if ( $handler = $this->get_plugin()->get_background_disable_virtual_products_sync_instance() ) {
229
230 // create_job() expects an non-empty array of attributes
231 $handler->create_job( [ 'created_at' => current_time( 'mysql' ) ] );
232 $handler->dispatch();
233 }
234 }
235
236
237 }
238