From 0aa30c720066b708bea3cbc59121984c35a04ea6 Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Sun, 7 Jun 2015 17:43:06 +0300 Subject: [PATCH] set LF --- bath.php | 450 +++++++++++++++++++++++++++---------------------------- 1 file changed, 225 insertions(+), 225 deletions(-) diff --git a/bath.php b/bath.php index 4062281..e9af193 100644 --- a/bath.php +++ b/bath.php @@ -1,226 +1,226 @@ -prefix . 'batch_operations'; - - $charset_collate = $wpdb->get_charset_collate(); - - $sql = "CREATE TABLE $table_name ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `operations` longtext NOT NULL, - PRIMARY KEY (`id`) - ) $charset_collate AUTO_INCREMENT=1;"; - - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - dbDelta( $sql ); - -} - -/** - * Add backend page without menu item - */ -function batch_operations_add_page() { - add_management_page( 'Batch operations', '', 'edit_posts', 'batch-operations', 'batch_operations_page_view' ); -} - -/** - * View batch operations page - */ -function batch_operations_page_view() { - //WP 3.3 - wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'batch_operations_script', plugin_dir_url('') . 'batch-operations/js/batch.min.js' ); - wp_enqueue_style( 'batch_operations_script', plugin_dir_url('') . 'batch-operations/css/batch.css' ); - $id = ( intval( $_REQUEST["id"] ) < 0 )? 0 : intval( $_REQUEST["id"] ); - ?> - -
- -

-
- -
-
- -
- $id ){ - wp_send_json( array( 'do' => 'finish' ) ); - } - - $current_array = $wpdb->get_var( 'SELECT `operations` FROM `' . $wpdb->prefix . "batch_operations` WHERE `id` = $id;" ); - if ( empty( $current_array ) ) { - wp_send_json( array( 'do' => 'finish' ) ); - } - - $result['do'] = ''; - $start = time() + 1; - $flag = true; - $current_array = unserialize( $current_array ); - - while ($flag) { - //make array of parameters for function - $parameters_array = array(); - if ( isset( $current_array['operations'][0][1] ) ) { - $parameters_array = $current_array['operations'][0][1]; - } - $parameters_array[] = &$current_array['context']; - //run function - call_user_func_array( $current_array['operations'][0][0], $parameters_array ); - - if ( true == $current_array['context']['finished'] ) { - $current_array['context']['sandbox'] = array(); - array_splice( $current_array['operations'], 0, 1 ); - $current_array['current']++; - } - - if ( time() > $start || 0 == count( $current_array['operations'] ) ) { - $flag=false; - } - } - - if ( 0 == count( $current_array['operations'] ) ) { - $result['do']='finish'; - } - - $result['percent'] = round( $current_array['current'] / ($current_array['count'] / 100 ) ); - $result['message'] = $current_array['context']['message']; - - if ( '' == $result['do'] ) { - $wpdb->update( - $wpdb->prefix . 'batch_operations', - array( 'operations' => serialize( $current_array ) ), - array( 'id' => $id ), - array( '%s' ), - array( '%d' ) - ); - } else { - $wpdb->query( 'DELETE FROM `' . $wpdb->prefix . 'batch_operations' . "` WHERE `id`=$id ;" ); - } - - wp_send_json( $result ); -} - - -/** - * Start batch operations - * - *
- * $batch = array(
- *   'title' => t('Exporting'),
- *   'operations' => array(
- *     array('my_function_1', array(123, 'qwe')),
- *     array('my_function_2', array()),
- *   ),
- *   'finished' => 'my_finished_callback',
- * );
- *
- * batch_operations_start($batch);
- * 
- * - *