Skip to content

Commit

Permalink
Deploying version 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ptasker committed Nov 19, 2018
1 parent 1c2825d commit 0a48fcf
Show file tree
Hide file tree
Showing 120 changed files with 11,876 additions and 7,232 deletions.
2 changes: 1 addition & 1 deletion asset/build/css/styles.css

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions asset/build/js/bundle-105.js

This file was deleted.

1 change: 0 additions & 1 deletion asset/build/js/bundle-105.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions asset/build/js/bundle-106.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions asset/build/js/bundle-106.js.map

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions class/Common/BackupExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

namespace DeliciousBrains\WPMDB\Common;

use DeliciousBrains\WPMDB\Common\Filesystem\Filesystem;
use DeliciousBrains\WPMDB\Common\FormData\FormData;
use DeliciousBrains\WPMDB\Common\Http\Http;
use DeliciousBrains\WPMDB\Common\MigrationState\StateDataContainer;
use DeliciousBrains\WPMDB\Common\Properties\Properties;
use DeliciousBrains\WPMDB\Common\Settings\Settings;
use DeliciousBrains\WPMDB\Common\Sql\Table;
use DeliciousBrains\WPMDB\Common\Sql\TableHelper;

class BackupExport {
/**
* @var Filesystem
*/
private $filesystem;
/**
* @var TableHelper
*/
private $table_helper;
/**
* @var Http
*/
private $http;

public $state_data;
/**
* @var Table
*/
private $table;
/**
* @var FormData
*/
private $form_data;
/**
* @var Properties
*/
private $props;
/**
* @var Settings
*/
private $settings;

public function __construct(
Settings $settings,
Filesystem $filesystem,
TableHelper $table_helper,
Http $http,
FormData $form_data,
Table $table,
Properties $properties,
StateDataContainer $state_data_container
) {
$this->props = $properties;
$this->settings = $settings->get_settings();
$this->filesystem = $filesystem;
$this->table_helper = $table_helper;
$this->http = $http;
$this->state_data = $state_data_container;
$this->form_data = $form_data;
$this->table = $table;
}

function register() {
add_filter( 'wpmdb_backup_header_included_tables', array( $this, 'backup_header_included_tables' ) );
}

function delete_export_file( $filename, $is_backup ) {
$dump_file = $this->table_helper->format_dump_name( $filename );

if ( true == $is_backup ) {
$dump_file = preg_replace( '/.gz$/', '', $dump_file );
}

$dump_file = $this->filesystem->get_upload_info( 'path' ) . DIRECTORY_SEPARATOR . $dump_file;

if ( empty( $dump_file ) || false === $this->filesystem->file_exists( $dump_file ) ) {
$return = array( 'wpmdb_error' => 1, 'body' => __( 'MySQL export file not found.', 'wp-migrate-db' ) );

return $this->http->end_ajax( json_encode( $return ) );
}

if ( false === $this->filesystem->unlink( $dump_file ) ) {
$return = array( 'wpmdb_error' => 1, 'body' => __( 'Could not delete the MySQL export file.', 'wp-migrate-db' ) );

return $this->http->end_ajax( json_encode( $return ) );
}
}

/**
* Determine which tables to backup (if required).
*
* @param $profile
* @param $prefixed_tables
* @param $all_tables
*
* @return mixed|void
*/
public function get_tables_to_backup( $profile, $prefixed_tables, $all_tables ) {
$tables_to_backup = array();

switch ( $profile['backup_option'] ) {
case 'backup_only_with_prefix':
$tables_to_backup = $prefixed_tables;
break;
case 'backup_selected':
/**
* When tables to migrate is tables with prefix, select_tables
* might be empty. Intersecting it with remote/local tables
* throws notice/warning and won't backup the file either.
*/
if ( 'migrate_only_with_prefix' === $profile['table_migrate_option'] ) {
$tables_to_backup = $prefixed_tables;
} else {
$tables_to_backup = array_intersect( $profile['select_tables'], $all_tables );
}
break;
case 'backup_manual_select':
$tables_to_backup = array_intersect( $profile['select_backup'], $all_tables );
break;
}

return apply_filters( 'wpmdb_tables_to_backup', $tables_to_backup, $profile );
}

/**
* Updates the database backup header with the tables that were backed up.
*
* @param $included_tables
*
* @return mixed|void
*/
public function backup_header_included_tables( $included_tables ) {
$state_data = $this->state_data->getData();
$form_data = $this->form_data->getFormData();
if ( 'backup' === $state_data['stage'] ) {
$included_tables = $this->get_tables_to_backup( $form_data, $this->table->get_tables( 'prefix' ), $this->table->get_tables() );
}

return $included_tables;
}
}
Loading

0 comments on commit 0a48fcf

Please sign in to comment.