-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create import xeed command for testing (#14)
* Create import xeed command for testing * Fix some namespace typo and add method comments
- Loading branch information
Showing
7 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Cable8mm\Xeed\Command; | ||
|
||
use Cable8mm\Xeed\DB; | ||
use Cable8mm\Xeed\Support\Path; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'import-xeed', | ||
description: 'Import xeed sql for testing. run `bin/console import-xeed`', | ||
hidden: false, | ||
aliases: ['xeed'] | ||
)] | ||
class ImportXeedCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$dotenv = \Dotenv\Dotenv::createImmutable(getcwd()); | ||
$dotenv->safeLoad(); | ||
|
||
$this | ||
->addArgument('drop', InputArgument::OPTIONAL, 'Drop xeeds table?'); | ||
} | ||
|
||
/** | ||
* Generate models. | ||
* | ||
* Run `bin/console generate-seeders` or `bin/console seeders` | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
|
||
$drop = $input->getArgument('drop'); | ||
|
||
if ($drop) { | ||
DB::getInstance()->prepare('DROP TABLE xeeds')->execute(); | ||
} else { | ||
$sql = file_get_contents(Path::resourceTest().'xeeds.sql'); | ||
|
||
DB::getInstance()->exec($sql); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters