From ead972021dd02283518a125b6d7c5a7f65568071 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 20 Mar 2017 12:21:47 +0200 Subject: [PATCH 1/5] Add custom dump functionaity Add the ability to someone to add custom db dump in case of complex scenarios. --- src/WPCliDb.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/WPCliDb.php b/src/WPCliDb.php index b6eca56..f7c19a2 100755 --- a/src/WPCliDb.php +++ b/src/WPCliDb.php @@ -68,6 +68,18 @@ public function start_with_dump2() echo "Dump2 not set, default database dump loaded instead."; } } + + public function start_with_dump($filename) + { + $this->runShellCommand("wp db reset --yes"); + + if (isset($filename)) { + $this->runShellCommand("wp db import " . $filename); + $this->db_cleanup(); + } else { + echo $filename." not set, default database dump loaded instead."; + } + } private function db_cleanup() { From 212e2a895ba4159bcf3ba35f7a84ff52e2cc0bc1 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 20 Mar 2017 12:44:37 +0200 Subject: [PATCH 2/5] Update WPCliDb.php Change the filename to be taken from the configuration of the module --- src/WPCliDb.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WPCliDb.php b/src/WPCliDb.php index f7c19a2..4566995 100755 --- a/src/WPCliDb.php +++ b/src/WPCliDb.php @@ -69,15 +69,15 @@ public function start_with_dump2() } } - public function start_with_dump($filename) + public function start_with_dump($custom_dump) { $this->runShellCommand("wp db reset --yes"); if (isset($filename)) { - $this->runShellCommand("wp db import " . $filename); + $this->runShellCommand("wp db import " . $this->config[$custom_dump]); $this->db_cleanup(); } else { - echo $filename." not set, default database dump loaded instead."; + echo $custom_dump." not set, default database dump loaded instead."; } } From 4fea0138473ed6a74fe9a9a72a52cceb00617f6b Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 20 Mar 2017 12:51:57 +0200 Subject: [PATCH 3/5] Update WPCliDb.php Changed again so the custom dump file be taken directly from the _data folder --- src/WPCliDb.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WPCliDb.php b/src/WPCliDb.php index 4566995..ade7a4e 100755 --- a/src/WPCliDb.php +++ b/src/WPCliDb.php @@ -69,15 +69,15 @@ public function start_with_dump2() } } - public function start_with_dump($custom_dump) + public function import_dump($filename) { $this->runShellCommand("wp db reset --yes"); if (isset($filename)) { - $this->runShellCommand("wp db import " . $this->config[$custom_dump]); + $this->runShellCommand("wp db import " . codecept_data_dir() . $filename); $this->db_cleanup(); } else { - echo $custom_dump." not set, default database dump loaded instead."; + echo $filename." not set, default database dump loaded instead."; } } From 2f94eb81ee4a93b03e9b4da9baa8c098b63234b7 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 20 Mar 2017 12:57:44 +0200 Subject: [PATCH 4/5] Update WPCliDb.php add some changes proposed from Kostas --- src/WPCliDb.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WPCliDb.php b/src/WPCliDb.php index ade7a4e..331491b 100755 --- a/src/WPCliDb.php +++ b/src/WPCliDb.php @@ -73,11 +73,11 @@ public function import_dump($filename) { $this->runShellCommand("wp db reset --yes"); - if (isset($filename)) { + if (file_exists($filename)) { $this->runShellCommand("wp db import " . codecept_data_dir() . $filename); $this->db_cleanup(); } else { - echo $filename." not set, default database dump loaded instead."; + echo $filename." not found in _data folder, default database dump loaded instead."; } } From 0dde093497dcd34b85bafab0151166959e110d06 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 20 Mar 2017 13:05:34 +0200 Subject: [PATCH 5/5] Update WPCliDb.php Added some more changes in the function --- src/WPCliDb.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/WPCliDb.php b/src/WPCliDb.php index 331491b..846fd25 100755 --- a/src/WPCliDb.php +++ b/src/WPCliDb.php @@ -73,11 +73,13 @@ public function import_dump($filename) { $this->runShellCommand("wp db reset --yes"); - if (file_exists($filename)) { - $this->runShellCommand("wp db import " . codecept_data_dir() . $filename); + $file = codecept_data_dir() . $filename; + + if (file_exists($file)) { + $this->runShellCommand("wp db import " . $file); $this->db_cleanup(); } else { - echo $filename." not found in _data folder, default database dump loaded instead."; + $this->fail("Your file does not exist"); } }