| @@ -38,8 +38,14 @@ | ||
| 38 | 38 | sortList: [[0,0]], |
| 39 | 39 | headers: {6: {sorter: false}} |
| 40 | 40 | }); |
| 41 | 41 | } |
| 42 | + | |
| 43 | + // unhide queuerunner button conditionally (we don't want people running the queue continuously) and attach event to it. | |
| 44 | + if (queueBodyEl > 4 || ( queueBodyEl > 0 && jQuery('#rules > tr').length < 1 ) ) { | |
| 45 | + jQuery('#queuerunner-container').show(); | |
| 46 | + jQuery("#queuerunner").click(function(){queuerunner();}); | |
| 47 | + } | |
| 42 | 48 | }); |
| 43 | 49 | } |
| 44 | 50 | |
| 45 | 51 | // Render the queue in a table |
| @@ -56,8 +62,13 @@ | ||
| 56 | 62 | rbtn = false; |
| 57 | 63 | dbtn = false; |
| 58 | 64 | hbtn = false; |
| 59 | 65 | |
| 66 | + // don't list jobs that don't have a type, they are irrelevant and this also avoids "type.replace is not a function". | |
| 67 | + if ( type == false ) { | |
| 68 | + return; | |
| 69 | + } | |
| 70 | + | |
| 60 | 71 | // Prepare job statuses |
| 61 | 72 | if (keys.jqstat === 'NEW') { |
| 62 | 73 | // Status: NEW (N, sort order 1) |
| 63 | 74 | status = '<span class="hidden">1</span>N'; |
| @@ -204,8 +215,28 @@ | ||
| 204 | 215 | if ( $ao_ccss_debug ) { |
| 205 | 216 | echo "console.log('Updated Queue Object:', queue);\n"; |
| 206 | 217 | } |
| 207 | 218 | ?> |
| 219 | +} | |
| 220 | + | |
| 221 | +// Run the queue manually (in case of cron issues/ impatient users). | |
| 222 | +function queuerunner() { | |
| 223 | + var data = { | |
| 224 | + 'action': 'ao_ccss_queuerunner', | |
| 225 | + 'ao_ccss_queuerunner_nonce': '<?php echo wp_create_nonce( 'ao_ccss_queuerunner_nonce' ); ?>', | |
| 226 | + }; | |
| 227 | + | |
| 228 | + jQuery.post(ajaxurl, data, function(response) { | |
| 229 | + response_array=JSON.parse(response); | |
| 230 | + if (response_array['code'] == 200) { | |
| 231 | + displayNotice( '<?php _e( 'Queue processed, reloading page.', 'autoptimize' ); ?>', 'success' ) | |
| 232 | + setTimeout(window.location.reload.bind(window.location), 1.5*1000); | |
| 233 | + } else if ( response_array['code'] == 302 ) { | |
| 234 | + displayNotice( '<?php _e( 'The queue is locked, retry in a couple of minutes. If this problem persists and the queue is not moving at all remove the <code>wp-content/uploads/ao_ccss/queue.lock</code> file.', 'autoptimize' ); ?>', 'warning' ) | |
| 235 | + } else { | |
| 236 | + displayNotice( '<?php _e( 'Could not process queue.', 'autoptimize' ); ?>', 'error' ) | |
| 237 | + } | |
| 238 | + }); | |
| 208 | 239 | } |
| 209 | 240 | |
| 210 | 241 | // Convert epoch to date for job times |
| 211 | 242 | function EpochToDate(epoch) { |