- Database cleanup uses Models

- Formatted code as per Marco's comments
This commit is contained in:
Vlad
2015-08-12 22:48:42 +00:00
parent 9402074bed
commit c5f67cb371
5 changed files with 26 additions and 27 deletions

View File

@@ -14,10 +14,11 @@ class RoboFile extends \Robo\Tasks {
} }
function watch() { function watch() {
$files = array(// global admin styles $files = array(
'assets/css/src/admin.styl', // global admin styles
// rtl specific styles 'assets/css/src/admin.styl',
'assets/css/src/rtl.styl' // rtl specific styles
'assets/css/src/rtl.styl'
); );
$command = array( $command = array(
@@ -28,11 +29,15 @@ class RoboFile extends \Robo\Tasks {
} }
function makepot() { function makepot() {
$this->_exec('grunt makepot' . ' --gruntfile ' . __DIR__ . '/tasks/makepot/makepot.js' . ' --base_path ' . __DIR__); $this->_exec('grunt makepot' . ' --gruntfile '
. __DIR__ . '/tasks/makepot/makepot.js'
. ' --base_path ' . __DIR__);
} }
function pushpot() { function pushpot() {
$this->_exec('grunt pushpot' . ' --gruntfile ' . __DIR__ . '/tasks/makepot/makepot.js' . ' --base_path ' . __DIR__); $this->_exec('grunt pushpot' . ' --gruntfile '
. __DIR__ . '/tasks/makepot/makepot.js'
. ' --base_path ' . __DIR__);
} }
function testUnit() { function testUnit() {

View File

@@ -1,13 +1,11 @@
<?php <?php
namespace MailPoet\Models; namespace MailPoet\Models;
if (!defined('ABSPATH')) { if (!defined('ABSPATH')) exit;
exit;
}
class Model extends \Sudzy\ValidModel { class Model extends \Sudzy\ValidModel {
function __construct() { function __construct() {
$customValidator = new CustomValidator(); $customValidators = new CustomValidator();
parent::__construct($customValidator->init()); parent::__construct($customValidators->init());
} }
} }

View File

@@ -1,9 +1,7 @@
<?php <?php
namespace MailPoet\Models; namespace MailPoet\Models;
if (!defined('ABSPATH')) { if (!defined('ABSPATH')) exit;
exit;
}
class Setting extends Model { class Setting extends Model {
public static $_table = MP_SETTINGS_TABLE; public static $_table = MP_SETTINGS_TABLE;

View File

@@ -1,9 +1,7 @@
<?php <?php
namespace MailPoet\Models; namespace MailPoet\Models;
if (!defined('ABSPATH')) { if (!defined('ABSPATH')) exit;
exit;
}
class Subscriber extends Model { class Subscriber extends Model {
public static $_table = MP_SUBSCRIBERS_TABLE; public static $_table = MP_SUBSCRIBERS_TABLE;

View File

@@ -1,9 +1,9 @@
<?php <?php
use MailPoet\Config\Env; $console = new \Codeception\Lib\Console\Output([]);
$console->writeln('Loading WP core...');
$wordpress_path = getenv('WP_TEST_PATH'); $wordpress_path = getenv('WP_TEST_PATH');
if ($wordpress_path) { if ($wordpress_path) {
if (file_exists($wordpress_path . '/wp-load.php')) { if (file_exists($wordpress_path . '/wp-load.php')) {
require_once(getenv('WP_TEST_PATH') . '/wp-load.php'); require_once(getenv('WP_TEST_PATH') . '/wp-load.php');
@@ -12,13 +12,13 @@ if ($wordpress_path) {
throw new Exception("You need to specify the path to your WordPress installation\n`WP_TEST_PATH` in your .env file"); throw new Exception("You need to specify the path to your WordPress installation\n`WP_TEST_PATH` in your .env file");
} }
global $wpdb; $console->writeln('Cleaning up database...');
$models = array(
"Subscriber",
"Setting"
);
// clean database on each run foreach ($models as $model) {
$truncate_commands = $wpdb->get_results("SELECT concat('TRUNCATE TABLE `', TABLE_NAME, '`;') as `truncate` Model::factory("\MailPoet\Models\\" . $model)
FROM INFORMATION_SCHEMA.TABLES ->delete_many();
WHERE TABLE_SCHEMA = '" . Env::$db_name . "' AND TABLE_NAME LIKE '" . Env::$db_prefix . "%'");
foreach ($truncate_commands as $command) {
$wpdb->query($command->truncate);
} }