Пример #1
0
 /**
  * @return array|mixed|string|void|WP_Error
  */
 function migrate_tables()
 {
     $tables_to_migrate = $this->get_tables_to_migrate();
     $tables = $tables_to_migrate;
     $stage_iterator = 2;
     $filtered_vars = apply_filters('wpmdb_cli_filter_before_migrate_tables', array('tables' => $tables, 'stage_iterator' => $stage_iterator));
     if (!is_array($filtered_vars)) {
         return $filtered_vars;
     } else {
         extract($filtered_vars, EXTR_OVERWRITE);
     }
     if (empty($tables)) {
         return $this->cli_error(__('No tables selected for migration.', 'wp-migrate-db'));
     }
     $table_rows = $this->get_row_counts_from_table_list($tables, $stage_iterator);
     do_action('wpmdb_cli_before_migrate_tables', $this->profile, $this->migration);
     $notify = $this->get_progress_bar($tables, $stage_iterator);
     $args = $this->post_data;
     do {
         $migration_progress = 0;
         foreach ($tables as $key => $table) {
             $current_row = -1;
             $primary_keys = '';
             $table_progress = 0;
             $table_progress_last = 0;
             $args['table'] = $table;
             $args['last_table'] = $key == count($tables) - 1 ? '1' : '0';
             do {
                 // reset the current chunk
                 $this->wpmdb->empty_current_chunk();
                 $args['current_row'] = $current_row;
                 $args['primary_keys'] = $primary_keys;
                 $args = apply_filters('wpmdb_cli_migrate_table_args', $args, $this->profile, $this->migration);
                 $response = $this->migrate_table($args);
                 $migrate_table_response = $this->verify_cli_response($response, 'migrate_table()');
                 if (is_wp_error($migrate_table_response)) {
                     return $migrate_table_response;
                 }
                 $migrate_table_response = apply_filters('wpmdb_cli_migrate_table_response', $migrate_table_response, $_POST, $this->profile, $this->migration);
                 $current_row = $migrate_table_response['current_row'];
                 $primary_keys = $migrate_table_response['primary_keys'];
                 $last_migration_progress = $migration_progress;
                 if (-1 == $current_row) {
                     $migration_progress -= $table_progress;
                     $migration_progress += $table_rows[$table];
                 } else {
                     if (0 === $table_progress_last) {
                         $table_progress_last = $current_row;
                         $table_progress = $table_progress_last;
                         $migration_progress += $table_progress_last;
                     } else {
                         $iteration_progress = $current_row - $table_progress_last;
                         $table_progress_last = $current_row;
                         $table_progress += $iteration_progress;
                         $migration_progress += $iteration_progress;
                     }
                 }
                 $increment = $migration_progress - $last_migration_progress;
                 $notify->tick($increment);
             } while (-1 != $current_row);
         }
         $notify->finish();
         ++$stage_iterator;
         $args['stage'] = 'migrate';
         $tables = $tables_to_migrate;
         $table_rows = $this->get_row_counts_from_table_list($tables, $stage_iterator);
         if ($stage_iterator < 3) {
             $notify = $this->get_progress_bar($tables, $stage_iterator);
         }
     } while ($stage_iterator < 3);
     $this->post_data = $args;
     return $tables;
 }