1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
<?php
namespace AutomateWoo;
defined( 'ABSPATH' ) || exit;
$plugin_slug = Clean::string( aw_request( 'plugin_slug' ) );
if ( $plugin_slug === AW()->plugin_slug ) { // updating the primary plugin $plugin_name = 'AutomateWoo'; $version = AW()->version; $update_available = Installer::is_database_upgrade_required(); } elseif ( $plugin_slug ) { // updating an addon $addon = Addons::get( $plugin_slug );
if ( ! $addon ) { wp_die( esc_html__( 'Add-on could not be updated', 'automatewoo' ) ); }
$plugin_name = $addon->name; $version = $addon->version; $update_available = $addon->is_database_upgrade_available(); } else { wp_die( 'Missing parameter.' ); }
?>
<div id="automatewoo-upgrade-wrap" class="wrap woocommerce automatewoo-page automatewoo-page--data-upgrade">
<h2><?php /* translators: Plugin name. */ printf( esc_html__( '%s - Database Update', 'automatewoo' ), esc_html( $plugin_name ) ); ?></h2>
<?php if ( $update_available ) : ?>
<p><?php esc_html_e( 'Reading update tasks...', 'automatewoo' ); ?></p>
<p class="show-on-ajax"> <?php /* translators: Version. */ printf( esc_html__( 'Upgrading data to version %s.', 'automatewoo' ), esc_html( $version ) ); ?> <span style="display: none" data-automatewoo-update-items-to-process-text> <?php /* translators: %1$s wrapping span tag, %2$s closing span tag */ printf( esc_html__( 'Approximately %1$s0%2$s items to process.', 'automatewoo' ), '<span data-automatewoo-update-items-to-process-count>', '</span>' ); ?> </span> <span style="display: none" data-automatewoo-update-items-processed-text> <?php /* translators: %1$s wrapping span tag, %2$s closing span tag */ printf( esc_html__( '%1$s0%2$s items processed.', 'automatewoo' ), '<span data-automatewoo-update-items-processed-count>', '</span>' ); ?> </span> <i class="automatewoo-upgrade-loader"></i> </p>
<p class="show-on-complete"><?php esc_html_e( 'Database update complete', 'automatewoo' ); ?>.</p>
<style type="text/css">
/* hide show */ .show-on-ajax, .show-on-complete { display: none; }
</style>
<script type="text/javascript"> (function($) {
var $wrap = $('#automatewoo-upgrade-wrap');
var updater = {
items_processed_count: 0,
items_to_process_count: 0,
init: function(){ // allow user to read message for 1 second setTimeout(function(){ updater.load_items_to_process_count(function() { updater.start(); }); }, 1000); },
start: function(){ $('.show-on-ajax').show(); updater.maybe_reveal_items_to_process_text(); updater.dispatch(); },
dispatch: function() {
$.ajax({ method: 'POST', url: ajaxurl, data: { action: 'aw_database_update', nonce: '<?php echo esc_js( wp_create_nonce( 'automatewoo_database_upgrade' ) ); ?>', plugin_slug: '<?php echo esc_js( $plugin_slug ); ?>' }, success: function (response) {
if ( response.success ) {
if ( response.data.items_processed ) { updater.update_count( response.data.items_processed ); }
if ( response.data.complete ) { updater.complete(); } else { updater.dispatch(); } } else { updater.error( response ); }
} });
},
update_count: function( count ) { updater.items_processed_count += count;
if ( updater.items_processed_count ) { $('[data-automatewoo-update-items-processed-text]').show(); }
$('[data-automatewoo-update-items-processed-count]').text( updater.items_processed_count ); },
/** * Does ajax request to get number of items that need processing. */ load_items_to_process_count: function( callback ) { $.post( ajaxurl, { action: 'aw_database_update_items_to_process_count', plugin_slug: '<?php echo esc_js( $plugin_slug ); ?>', nonce: '<?php echo esc_js( wp_create_nonce( 'aw_database_update_items_to_process_count' ) ); ?>' }, function( response ) { if ( response.success ) { updater.items_to_process_count = response.data.items_to_process; } callback(); } ); },
maybe_reveal_items_to_process_text: function() { if ( updater.items_to_process_count === 0 ) { return; } $('[data-automatewoo-update-items-to-process-text]').show(); $('[data-automatewoo-update-items-to-process-count]').text( updater.items_to_process_count ); },
complete: function() { $('.show-on-complete').show(); $('.automatewoo-upgrade-loader').hide(); },
error: function( response ) { if ( response.data ) { $wrap.append('<p><strong>' + response.data + '</strong></p>'); } $('.automatewoo-upgrade-loader').hide(); } };
updater.init();
})(jQuery); </script>
<?php else : ?>
<p><?php esc_html_e( 'No updates available', 'automatewoo' ); ?>.</p>
<?php endif; ?>
</div>
|