Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #76 WP-76/give-admins-option-to-force-migrate-rooms #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions admin/class-bigbluebutton-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ public function bbb_room_custom_columns( $column, $post_id ) {
* @since 3.0.0
*/
public function display_room_server_settings() {
$change_success = $this->room_server_settings_change();
$bbb_settings = $this->fetch_room_server_settings();
$meta_nonce = wp_create_nonce( 'bbb_edit_server_settings_meta_nonce' );
$change_success = $this->room_server_settings_change();
$bbb_settings = $this->fetch_room_server_settings();
$meta_nonce = wp_create_nonce( 'bbb_edit_server_settings_meta_nonce' );
$old_rooms_exist = $this->check_old_room_tables();
require_once 'partials/bigbluebutton-settings-display.php';
}

Expand Down Expand Up @@ -253,6 +254,18 @@ public function bigbluebutton_show_upgrade_notification( $current_plugin_metadat
}
}

/**
* Check if old rooms table exists.
*
* @since 3.0.0
*/
private function check_old_room_tables() {
global $wpdb;
$old_rooms_table = $wpdb->prefix . 'bigbluebutton';
$old_rooms_query = $wpdb->prepare( 'SHOW TABLES LIKE %s;', $wpdb->esc_like( $old_rooms_table ) );
return $wpdb->get_var( $old_rooms_query ) === $old_rooms_table;
}

/**
* Get information about the newest plugin version.
*
Expand Down
6 changes: 6 additions & 0 deletions admin/css/bigbluebutton-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@
margin-top: 2em;
margin-bottom: 2em;
}

.bbb-warning {
font-weight: 700;
color: red;
font-size: 1.2em;
}
7 changes: 7 additions & 0 deletions admin/partials/bigbluebutton-settings-display.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<div class="bbb-settings-card">
<?php if ( $old_rooms_exist && current_user_can( 'administrator' ) ) { ?>
<form id="bbb-force-migration-form" method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
<input type="hidden" name="action" value="bbb_force_migration">
<p class="bbb-warning"><?php esc_html_e( 'Please backup your database before migrating old rooms.', 'bigbluebutton' ); ?></p>
<input class="button button-primary" type="submit" value="<?php esc_html_e( 'Force Migration', 'bigbluebutton' ); ?>"/>
</form>
<?php } ?>
<h1><?php esc_html_e( 'Room Settings', 'bigbluebutton' ); ?></h1>
<h2><?php esc_html_e( 'Server', 'bigbluebutton' ); ?></h2>
<p><?php esc_html_e( 'The server settings explanation.', 'bigbluebutton' ); ?></p>
Expand Down
14 changes: 11 additions & 3 deletions includes/class-bigbluebutton-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public function migrate() {
*
* @since 3.0.0
*/
private function import_rooms() {
public function import_rooms() {
global $wpdb;
$old_rooms_table = 'wp_bigbluebutton';
$old_room_logs_table = 'wp_bigbluebutton_logs';
$old_rooms_table = $wpdb->prefix . 'bigbluebutton';
$old_room_logs_table = $wpdb->prefix . 'bigbluebutton_logs';

// Import old rooms to new rooms.
$old_rooms_query = $wpdb->prepare( 'SHOW TABLES LIKE %s;', $wpdb->esc_like( $old_rooms_table ) );
Expand Down Expand Up @@ -151,6 +151,14 @@ private function import_rooms() {
$wpdb->query( 'DROP TABLE IF EXISTS ' . $old_room_logs_table );
}
}

// Redirect to rooms page after forced migration.
if (isset($_POST['action']) && "bbb_force_migration" == $_POST['action']) {
$args = array(
'post_type' => 'bbb-room'
);
wp_redirect( add_query_arg( $args, admin_url( 'edit.php') ) );
}
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion includes/class-bigbluebutton.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ private function set_locale() {
* @access private
*/
private function define_admin_hooks() {

$plugin_admin = new Bigbluebutton_Admin( $this->get_plugin_name(), $this->get_version() );
$plugin_admin_api = new Bigbluebutton_Admin_Api();
$plugin_admin_register_custom_types = new Bigbluebutton_Register_Custom_Types();
$migrator = new Bigbluebutton_Migration( "1.4.6", $this->get_version() );

// Suggest not disabling heartbeat.
$this->loader->add_action( 'admin_notices', $plugin_admin, 'check_for_heartbeat_script' );
Expand Down Expand Up @@ -274,6 +274,9 @@ private function define_admin_hooks() {
$this->loader->add_action( 'manage_posts_custom_column', $plugin_admin, 'bbb_room_custom_columns', 10, 2 );
$this->loader->add_filter( 'manage_bbb-room_posts_columns', $plugin_admin, 'add_custom_room_column_to_list' );

// Force old rooms migration.
$this->loader->add_action( 'admin_post_bbb_force_migration', $migrator, 'import_rooms' );

}

/**
Expand Down
Binary file modified languages/bigbluebutton-en_CA.mo
Binary file not shown.
8 changes: 7 additions & 1 deletion languages/bigbluebutton-en_CA.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2019-09-13 10:54-0400\n"
"PO-Revision-Date: 2019-12-13 18:14-0500\n"
"PO-Revision-Date: 2020-01-10 16:42-0500\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -56,6 +56,12 @@ msgstr ""
"Error: The server cannot be reached. Are you sure the server is running and your settings "
"are correct?"

msgid "Force Migration"
msgstr "Force Migration"

msgid "Please backup your database before migrating old rooms."
msgstr "Please backup your database before migrating old rooms."

# Admin Room settings
msgid "Add New"
msgstr "Add New"
Expand Down
Binary file modified languages/bigbluebutton-en_US.mo
Binary file not shown.
8 changes: 7 additions & 1 deletion languages/bigbluebutton-en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2019-09-13 10:54-0400\n"
"PO-Revision-Date: 2019-12-13 18:15-0500\n"
"PO-Revision-Date: 2020-01-10 16:42-0500\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -56,6 +56,12 @@ msgstr ""
"Error: The server cannot be reached. Are you sure the server is running and your settings "
"are correct?"

msgid "Force Migration"
msgstr "Force Migration"

msgid "Please backup your database before migrating old rooms."
msgstr "Please backup your database before migrating old rooms."

# Admin Room settings
msgid "Add New"
msgstr "Add New"
Expand Down
6 changes: 6 additions & 0 deletions languages/bigbluebutton.pot
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ msgstr ""
msgid "Save server settings bad server settings error message."
msgstr ""

msgid "Force Migration"
msgstr ""

msgid "Please backup your database before migrating old rooms."
msgstr ""

# Admin Room settings
msgid "Add New"
msgstr ""
Expand Down