diff --git a/modules/backend/database/seeds/DatabaseSeeder.php b/modules/backend/database/seeds/DatabaseSeeder.php index 78c561441..50701273e 100644 --- a/modules/backend/database/seeds/DatabaseSeeder.php +++ b/modules/backend/database/seeds/DatabaseSeeder.php @@ -1,5 +1,6 @@ call('Backend\Database\Seeds\SeedSetupAdmin'); + $adminPassword = Str::random(22); + + Eloquent::unguarded(function () use ($adminPassword) { + // Generate a random password for the seeded admin account + $adminSeeder = new \Backend\Database\Seeds\SeedSetupAdmin; + $adminSeeder->setDefaults([ + 'password' => $adminPassword + ]); + $this->call($adminSeeder); }); + + return 'The following password has been automatically generated for the "admin" account: ' + . "${adminPassword}"; } } diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index 7a318c62a..bd621743a 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -89,6 +89,11 @@ class UpdateManager */ protected $repository; + /** + * @var array An array of messages returned by migrations / seeders. Returned at the end of the update process. + */ + protected $messages = []; + /** * Initialize this singleton. */ @@ -162,6 +167,9 @@ class UpdateManager } } + // Print messages returned by migrations / seeders + $this->printMessages(); + return $this; } @@ -440,7 +448,11 @@ class UpdateManager } $seeder = App::make($className); - $seeder->run(); + $return = $seeder->run(); + + if (isset($return) && (is_string($return) || is_array($return))) { + $this->addMessage($className, $return); + } $this->note(sprintf('Seeded %s ', $module)); return $this; @@ -1003,4 +1015,50 @@ class UpdateManager { return Config::get('database.migrations', 'migrations'); } + + /** + * Adds a message from a specific migration or seeder. + * + * @param string|object $class + * @param string|array $message + * @return void + */ + protected function addMessage($class, $message) + { + if (is_object($class)) { + $class = get_class($class); + } + if (!isset($this->messages[$class])) { + $this->messages[$class] = []; + } + + if (is_string($message)) { + $this->messages[$class][] = $message; + } else if (is_array($message)) { + array_merge($this->messages[$class], $message); + } + } + + /** + * Prints collated messages from the migrations and seeders + * + * @return void + */ + protected function printMessages() + { + if (!count($this->messages)) { + return; + } + + // Add a line break + $this->note(''); + + foreach ($this->messages as $class => $messages) { + $this->note(sprintf('%s reported:', $class)); + + foreach ($messages as $message) { + $this->note(' - ' . (string) $message); + } + } + } } diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index 11d425d9a..696e567be 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -83,7 +83,7 @@ class VersionManager // No updates needed if ($currentVersion == $databaseVersion) { - $this->note('- Nothing to update.'); + $this->note(' - Nothing to update.'); return; } @@ -140,7 +140,7 @@ class VersionManager foreach ($comments as $comment) { $this->applyDatabaseComment($code, $version, $comment); - $this->note(sprintf('- v%s: %s', $version, $comment)); + $this->note(sprintf(' - v%s: %s', $version, $comment)); } } diff --git a/tests/unit/plugins/database/ModelTest.php b/tests/unit/plugins/database/PluginModelTest.php similarity index 94% rename from tests/unit/plugins/database/ModelTest.php rename to tests/unit/plugins/database/PluginModelTest.php index 16bf07c1d..85d7e31b8 100644 --- a/tests/unit/plugins/database/ModelTest.php +++ b/tests/unit/plugins/database/PluginModelTest.php @@ -2,7 +2,7 @@ use Database\Tester\Models\Post; -class ModelTest extends PluginTestCase +class PluginModelTest extends PluginTestCase { public function setUp() : void {