html-admin-page-upgrade.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Admin Database Upgrade
  4. *
  5. * Shows the databse upgrade process.
  6. *
  7. * @date 24/8/18
  8. * @since 5.7.4
  9. * @param void
  10. */
  11. ?>
  12. <style type="text/css">
  13. /* hide steps */
  14. .step-1,
  15. .step-2,
  16. .step-3 {
  17. display: none;
  18. }
  19. </style>
  20. <div id="acf-upgrade-wrap" class="wrap">
  21. <h1><?php _e( 'Upgrade Database', 'acf' ); ?></h1>
  22. <?php if ( acf_has_upgrade() ) : ?>
  23. <p><?php _e( 'Reading upgrade tasks...', 'acf' ); ?></p>
  24. <p class="step-1"><i class="acf-loading"></i> <?php printf( __( 'Upgrading data to version %s', 'acf' ), ACF_VERSION ); ?></p>
  25. <p class="step-2"></p>
  26. <p class="step-3"><?php echo sprintf( __( 'Database upgrade complete. <a href="%s">See what\'s new</a>', 'acf' ), admin_url( 'edit.php?post_type=acf-field-group' ) ); ?></p>
  27. <script type="text/javascript">
  28. (function($) {
  29. var upgrader = new acf.Model({
  30. initialize: function(){
  31. // allow user to read message for 1 second
  32. this.setTimeout( this.upgrade, 1000 );
  33. },
  34. upgrade: function(){
  35. // show step 1
  36. $('.step-1').show();
  37. // vars
  38. var response = '';
  39. var success = false;
  40. // send ajax request to upgrade DB
  41. $.ajax({
  42. url: acf.get('ajaxurl'),
  43. dataType: 'json',
  44. type: 'post',
  45. data: acf.prepareForAjax({
  46. action: 'acf/ajax/upgrade'
  47. }),
  48. success: function( json ){
  49. success = true;
  50. },
  51. error: function( jqXHR, textStatus, errorThrown ){
  52. response = '<?php _e( 'Upgrade failed.', 'acf' ); ?>';
  53. if( error = acf.getXhrError(jqXHR) ) {
  54. response += ' <code>' + error + '</code>';
  55. }
  56. },
  57. complete: this.proxy(function(){
  58. // remove spinner
  59. $('.acf-loading').hide();
  60. // display response
  61. if( response ) {
  62. $('.step-2').show().html( response );
  63. }
  64. // display success
  65. if( success ) {
  66. $('.step-3').show();
  67. }
  68. })
  69. });
  70. }
  71. });
  72. })(jQuery);
  73. </script>
  74. <?php else : ?>
  75. <p><?php _e( 'No updates available.', 'acf' ); ?></p>
  76. <?php endif; ?>
  77. </div>