Reinstall feature

- implemented reinstall in Settings > Advanced
- shorten placeholder for Form name input
This commit is contained in:
Jonathan Labreuille
2015-12-15 13:07:43 +01:00
parent a2d38c9076
commit 6e63c72aa5
7 changed files with 58 additions and 3 deletions

View File

@@ -23,4 +23,9 @@ class Activator {
$populator = new Populator();
$populator->up();
}
function deactivate() {
$migrator = new Migrator();
$migrator->down();
}
}

View File

@@ -10,7 +10,8 @@ class Analytics {
}
function init() {
add_action('admin_enqueue_scripts', array($this, 'setupAdminDependencies'));
// review: this creates a fatal error when mailpoet tables are dropped.
//add_action('admin_enqueue_scripts', array($this, 'setupAdminDependencies'));
}
function setupAdminDependencies() {

View File

@@ -113,6 +113,7 @@ class Initializer {
}
function setupAnalytics() {
$widget = new Analytics();
$widget->init();
}

View File

@@ -41,7 +41,7 @@ class Migrator {
function down() {
global $wpdb;
$drop_table = function($model) {
$drop_table = function($model) use($wpdb) {
$table = $this->prefix . $model;
$wpdb->query("DROP TABLE {$table}");
};

25
lib/Router/Setup.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace MailPoet\Router;
use \MailPoet\Config\Activator;
use \MailPoet\Models\Setting;
if(!defined('ABSPATH')) exit;
class Setup {
function __construct() {
}
function reset() {
try {
$activator = new Activator();
$activator->deactivate();
$activator->activate();
$result = true;
} catch(Exception $e) {
$result = false;
}
wp_send_json(array(
'result' => $result
));
}
}

View File

@@ -4,7 +4,7 @@
<h2 class="title">
<input
type="text"
placeholder="<%= __('Click to change the form name!') %>"
placeholder="<%= __('Click to change the name!') %>"
id="mailpoet_form_name"
value="<%= form.name %>"
/>

View File

@@ -182,3 +182,26 @@
</tr>
</tbody>
</table>
<script type="text/javascript">
jQuery(function($) {
$(function() {
$('#mailpoet_reinstall').on('click', function() {
MailPoet.Ajax.post({
'endpoint': 'setup',
'action': 'reset'
}).done(function(response) {
if(response.result === true) {
MailPoet.Notice.success(
"<%= __('MailPoet has been reinstalled successfully using the same version. Settings and data have been deleted.') %>",
{ scroll: true });
} else {
MailPoet.Notice.error(
"<%= __('MailPoet could not be reinstalled. You might need to remove it manually first.') %>",
{ scroll: true });
}
});
});
});
});
</script>