- 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

@@ -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();
}