/** * Delete this group from the database, along with any linked user and authorization rules * */ public function delete() { // Remove all user associations $this->users()->detach(); // Remove all group auth rules $auth_table = Database::getSchemaTable('authorize_group')->name; Capsule::table($auth_table)->where("group_id", $this->id)->delete(); // Reassign any primary users to the current default primary group $default_primary_group = Group::where('is_default', GROUP_DEFAULT_PRIMARY)->first(); $user_table = Database::getSchemaTable('user')->name; Capsule::table($user_table)->where('primary_group_id', $this->id)->update(["primary_group_id" => $default_primary_group->id]); // TODO: assign user to the default primary group as well? // Delete the group $result = parent::delete(); return $result; }
/** * Construct the site settings object, loading values from the database. * * Fall back to default settings, if the configuration table cannot be loaded for one reason or another. * @param array $settings the default settings to use, if they can't be retrieved from the DB. * @param array $descriptions the default descriptions to use, if they can't be retrieved from the DB. */ public function __construct($settings = [], $descriptions = []) { $table_schema = Database::getSchemaTable(static::$_table_id); $this->table = $table_schema->name; $this->fillable = $table_schema->columns; // Initialize UF environment $this->initEnvironment(); // Set default settings first $this->_settings = $settings; $this->_descriptions = $descriptions; // Now, try to load settings from database if possible try { $results = $this->fetchSettings(); // Merge, replacing default settings with DB settings as necessary. $this->_settings = array_replace_recursive($this->_settings, $results['settings']); $this->_descriptions = array_replace_recursive($this->_descriptions, $results['descriptions']); // If there are settings in this object that are not present in the database, go ahead and store them to the DB. if (!$this->isConsistent()) { $this->store(); } } catch (\PDOException $e) { error_log("The configuration table could not be loaded. Falling back to default configuration settings."); } }
/** * Delete this user from the database, along with any linked groups and authorization rules * * @return bool true if the deletion was successful, false otherwise. */ public function delete() { // Remove all group associations $this->groups()->detach(); // Remove all user auth rules $auth_table = Database::getSchemaTable('authorize_user')->name; Capsule::table($auth_table)->where("user_id", $this->id)->delete(); // Remove all user events $event_table = Database::getSchemaTable('user_event')->name; Capsule::table($event_table)->where("user_id", $this->id)->delete(); // Delete the user $result = parent::delete(); return $result; }
/** * 0.3.1 - Updating groups to use dashboard instead of the old accounts page. */ echo '(0.3.1) Updating groups to use new dashboard in ' . \UserFrosting\Database::getSchemaTable('group')->name . ': '; $connection->statement("UPDATE `" . \UserFrosting\Database::getSchemaTable('group')->name . "`\n SET `landing_page` = 'dashboard' WHERE `landing_page` = 'account'; ") or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); echo 'Done.' . PHP_EOL; /** * 0.3.1.5 - Add default value for secret_token. */ echo '(0.3.1.5) Creating default value for secret_token: '; $connection->statement("ALTER TABLE `" . \UserFrosting\Database::getSchemaTable('user')->name . "`\n CHANGE `secret_token` `secret_token` varchar(32) NOT NULL DEFAULT ''\n COMMENT 'The current one-time use token for various user activities confirmed via email.'") or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); echo 'Done.' . PHP_EOL; /** * 0.3.1.7 - Change from "default_theme" to "guest_theme". */ echo '(0.3.1.7) Updating "default_theme" to "guest_theme": '; if (isset($settings['default_theme'])) { $settings['guest_theme'] = $settings['default_theme']; $settings->save(); $connection->statement('DELETE FROM `' . \UserFrosting\Database::getSchemaTable('configuration')->name . '` WHERE `name` = \'default_theme\'') or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); } echo 'Done.' . PHP_EOL; /** * Latest - Update the version number in the database. */ $settings = SiteSettings::all()->first(); echo PHP_EOL . '(' . $versionTargetDatabase . ') Updating database version: '; $settings['version'] = $versionTargetDatabase; $settings->save() or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); echo 'Done.' . PHP_EOL; echo PHP_EOL . 'Conversion complete!' . PHP_EOL;
/** * For excluding certain columns in a query. */ public function scopeExclude($query, $value = []) { $columns = array_merge(['id'], Database::getSchemaTable(static::$_table_id)->columns); return $query->select(array_diff($columns, (array) $value)); }
/** * For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id. */ public static function queryBuilder() { // Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects) Capsule::connection()->setFetchMode(\PDO::FETCH_ASSOC); $table = Database::getSchemaTable(static::$_table_id)->name; return Capsule::table($table); }