Coding standard fixes

This commit is contained in:
fred
2017-04-15 19:35:52 +02:00
parent dd7f959731
commit a1ea56f505
5 changed files with 294 additions and 298 deletions

View File

@ -4,7 +4,6 @@
var that;
var mailpoet_import = {
fatal_error: '',
is_logging: false,
@ -26,7 +25,6 @@
that.is_logging = false;
},
/**
* Update the display
*/
@ -120,7 +118,9 @@
}).fail(function (response) {
if(response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) {
return error.message;
}),
{scroll: true}
);
}
@ -157,7 +157,7 @@
});
that.stop_logger();
return false;
},
}
};
@ -176,12 +176,4 @@
$('#stop-import').click(that.stop_import);
});
/**
* Actions to run when the window is loaded
*/
$( window ).load(function() {
});
})(jQuery);

View File

@ -35,7 +35,7 @@ class MP2MigratorAPI extends APIEndpoint {
*/
public function stopImport($data) {
try {
$process = $this->MP2Migrator->stop_import();
$process = $this->MP2Migrator->stopImport();
return $this->successResponse($process);
} catch(\Exception $e) {
return $this->errorResponse(array(

View File

@ -1,4 +1,5 @@
<?php
namespace MailPoet\Config;
use MailPoet\Util\ProgressBar;
@ -32,7 +33,7 @@ class MP2Migrator {
if(get_option('mailpoet_migration_complete')) {
return false;
} else {
return $this->table_exists('wysija_campaign'); // Check if the MailPoet 2 tables exist
return $this->tableExists('wysija_campaign'); // Check if the MailPoet 2 tables exist
}
}
@ -42,14 +43,16 @@ class MP2Migrator {
* @param string $table Table name
* @return boolean
*/
public function table_exists($table) {
private function tableExists($table) {
global $wpdb;
try {
$sql = "SHOW TABLES LIKE '{$wpdb->prefix}{$table}'";
$result = $wpdb->query($sql);
return !empty($result);
} catch ( Exception $e ) {}
} catch (Exception $e) {
// Do nothing
}
return false;
}
@ -59,7 +62,7 @@ class MP2Migrator {
*
*/
public function init() {
$this->enqueue_scripts();
$this->enqueueScripts();
$this->log('INIT');
}
@ -67,7 +70,7 @@ class MP2Migrator {
* Register the JavaScript for the admin area.
*
*/
private function enqueue_scripts() {
private function enqueueScripts() {
wp_enqueue_script('jquery-ui-progressbar');
}
@ -76,7 +79,7 @@ class MP2Migrator {
*
* @param string $message
*/
public function log($message) {
private function log($message) {
file_put_contents($this->log_file, "$message\n", FILE_APPEND);
}
@ -87,15 +90,14 @@ class MP2Migrator {
*/
public function import() {
$this->log('START IMPORT');
update_option('mailpoet_stop_import', false, false); // Reset the stop import action
update_option('mailpoet_stopImport', false, false); // Reset the stop import action
// TODO to remove, for testing only
$this->progressbar->set_total_count(0);
$this->progressbar->set_total_count(10);
$this->progressbar->setTotalCount(0);
$this->progressbar->setTotalCount(10);
for($i = 0; $i < 10; $i++) {
$this->progressbar->increment_current_count(1);
$this->progressbar->incrementCurrentCount(1);
usleep(300000);
if ( $this->import_stopped() ) {
if($this->importStopped()) {
return;
}
}
@ -107,8 +109,8 @@ class MP2Migrator {
* Stop the import
*
*/
public function stop_import() {
update_option('mailpoet_stop_import', true);
public function stopImport() {
update_option('mailpoet_stopImport', true);
$this->log('IMPORT STOPPED BY USER');
}
@ -117,8 +119,8 @@ class MP2Migrator {
*
* @return boolean Import must stop or not
*/
public function import_stopped() {
return get_option('mailpoet_stop_import');
private function importStopped() {
return get_option('mailpoet_stopImport');
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace MailPoet\Util;
use MailPoet\Config\Env;
@ -27,7 +28,7 @@ if ( !class_exists('ProgressBar', false) ) {
$filename = Env::$plugin_name . '-' . $progress_bar_id . '-progress.json';
$this->filename = $upload_dir['basedir'] . '/' . $filename;
$this->url = $upload_dir['baseurl'] . '/' . $filename;
$counters = $this->read_progress();
$counters = $this->readProgress();
if(isset($counters->total)) {
$this->total_count = $counters->total;
}
@ -41,7 +42,7 @@ if ( !class_exists('ProgressBar', false) ) {
*
* @return string Progress file URL
*/
public function get_url() {
public function getUrl() {
return $this->url;
}
@ -50,7 +51,7 @@ if ( !class_exists('ProgressBar', false) ) {
*
* @return array|false Array of counters
*/
private function read_progress() {
private function readProgress() {
if(file_exists($this->filename)) {
$json_content = file_get_contents($this->filename);
return json_decode($json_content);
@ -64,11 +65,11 @@ if ( !class_exists('ProgressBar', false) ) {
*
* @param int $count Count
*/
public function set_total_count($count) {
public function setTotalCount($count) {
if($count != $this->total_count) {
$this->total_count = $count;
$this->current_count = 0;
$this->save_progress();
$this->saveProgress();
}
}
@ -77,21 +78,22 @@ if ( !class_exists('ProgressBar', false) ) {
*
* @param int $count Count
*/
public function increment_current_count($count) {
public function incrementCurrentCount($count) {
$this->current_count += $count;
$this->save_progress();
$this->saveProgress();
}
/**
* Save the progress counters
*
*/
private function save_progress() {
private function saveProgress() {
file_put_contents($this->filename, json_encode(array(
'total' => $this->total_count,
'current' => $this->current_count,
)));
}
}
}
}