- 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() {
$files = array(// global admin styles
'assets/css/src/admin.styl',
// rtl specific styles
'assets/css/src/rtl.styl'
$files = array(
// global admin styles
'assets/css/src/admin.styl',
// rtl specific styles
'assets/css/src/rtl.styl'
);
$command = array(
@ -28,11 +29,15 @@ class RoboFile extends \Robo\Tasks {
}
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() {
$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() {

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
<?php
use MailPoet\Config\Env;
$console = new \Codeception\Lib\Console\Output([]);
$console->writeln('Loading WP core...');
$wordpress_path = getenv('WP_TEST_PATH');
if ($wordpress_path) {
if (file_exists($wordpress_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");
}
global $wpdb;
$console->writeln('Cleaning up database...');
$models = array(
"Subscriber",
"Setting"
);
// clean database on each run
$truncate_commands = $wpdb->get_results("SELECT concat('TRUNCATE TABLE `', TABLE_NAME, '`;') as `truncate`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '" . Env::$db_name . "' AND TABLE_NAME LIKE '" . Env::$db_prefix . "%'");
foreach ($truncate_commands as $command) {
$wpdb->query($command->truncate);
foreach ($models as $model) {
Model::factory("\MailPoet\Models\\" . $model)
->delete_many();
}