Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): adds elgg-cli seed and unseed commands
Database seeding can now be performed via elgg-cli tool
- Loading branch information
1 parent
7b2d459
commit ded471f
Showing
10 changed files
with
97 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,42 @@ | ||
<?php | ||
|
||
namespace Elgg\Cli; | ||
|
||
/** | ||
* elgg-cli seed | ||
*/ | ||
class SeedCommand extends Command { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() { | ||
$this->setName('seed') | ||
->setDescription('Seeds the database with fake entities'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function command() { | ||
|
||
if (!class_exists('\Faker\Generator')) { | ||
elgg_log('This is a developer tool currently intended for testing purposes only. Please refrain from using it.', 'ERROR'); | ||
return 1; | ||
} | ||
|
||
elgg_set_config('debug', 'NOTICE'); | ||
|
||
set_time_limit(0); | ||
|
||
if (elgg_is_logged_in()) { | ||
elgg_log("Seeds should not be run with a logged in user", 'ERROR'); | ||
return 2; | ||
} | ||
|
||
_elgg_services()->setValue('mailer', new \Zend\Mail\Transport\InMemory()); | ||
|
||
_elgg_services()->seeder->seed(); | ||
} | ||
|
||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Elgg\Cli; | ||
|
||
/** | ||
* elgg-cli unseed | ||
*/ | ||
class UnseedCommand extends Command { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() { | ||
$this->setName('unseed') | ||
->setDescription('Removes seeded fake entities from the database'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function command() { | ||
|
||
if (!class_exists('\Faker\Generator')) { | ||
elgg_log('This is a developer tool currently intended for testing purposes only. Please refrain from using it.', 'ERROR'); | ||
return 1; | ||
} | ||
|
||
set_time_limit(0); | ||
|
||
_elgg_services()->setValue('mailer', new \Zend\Mail\Transport\InMemory()); | ||
|
||
_elgg_services()->seeder->unseed(); | ||
} | ||
|
||
} |
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