rename
Этот коммит содержится в:
родитель
4256c42432
Коммит
fa9f25a253
36
bath.php
36
bath.php
@ -81,48 +81,48 @@ function batch_operations_process () {
|
|||||||
wp_send_json( array( 'do' => 'finish' ) );
|
wp_send_json( array( 'do' => 'finish' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$carr = $wpdb->get_var( 'SELECT `operations` FROM `' . $wpdb->prefix . "batch_operations` WHERE `id` = $id;" );
|
$current_array = $wpdb->get_var( 'SELECT `operations` FROM `' . $wpdb->prefix . "batch_operations` WHERE `id` = $id;" );
|
||||||
if ( empty( $carr ) ) {
|
if ( empty( $current_array ) ) {
|
||||||
wp_send_json( array( 'do' => 'finish' ) );
|
wp_send_json( array( 'do' => 'finish' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['do'] = '';
|
$result['do'] = '';
|
||||||
$start = time() + 1;
|
$start = time() + 1;
|
||||||
$flag = true;
|
$flag = true;
|
||||||
$carr = unserialize( $carr );
|
$current_array = unserialize( $current_array );
|
||||||
|
|
||||||
while ($flag) {
|
while ($flag) {
|
||||||
//make array of parameters for function
|
//make array of parameters for function
|
||||||
$arr = array();
|
$parameters_array = array();
|
||||||
if ( isset( $carr['operations'][0][1] ) ) {
|
if ( isset( $current_array['operations'][0][1] ) ) {
|
||||||
$arr = $carr['operations'][0][1];
|
$parameters_array = $current_array['operations'][0][1];
|
||||||
}
|
}
|
||||||
$arr[] = &$carr['context'];
|
$parameters_array[] = &$current_array['context'];
|
||||||
//run function
|
//run function
|
||||||
call_user_func_array( $carr['operations'][0][0], $arr );
|
call_user_func_array( $current_array['operations'][0][0], $parameters_array );
|
||||||
|
|
||||||
if ( true == $carr['context']['finished'] ) {
|
if ( true == $current_array['context']['finished'] ) {
|
||||||
$carr['context']['sandbox'] = array();
|
$current_array['context']['sandbox'] = array();
|
||||||
array_splice( $carr['operations'], 0, 1 );
|
array_splice( $current_array['operations'], 0, 1 );
|
||||||
$carr['current']++;
|
$current_array['current']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( time() > $start || 0 == count($carr['operations']) ) {
|
if ( time() > $start || 0 == count( $current_array['operations'] ) ) {
|
||||||
$flag=false;
|
$flag=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 == count($carr['operations']) ) {
|
if ( 0 == count( $current_array['operations'] ) ) {
|
||||||
$result['do']='finish';
|
$result['do']='finish';
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['percent'] = round( $carr['current'] / ($carr['count'] /100 ) );
|
$result['percent'] = round( $current_array['current'] / ($current_array['count'] / 100 ) );
|
||||||
$result['message'] = $carr['context']['message'];
|
$result['message'] = $current_array['context']['message'];
|
||||||
|
|
||||||
if ( '' == $result['do'] ) {
|
if ( '' == $result['do'] ) {
|
||||||
$wpdb->update(
|
$wpdb->update(
|
||||||
$wpdb->prefix . 'batch_operations',
|
$wpdb->prefix . 'batch_operations',
|
||||||
array( 'operations' => serialize( $carr ) ),
|
array( 'operations' => serialize( $current_array ) ),
|
||||||
array( 'id' => $id ),
|
array( 'id' => $id ),
|
||||||
array( '%s' ),
|
array( '%s' ),
|
||||||
array( '%d' )
|
array( '%d' )
|
||||||
@ -148,7 +148,7 @@ function batch_operations_process () {
|
|||||||
* 'finished' => 'my_finished_callback',
|
* 'finished' => 'my_finished_callback',
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* BatchController::Start($batch);
|
* batch_operations_start($batch);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user