M2_Migration_Handler

Prepare upgrade to Membership (free) to Membership2 (free).

Defined (1)

The class is defined in the following location(s).

/app_old/membershipincludes/classes/class-m2-migration-handler.php  
  1. class M2_Migration_Handler { 
  2. const PLUGIN_ID = 'membership2'; 
  3.  
  4. /** 
  5. * User has to confirm update before updating the plugin to this name. 
  6. * I.e. While the NEW plugin keeps its old name no confirmation is displayed 
  7. * but once the new plugin contains this phrase in the project name the 
  8. * migration process begins by displaying a confirmation message. 
  9. */ 
  10. const NEW_PLUGIN_NAME = 'Membership2'; 
  11.  
  12. /** 
  13. * When the big update is ready a flag is stored in site-options table using 
  14. * this option key. 
  15. * After the update the new plugin should remove this site-option again. 
  16. */ 
  17. const TEMP_OPTION_KEY = '_wporg_update_to_m2'; 
  18.  
  19. /** 
  20. * Add hooks to watch all upgrade requests 
  21. */ 
  22. static public function setup() { 
  23. // Display a custom "Update available" message. 
  24. add_action( 'admin_head', array( __CLASS__, 'hook_confirm_message' ) ); 
  25.  
  26. // Ajax handlers. 
  27. add_action( 'wp_ajax_wpmudev-unlock-' . self::PLUGIN_ID, array( __CLASS__, 'ajax_unlock' ) ); 
  28. add_action( 'wp_ajax_wpmudev-remind-' . self::PLUGIN_ID, array( __CLASS__, 'ajax_remind' ) ); 
  29.  
  30. /** 
  31. * Add the admin-notice callback. We do this in the admin_head hook because 
  32. * the WPMUDEV Dashboard disables all admin_notices that are added earlier. 
  33. * Hook: admin_head 
  34. */ 
  35. static public function hook_confirm_message() { 
  36. if ( ! current_user_can( 'update_plugins' ) ) { return; } 
  37.  
  38. $state = self::get_state(); 
  39. if ( ! $state->available ) { return false; } 
  40.  
  41. if ( time() > $state->remind_time ) { 
  42. // If on other pages then WPMUDEV Dashboard we check the remind-time setting. 
  43. add_action( 'all_admin_notices', array( __CLASS__, 'confirm_message' ) ); 
  44.  
  45. /** 
  46. * Handles clicking the "Unlock Update" button in the update dialog. 
  47. * No response is made, but state is updated. 
  48. */ 
  49. static public function ajax_unlock() { 
  50. $state = self::get_state(); 
  51.  
  52. // Switch to the new version. 
  53. membership2_use_m2(); 
  54.  
  55. echo 'OK'; 
  56. exit; 
  57.  
  58. /** 
  59. * Handles clicking the "Remind me later" button in the update dialog. 
  60. * No response is made, but state is updated. 
  61. */ 
  62. static public function ajax_remind() { 
  63. $state = self::get_state(); 
  64.  
  65. // Remind again in one week. 
  66. $state->remind_time = time() + WEEK_IN_SECONDS; 
  67. update_site_option( self::TEMP_OPTION_KEY, $state ); 
  68.  
  69. echo 'OK'; 
  70. exit; 
  71.  
  72. /** 
  73. * Returns the current update state. 
  74. * @return array Update-status information. 
  75. */ 
  76. static protected function get_state() { 
  77. $state = get_site_option( self::TEMP_OPTION_KEY ); 
  78. $default_state = (object) array( 
  79. 'available' => true,  
  80. 'remind_time' => 0,  
  81. ); 
  82.  
  83. if ( ! is_object( $state ) ) { 
  84. $state = $default_state; 
  85. update_site_option( self::TEMP_OPTION_KEY, $state ); 
  86.  
  87. $state = (object) array_merge( (array) $default_state, (array) $state ); 
  88.  
  89. return $state; 
  90.  
  91. /** 
  92. * Display a message that must be confirmed before making the big update 
  93. * available to the user. The message is only displayed when the update is 
  94. * ready. 
  95. */ 
  96. static public function confirm_message() { 
  97. // We output the base CSS here, in case the WPMUDEV Dashboard plugin is deactivated. 
  98. ?> 
  99. <style> 
  100. .wpmudev-new { 
  101. padding: 10px; 
  102. color: #5F5F5F; 
  103. border-radius: 2px; 
  104. text-shadow: 0 1px 0 #FFF; 
  105. -webkit-box-sizing: border-box; 
  106. -moz-box-sizing: border-box; 
  107. box-sizing: border-box; 
  108. background-color: #F0F1F2; 
  109. border: 1px solid #CFDFE5; 
  110. margin: 5px 15px 15px 0; 
  111. position: relative; 
  112. .wpmudev-new h4 { 
  113. margin: 0 0 10px 0; 
  114. font-size: 1.3em; 
  115. font-family: 'Helvetica Neue', helvetica, arial, sans-serif; 
  116. font-weight: 600; 
  117. color: #3C3C3C; 
  118. .wpmudev-new .dev-widget-content > h4 { 
  119. padding-bottom: 10px; 
  120. border-bottom: 1px solid #DCEAF5; 
  121. .wpmudev-new h4 strong { 
  122. color: #053254; 
  123. font-weight: 400; 
  124. font-size: 1.3em; 
  125. padding-left: 20px; 
  126. line-height: 33px; 
  127. .dev-content-wrapper { 
  128. margin-top: 10px; 
  129. .wpmudev-new img { 
  130. float: left; 
  131. margin-right: 20px; 
  132. .dev-cta-wrap { 
  133. text-align: right; 
  134. .dev-cta-wrap .wpmu-button { 
  135. padding: 12px 20px; 
  136. background-color: rgba(0, 0, 0, 0); 
  137. text-decoration: none; 
  138. display: inline-block; 
  139. outline: none; 
  140. font-weight: bold; 
  141. font-family: Helvetica Neue, helvetica, sans-serif !important; 
  142. text-rendering: optimizeLegibility; 
  143. -moz-border-radius: 3px; 
  144. -webkit-border-radius: 3px; 
  145. border-radius: 3px; 
  146. -moz-background-clip: padding; 
  147. -webkit-background-clip: padding-box; 
  148. background-clip: padding-box; 
  149. -moz-box-shadow: 0 1px 0 #001c33, inset 0 1px 0 #004f8c; 
  150. -webkit-box-shadow: 0 1px 0 #001C33, inset 0 1px 0 #004F8C; 
  151. box-shadow: 0 1px 0 #001C33, inset 0 1px 0 #004F8C; 
  152. background-image: -moz-linear-gradient(bottom, #003866 0%, #00487f 100%); 
  153. background-image: -o-linear-gradient(bottom, #003866 0%, #00487f 100%); 
  154. background-image: -webkit-linear-gradient(bottom, #003866 0%, #00487F 100%); 
  155. background-image: linear-gradient(bottom, #003866 0%, #00487f 100%); 
  156. color: #E2ECF4; 
  157. font-size: 14px; 
  158. text-shadow: 0 -1px 0 #002A4C; 
  159. border: none; 
  160. -webkit-font-smoothing: antialiased; 
  161. .dev-cta-wrap .wpmu-button:hover,  
  162. .dev-cta-wrap .wpmu-button:focus,  
  163. .dev-cta-wrap .wpmu-button:active { 
  164. color: #FFF; 
  165. </style> 
  166. <div class="wpmudev-new notice" id="message-<?php echo self::PLUGIN_ID; ?>"> 
  167. <div class="dev-widget-content"> 
  168. <h4> 
  169. <strong><?php _e( 'Membership2 Is Available', 'membership' ); ?></strong> 
  170. </h4> 
  171.  
  172. <div class="dev-content-wrapper"> 
  173. <img src="https://premium.wpmudev.org/wp-content/uploads/2014/10/Product-Content-280x158.png" width="186" height="105" style="margin-bottom:20px;"/> 
  174.  
  175. <h4><?php _e( 'The Best Membership Plugin You Ever Used!', 'membership' ); ?></h4> 
  176.  
  177. <p> 
  178. <?php _e( 'Membership2 is a <strong>completely rewritten plugin</strong> with a brand new user interface and new features.<br>We improved workflows and data structure to make the plugin as simple and easy to use as possible for you!', 'membership' ); ?> 
  179. </p> 
  180. <p> 
  181. <?php _e( 'When you update to the new version we will migrate your Subscription plans and Members to the new data structure automatically.<br>However, the protection rules cannot be migrated. So you have to manually <strong>set up all protection rules again</strong> after the update.', 'membership' ); ?><small><sup>*</sup></small><br /> 
  182. <?php printf( __( '%sRead more about the new version%s on our website!', 'membership' ), '<a href="http://premium.wpmudev.org/project/membership" target="_blank">', '</a>' ); ?> 
  183. </p> 
  184.  
  185. <div class="dev-cta-wrap"> 
  186. <a href="#remind-me-later" id="wpmudev-remind-<?php echo self::PLUGIN_ID; ?>"><?php 
  187. _e( 'Remind me in a few days', 'membership' ); 
  188. ?></a> 
  189.   
  190. <a href="#update-now" id="wpmudev-unlock-<?php echo self::PLUGIN_ID; ?>" class="wpmu-button"><?php 
  191. _e( 'I understand. <u>Switch to Membership2 now</u>!', 'membership' ); 
  192. ?><small><sup>*</sup></small></a> 
  193. </div> 
  194. <p style="text-align:right"> 
  195. <small><sup>*</sup> <?php _e( 'When you switch to Membership2 your data is migrated and you need to set up your protection rules again. Until this is completed your content is unprotected.', 'membership' ); ?></small> 
  196. </p> 
  197. </div> 
  198.  
  199. <div class="clear"></div> 
  200. </div> 
  201. </div> 
  202. <?php 
  203. self::confirm_scripts(); 
  204.  
  205. /** 
  206. * Outputs javascript that handles the confirm/remind-me-later clicks. 
  207. */ 
  208. static protected function confirm_scripts() { 
  209. global $wpmudev_un; 
  210. ?> 
  211. <script> 
  212. (function() { 
  213. var unlock = jQuery( '#wpmudev-unlock-<?php echo self::PLUGIN_ID; ?>' ),  
  214. remind = jQuery( '#wpmudev-remind-<?php echo self::PLUGIN_ID; ?>' ),  
  215. message = jQuery( '#message-<?php echo self::PLUGIN_ID; ?>' ); 
  216.  
  217. function confirmed() { 
  218. message.detach(); 
  219. window.location.reload(); 
  220. function postponed() { 
  221. message.detach(); 
  222.  
  223. unlock.click(function() { jQuery.post(window.ajaxurl, {action:jQuery(this).attr( 'id' )}, confirmed )}); 
  224. remind.click(function() { jQuery.post(window.ajaxurl, {action:jQuery(this).attr( 'id' )}, postponed )}); 
  225. })(); 
  226. </script> 
  227. <?php 
  228. };