Generate random password for seeded admin account through october:up (#4866)
This commit is contained in:
parent
96fd2ec657
commit
d7d6faeedb
|
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Backend\Database\Seeds;
|
||||
|
||||
use Str;
|
||||
use Seeder;
|
||||
use Eloquent;
|
||||
|
||||
|
|
@ -8,12 +9,22 @@ class DatabaseSeeder extends Seeder
|
|||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Eloquent::unguarded(function () {
|
||||
$this->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: '
|
||||
. "<fg=yellow;options=bold>${adminPassword}</>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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('<info>Seeded %s</info> ', $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('<info>%s reported:</info>', $class));
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$this->note(' - ' . (string) $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class VersionManager
|
|||
|
||||
// No updates needed
|
||||
if ($currentVersion == $databaseVersion) {
|
||||
$this->note('- <info>Nothing to update.</info>');
|
||||
$this->note(' - <info>Nothing to update.</info>');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ class VersionManager
|
|||
foreach ($comments as $comment) {
|
||||
$this->applyDatabaseComment($code, $version, $comment);
|
||||
|
||||
$this->note(sprintf('- <info>v%s: </info> %s', $version, $comment));
|
||||
$this->note(sprintf(' - <info>v%s: </info> %s', $version, $comment));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use Database\Tester\Models\Post;
|
||||
|
||||
class ModelTest extends PluginTestCase
|
||||
class PluginModelTest extends PluginTestCase
|
||||
{
|
||||
public function setUp() : void
|
||||
{
|
||||
Loading…
Reference in New Issue