/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->resolver->setDefaultConnection($this->getDatabase());
     $this->getSeeder()->run();
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $name = $this->input->getOption('database');
     $total = $this->seeder->seed($this->resolver->connection($name), $this->path);
     if ($total == 0) {
         $this->info('Nothing to seed.');
     }
 }
Example #3
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->resolver->setDefaultConnection($this->getDatabase());
     Model::unguarded(function () {
         $this->getSeeder()->__invoke();
     });
 }
 /**
  * @return mixed
  */
 public function handle()
 {
     // TODO: Implement handle() method.
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->resolver->setDefaultConnection($this->getDatabase());
     Model::unguarded(function () {
         $this->getSeeder()->run();
     });
 }
Example #5
0
 /**
  * @param Request $request
  * @param Closure $next
  * @return mixed
  * @throws \Exception
  */
 public function handle(Request $request, Closure $next)
 {
     $this->connectionResolver->connection()->beginTransaction();
     try {
         $response = $next($request);
     } catch (\Exception $e) {
         $this->connectionResolver->connection()->rollBack();
         throw $e;
     }
     $this->connectionResolver->connection()->commit();
     return $response;
 }
Example #6
0
 /**
  * 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();
     }
 }
Example #7
0
 /**
  * connects the database, saves SQL-Connection, database-name and prefix
  * @param ConnectionResolverInterface $db
  * @throws \ErrorException
  */
 public function __construct(ConnectionResolverInterface $db)
 {
     try {
         /** @var Connection $connection */
         $connection = $db->connection();
         $this->sql = $connection->getPdo();
         $this->db = $connection->getConfig('database');
         $this->pref = $connection->getConfig('prefix');
     } catch (\Exception $e) {
         $this->sql = false;
         $this->error = $e->getMessage();
         throw new \ErrorException('No Connection to Database: ' . $e->getMessage());
     }
 }
 /**
  * Set the default connection name.
  *
  * @param  string  $name
  * @return void
  */
 public function setConnection($name)
 {
     if (!is_null($name)) {
         $this->resolver->setDefaultConnection($name);
     }
     $this->repository->setSource($name);
     $this->connection = $name;
 }
 /**
  * Get a query builder for the given table.
  *
  * @param  string  $table
  * @return \Illuminate\Database\Query\Builder
  */
 protected function table($table)
 {
     return $this->db->connection($this->connection)->table($table);
 }
 /**
  * Get a query builder for the given table.
  *
  * @param  string  $table
  * @return \Illuminate\Database\Query\Builder
  */
 protected function table($table)
 {
     return $this->db->connection($this->connection)->table($table)->useWritePdo();
 }
 /**
  * Get the connection.
  *
  * @return \Illuminate\Database\ConnectionInterface
  */
 protected function getConnection()
 {
     return $this->resolver->connection($this->connectionName);
 }
Example #12
0
 /**
  * Resolve a connection instance by name.
  *
  * @param  string  $connection
  * @return Illuminate\Database\Connection
  */
 public static function resolveConnection($connection)
 {
     return static::$resolver->connection($connection);
 }
 function it_should_get_connection_for_source()
 {
     $connection = microtime();
     $this->resolver->connection($this->source)->willReturn($connection);
     $this->getConnection()->shouldBe($connection);
 }
 /**
  * Establish a queue connection.
  *
  * @param  array  $config
  * @return \Illuminate\Contracts\Queue\Queue
  */
 public function connect(array $config)
 {
     return new DatabaseQueue($this->connections->connection(array_get($config, 'connection')), array_get($config, 'table', 'queues'), array_get($config, 'queue', null), array_get($config, 'expire', 60), array_get($config, 'lock_type', 60));
 }
 /**
  * @Transactional(value="testing",expect=\LogicException::class)
  *
  * @return string
  */
 public function errorException()
 {
     $this->db->connection()->statement('CREATE TABLE tests (test varchar(255) NOT NULL)');
     $this->db->connection()->table("tests")->insert(['test' => 'testing']);
     throw new \LogicException();
 }
 /**
  * Establish a queue connection.
  *
  * @param  array  $config
  * @return \Illuminate\Contracts\Queue\Queue
  */
 public function connect(array $config)
 {
     return new DatabaseQueue($this->connections->connection(Arr::get($config, 'connection')), $config['table'], $config['queue'], Arr::get($config, 'expire', 60));
 }
 /**
  * Resolve the database connection instance.
  *
  * @return \Illuminate\Database\Connection
  */
 public function getConnection()
 {
     return $this->resolver->connection($this->connection);
 }
 /**
  * Get a new query builder instance for the table.
  *
  * @return \Illuminate\Database\Query\Builder
  */
 protected function getTable()
 {
     return $this->resolver->connection($this->database)->table($this->table);
 }
Example #19
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->resolver->setDefaultConnection($this->getDatabase());
     $this->getSeeder()->run();
 }
 /**
  * @param array $config
  *
  * @return CouchbaseQueue|\Illuminate\Contracts\Queue\Queue
  */
 public function connect(array $config)
 {
     /** @var CouchbaseConnection $connection */
     $connection = $this->connectionResolver->connection($config['driver']);
     return new CouchbaseQueue($connection, $config['bucket'], $config['queue'], Arr::get($config, 'retry_after', 60));
 }