/** * Execute the console command. * * @return void */ public function fire() { $tenants = $this->manager->getRepository()->getTenants(); $seeder = $this->getSeeder(); foreach ($tenants as $tenant) { $this->manager->bootstrapConnectionByTenantName($tenant->tenant_name); $this->resolver->setDefaultConnection($tenant->tenant_name); $this->manager->assumeTenant($tenant->id, true); $seeder->run(); $this->output->writeln('<info>Seeded tenant ' . $tenant->tenant_name . '</info>'); $this->manager->restoreTenant(); } }
/** * Rollback the last migration operation. * * @param bool $pretend * @return int */ public function rollback($pretend = false) { $tenants = $this->getTenants(); $migrationsFileList = array(); if ($this->usePath) { $this->note('<info>Rollback command initiated with path "' . $this->path . '"</info>'); $migrationsFileList = $this->includeMigrations($this->path); } $everyMigration = 0; foreach ($tenants as $tenant) { $this->manager->bootstrapConnectionByTenantName($tenant->tenant_name); $this->note('<info>Bootstrapped connection for:</info> ' . $tenant->tenant_name); $this->setConnection($tenant->tenant_name); $this->repository->setSource($tenant->tenant_name); $migrations = $this->repository->getLast(); if (count($migrations) == 0) { // Move on to the next tenant. $this->note('<info>Nothing to rollback on "' . $tenant->tenant_name . '".</info>'); continue; } foreach ($migrations as $migration) { $this->note('<info>Rolling back "' . $migration->migration . '".</info>'); $this->runDown((object) $migration, $pretend); } $everyMigration += count($migrations); } return $everyMigration; }
/** * Execute the console command. * * @return void */ public function fire() { if ($this->manager->getMigrationBehavior() == 'only') { foreach ($this->manager->getTenantMigrations() as $migrationName) { $this->info($migrationName); } } else { // This bit of code will get all of the migrations from the file system and load them into // an array. After the migration files are in the array, we will get the actual class name // from the migration file. $path = $this->getMigrationPath(); $files = $this->migrator->getMigrationFiles($path); $migrations = array(); foreach ($files as $file) { $migrations[] = $this->tenantMigrationResolver->resolveMigrationName($file); } $migrations = array_diff($migrations, $this->manager->getTenantMigrations()); foreach ($migrations as $migrationName) { $this->info($migrationName); } } }
/** * Instatiates the validator used by the validation process, depending if the class is being used inside or * outside of Laravel. * * @param $data * @param $rules * @param $customMessages * @return \Illuminate\Validation\Validator * @see Ardent::$externalValidator */ protected static function makeValidator($data, $rules, $customMessages) { $manager = TenantManager::instance(); $tenantConnection = $manager->getCurrentConnection(); unset($manager); if (self::$externalValidator) { $validator = self::$validationFactory->make($data, $rules, $customMessages); $validator->getPresenceVerifier()->setConnection($tenantConnection); return $validator; } else { $validator = Validator::make($data, $rules, $customMessages); $validator->getPresenceVerifier()->setConnection($tenantConnection); return $validator; } }
/** * Returns a new instance of TenantRepository */ public function __construct() { $tenantManager = TenantManager::instance(); $this->setConnection($tenantManager->getCurrentConnection()); unset($tenantManager); }