Esempio n. 1
0
 public function update_roles($roles)
 {
     DB::delete('DELETE FROM roles_users WHERE user_id = :id', [':id' => $this->id]);
     foreach ($roles as $role) {
         DB::insert('INSERT INTO roles_users VALUES(:user_id, :role_id)', [':user_id' => $this->id, ':role_id' => $role]);
     }
 }
Esempio n. 2
0
 private function _up($limit = null)
 {
     $applied = 0;
     $migrations = $this->migrations_list;
     $total = count($migrations);
     $limit = (int) $limit;
     if ($limit > 0) {
         $migrations = array_slice($migrations, 0, $limit);
     }
     foreach ($migrations as $migration) {
         if ($migration['applied']) {
             continue;
         }
         $name = $migration['name'];
         $this->info('Loading migration #:name', [':name' => $name]);
         $obj = $this->load_migration($migration);
         $obj->init();
         if ($obj->up() === false) {
             $this->error('Migration #:name failed. Stop.', [':name' => $name]);
             return;
         }
         DB::begin();
         try {
             $obj->safe_up();
             DB::commit();
         } catch (\Throwable $e) {
             DB::rollback();
         }
         DB::insert('INSERT INTO`' . $this->migrate_table . '`(`name`, `date`) VALUES(:name, :date)', [':name' => $name, ':date' => time()]);
         $this->info('Migration up successfully', [':name' => $name]);
         $applied++;
     }
     if (!$applied) {
         $this->warning('No new migration found');
     }
 }