diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index a42f59384..e6f8eaa18 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -23,5 +23,6 @@ 'rememberToken' => str_random(10), 'roles' => new ArrayCollection(), 'emailVerifiedAt' => Carbon::now(), + 'google2faEnable' => false, ]; }); diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index c379e94da..a821ad700 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -1,6 +1,7 @@ call(UserTableSeeder::class); + $entityManager->clear(); $this->call(ProfileTableSeeder::class); + $entityManager->clear(); $this->call(AccountTableSeeder::class); + $entityManager->clear(); $this->call(PinTableSeeder::class); + $entityManager->clear(); $this->call(RfidTagTableSeeder::class); + $entityManager->clear(); $this->call(AccessLogTableSeeder::class); + $entityManager->clear(); $this->call(BankTransactionTableSeeder::class); + $entityManager->clear(); $this->call(RoleUpdateTableSeeder::class); + $entityManager->clear(); $this->call(ProductTableSeeder::class); + $entityManager->clear(); $this->call(TransactionTableSeeder::class); + $entityManager->clear(); $this->call(ToolTableSeeder::class); + $entityManager->clear(); } } diff --git a/database/seeds/ProfileTableSeeder.php b/database/seeds/ProfileTableSeeder.php index 7f0b4b20b..7032f4bfc 100644 --- a/database/seeds/ProfileTableSeeder.php +++ b/database/seeds/ProfileTableSeeder.php @@ -5,7 +5,7 @@ use Illuminate\Database\Seeder; use HMS\Repositories\RoleRepository; use HMS\Repositories\UserRepository; -use LaravelDoctrine\ORM\Facades\EntityManager; +use Doctrine\ORM\EntityManagerInterface; class ProfileTableSeeder extends Seeder { @@ -19,10 +19,23 @@ class ProfileTableSeeder extends Seeder */ protected $userRepository; - public function __construct(RoleRepository $roleRepository, UserRepository $userRepository) + /** + * @var EntityManagerInterface + */ + protected $entityManager; + + /** + * Create a new TableSeeder instance. + * + * @param RoleRepository $roleRepository + * @param UserRepository $userRepository, + * @param EntityManagerInterface $entityManager + */ + public function __construct(RoleRepository $roleRepository, UserRepository $userRepository, EntityManagerInterface $entityManager) { $this->roleRepository = $roleRepository; $this->userRepository = $userRepository; + $this->entityManager = $entityManager; } /** @@ -52,9 +65,9 @@ public function run() $p = entity(Profile::class)->make(['user' => $user]); break; } - EntityManager::persist($p); + $this->entityManager->persist($p); } } - EntityManager::flush(); + $this->entityManager->flush(); } } diff --git a/database/seeds/UserTableSeeder.php b/database/seeds/UserTableSeeder.php index a3a2135fe..b5e0ebc55 100644 --- a/database/seeds/UserTableSeeder.php +++ b/database/seeds/UserTableSeeder.php @@ -6,7 +6,7 @@ use HMS\Auth\PasswordStore; use Illuminate\Database\Seeder; use HMS\Repositories\RoleRepository; -use LaravelDoctrine\ORM\Facades\EntityManager; +use Doctrine\ORM\EntityManagerInterface; class UserTableSeeder extends Seeder { @@ -35,16 +35,23 @@ class UserTableSeeder extends Seeder */ protected $passwordStore; + /** + * @var EntityManagerInterface + */ + protected $entityManager; + /** * Create a new TableSeeder instance. * * @param RoleRepository $roleRepository * @param PasswordStore $passwordStore + * @param EntityManagerInterface $entityManager */ - public function __construct(RoleRepository $roleRepository, PasswordStore $passwordStore) + public function __construct(RoleRepository $roleRepository, PasswordStore $passwordStore, EntityManagerInterface $entityManager) { $this->roleRepository = $roleRepository; $this->passwordStore = $passwordStore; + $this->entityManager = $entityManager; } /** @@ -75,7 +82,7 @@ public function run() ->each(function ($u) { $u->getRoles()->add($this->roleRepository->findOneByName(Role::MEMBER_CURRENT)); $this->passwordStore->add($u->getUsername(), 'password'); - EntityManager::persist($u); + $this->entityManager->persist($u); }); // create all the other types @@ -85,7 +92,7 @@ public function run() ->each(function ($u) use ($role) { $u->getRoles()->add($this->roleRepository->findOneByName($role)); $this->passwordStore->add($u->getUsername(), 'password'); - EntityManager::persist($u); + $this->entityManager->persist($u); }); } @@ -95,9 +102,9 @@ public function run() $admin->getRoles()->add($this->roleRepository->findOneByName(Role::SUPERUSER)); $admin->setEmailVerifiedAt(new Carbon); $this->passwordStore->add($admin->getUsername(), 'admin'); - EntityManager::persist($admin); + $this->entityManager->persist($admin); } - EntityManager::flush(); + $this->entityManager->flush(); } } diff --git a/dev/reseed.sh b/dev/reseed.sh index b9510488d..21181caaf 100755 --- a/dev/reseed.sh +++ b/dev/reseed.sh @@ -6,10 +6,10 @@ mysql -uroot -proot mailserver -e "DELETE FROM alias" mysql -uroot -proot mailserver -e "DELETE FROM mailbox" php artisan migrate:reset -php artisan doctrine:migration:refresh +php artisan doctrine:migrations:refresh php artisan migrate php artisan hms:database:refresh-views php artisan hms:database:refresh-procedures -php artisan permission:defaults +php artisan permissions:defaults php artisan db:seed php artisan passport:install \ No newline at end of file diff --git a/routes/console.php b/routes/console.php index f5bf45dc1..ff72c7a95 100644 --- a/routes/console.php +++ b/routes/console.php @@ -21,3 +21,24 @@ Artisan::command('hms:auto-deploy', function () { PostGitDeployedJob::dispatchNow(); })->describe('Run the GitDeployedJob'); + +Artisan::command('hms:reseed {--force}', function ($force) { + if (! App::environment('local') && ! $force) { + // The environment is not local + $this->error('Abort, not local environment (use --force to override)'); + + return; + } + + exec('mysql -uroot -proot mailserver -e "DELETE FROM alias"'); + exec('mysql -uroot -proot mailserver -e "DELETE FROM mailbox"'); + + $this->call('migrate:reset'); + $this->call('doctrine:migrations:refresh'); + $this->call('migrate'); + $this->call('hms:database:refresh-views'); + $this->call('hms:database:refresh-procedures'); + $this->call('permissions:defaults'); + $this->call('db:seed'); + $this->call('passport:install'); +})->describe('Reseed the database');