Пример #1
0
 /**
  * Performs CLI migration given a profile data.
  *
  * @param  int|array $profile Profile key or array.
  *
  * @return bool|WP_Error Returns true if succeed or WP_Error if failed.
  */
 public function cli_migration($profile)
 {
     $pre_check = $this->pre_cli_migration_check($profile);
     if (is_wp_error($pre_check)) {
         return $pre_check;
     }
     // At this point, $profile has been checked a retrieved into $this->profile, so should not be used in this function any further.
     if (empty($this->profile)) {
         return $this->cli_error(__('Profile not found or unable to be generated from params.', 'wp-migrate-db-cli'));
     }
     unset($profile);
     $this->set_time_limit();
     $this->wpmdb->set_cli_migration();
     if ('savefile' === $this->profile['action']) {
         $this->post_data['intent'] = 'savefile';
         if (!empty($this->profile['export_dest'])) {
             $this->post_data['export_dest'] = $this->profile['export_dest'];
         } else {
             $this->post_data['export_dest'] = 'ORIGIN';
         }
     }
     // Ensure local site_details available.
     $this->post_data['site_details']['local'] = $this->site_details();
     // Check for tables specified in migration profile that do not exist in the source database
     if (!empty($this->profile['select_tables'])) {
         $source_tables = apply_filters('wpmdb_cli_filter_source_tables', $this->get_tables());
         if (!empty($source_tables)) {
             // Return error if selected tables do not exist in source database
             $nonexistent_tables = array();
             foreach ($this->profile['select_tables'] as $table) {
                 if (!in_array($table, $source_tables)) {
                     $nonexistent_tables[] = $table;
                 }
             }
             if (!empty($nonexistent_tables)) {
                 $local_or_remote = 'pull' === $this->profile['action'] ? 'remote' : 'local';
                 return $this->cli_error(sprintf(__('The following table(s) do not exist in the %1$s database: %2$s', 'wp-migrate-db-cli'), $local_or_remote, implode(', ', $nonexistent_tables)));
             }
         }
     }
     $this->profile = apply_filters('wpmdb_cli_filter_before_cli_initiate_migration', $this->profile);
     if (is_wp_error($this->profile)) {
         return $this->profile;
     }
     $this->migration = $this->cli_initiate_migration();
     if (is_wp_error($this->migration)) {
         return $this->migration;
     }
     $this->post_data['migration_state_id'] = $this->migration['migration_state_id'];
     $tables_to_process = $this->migrate_tables();
     if (is_wp_error($tables_to_process)) {
         return $tables_to_process;
     }
     $this->post_data['tables'] = implode(',', $tables_to_process);
     $finalize = $this->finalize_migration();
     if (is_wp_error($finalize) || 'savefile' === $this->profile['action']) {
         return $finalize;
     }
     return true;
 }
Пример #2
0
 /**
  * Performs CLI migration given a profile data.
  *
  * @param  int|array $profile Profile key or array.
  *
  * @return bool|WP_Error Returns true if succeed or WP_Error if failed.
  */
 public function cli_migration($profile)
 {
     $pre_check = $this->pre_cli_migration_check($profile);
     if (is_wp_error($pre_check)) {
         return $pre_check;
     }
     $this->set_time_limit();
     $this->wpmdb->set_cli_migration();
     if ('savefile' === $this->profile['action']) {
         $this->post_data['intent'] = 'savefile';
         if (!empty($this->profile['export_dest'])) {
             $this->post_data['export_dest'] = $profile['export_dest'];
         } else {
             $this->post_data['export_dest'] = 'ORIGIN';
         }
     }
     // Check for tables specified in migration profile that do not exist in the source database
     if (!empty($this->profile['select_tables'])) {
         $source_tables = apply_filters('wpmdb_cli_filter_source_tables', $this->get_tables());
         if (!empty($source_tables)) {
             // Return error if selected tables do not exist in source database
             $nonexistent_tables = array();
             foreach ($this->profile['select_tables'] as $table) {
                 if (!in_array($table, $source_tables)) {
                     $nonexistent_tables[] = $table;
                 }
             }
             if (!empty($nonexistent_tables)) {
                 $local_or_remote = 'pull' === $this->profile['action'] ? 'remote' : 'local';
                 return $this->cli_error(sprintf(__('The following table(s) do not exist in the %1$s database: %2$s', 'wp-migrate-db-cli'), $local_or_remote, implode(', ', $nonexistent_tables)));
             }
         }
     }
     $profile = apply_filters('wpmdb_cli_filter_before_cli_initiate_migration', $profile);
     if (is_wp_error($profile)) {
         return $profile;
     }
     $this->migration = $this->cli_initiate_migration();
     if (is_wp_error($this->migration)) {
         return $this->migration;
     }
     $this->post_data['migration_state_id'] = $this->migration['migration_state_id'];
     $tables_to_process = $this->migrate_tables();
     if (is_wp_error($tables_to_process)) {
         return $tables_to_process;
     }
     $this->post_data['tables'] = implode(',', $tables_to_process);
     $finalize = $this->finalize_migration();
     if (is_wp_error($finalize) || 'savefile' === $this->profile['action']) {
         return $finalize;
     }
     return true;
 }