/** * Boot the model. * * @return void */ public static function boot() { parent::boot(); static::deleted(function ($group) { $group->raise(new GroupWasDeleted($group)); $group->permissions()->delete(); }); }
/** * Boot the model. * * @return void */ public static function boot() { parent::boot(); static::deleted(function ($tag) { $tag->discussions()->detach(); Permission::where('permission', 'like', "tag{$tag->id}.%")->delete(); }); }
/** * Boot the model. * * @return void */ public static function boot() { parent::boot(); static::deleted(function ($discussion) { $discussion->raise(new DiscussionWasDeleted($discussion)); // Delete all of the posts in the discussion. Before we delete them // in a big batch query, we will loop through them and raise a // PostWasDeleted event for each post. $posts = $discussion->posts()->allTypes(); foreach ($posts->get() as $post) { $discussion->raise(new PostWasDeleted($post)); } $posts->delete(); // Delete all of the 'state' records for all of the users who have // read the discussion. $discussion->readers()->detach(); }); }
protected function install() { try { $this->storeConfiguration(); $this->runMigrations(); $this->writeSettings(); $this->application->register('Flarum\\Core\\CoreServiceProvider'); $resolver = $this->application->make('Illuminate\\Database\\ConnectionResolverInterface'); Model::setConnectionResolver($resolver); Model::setEventDispatcher($this->application->make('events')); $this->seedGroups(); $this->seedPermissions(); $this->createAdminUser(); $this->enableBundledExtensions(); } catch (Exception $e) { @unlink($this->getConfigFile()); throw $e; } }
/** * Create a new model instance according to the post's type. * * @param array $attributes * @param string|null $connection * @return static|object */ public function newFromBuilder($attributes = [], $connection = null) { $attributes = (array) $attributes; if (!empty($attributes['type']) && isset(static::$models[$attributes['type']]) && class_exists($class = static::$models[$attributes['type']])) { /** @var Post $instance */ $instance = new $class(); $instance->exists = true; $instance->setRawAttributes($attributes, true); $instance->setConnection($connection ?: $this->connection); return $instance; } return parent::newFromBuilder($attributes, $connection); }
/** * Boot the model. * * @return void */ public static function boot() { parent::boot(); // Don't allow the root admin to be deleted. static::deleting(function (User $user) { if ($user->id == 1) { throw new DomainException('Cannot delete the root admin'); } }); static::deleted(function ($user) { $user->raise(new UserWasDeleted($user)); // Delete all of the posts by the user. Before we delete them // in a big batch query, we will loop through them and raise a // PostWasDeleted event for each post. $posts = $user->posts()->allTypes(); foreach ($posts->get() as $post) { $user->raise(new PostWasDeleted($post)); } $posts->delete(); $user->read()->detach(); $user->groups()->detach(); $user->accessTokens()->delete(); $user->notifications()->delete(); }); event(new RegisterUserPreferences()); }
protected function install() { try { $this->dbConfig = $this->dataSource->getDatabaseConfiguration(); $validation = $this->getValidator()->make($this->dbConfig, ['driver' => 'required|in:mysql', 'host' => 'required', 'database' => 'required|alpha_dash', 'username' => 'required|alpha_dash', 'prefix' => 'alpha_dash|max:10']); if ($validation->fails()) { throw new Exception(implode("\n", call_user_func_array('array_merge', $validation->getMessageBag()->toArray()))); } $this->baseUrl = $this->dataSource->getBaseUrl(); $this->settings = $this->dataSource->getSettings(); $this->adminUser = $admin = $this->dataSource->getAdminUser(); if (strlen($admin['password']) < 8) { throw new Exception('Password must be at least 8 characters.'); } if ($admin['password'] !== $admin['password_confirmation']) { throw new Exception('The password did not match its confirmation.'); } if (!filter_var($admin['email'], FILTER_VALIDATE_EMAIL)) { throw new Exception('You must enter a valid email.'); } if (!$admin['username'] || preg_match('/[^a-z0-9_-]/i', $admin['username'])) { throw new Exception('Username can only contain letters, numbers, underscores, and dashes.'); } $this->storeConfiguration(); $this->runMigrations(); $this->writeSettings(); $this->application->register('Flarum\\Core\\CoreServiceProvider'); $resolver = $this->application->make('Illuminate\\Database\\ConnectionResolverInterface'); Model::setConnectionResolver($resolver); Model::setEventDispatcher($this->application->make('events')); $this->seedGroups(); $this->seedPermissions(); $this->createAdminUser(); $this->enableBundledExtensions(); } catch (Exception $e) { @unlink($this->getConfigFile()); throw $e; } }