Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #221 from joomlatools/feature/220-users
Browse files Browse the repository at this point in the history
Rename user related database tables
  • Loading branch information
johanjanssens committed Jul 10, 2015
2 parents f97f26f + 9665589 commit d318541
Show file tree
Hide file tree
Showing 37 changed files with 156 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function getListQuery()

// Join over the asset groups.
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
->join('LEFT', '#__users_roles AS ag ON ag.id = a.access');

// Select the language home pages
$query->select('l.home AS home')
Expand Down
2 changes: 1 addition & 1 deletion app/administrator/components/com_menus/models/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ public function getModules()

// Join on the asset groups table.
$query->select('ag.title AS access_title')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access')
->join('LEFT', '#__users_roles AS ag ON ag.id = a.access')
->where('a.published >= 0')
->where('a.client_id = 0')
->order('a.position, a.ordering');
Expand Down
2 changes: 1 addition & 1 deletion app/administrator/components/com_menus/models/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected function getListQuery()

// Join over the asset groups.
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
->join('LEFT', '#__users_roles AS ag ON ag.id = a.access');

// Join over the associations.
$assoc = JLanguageAssociations::isEnabled();
Expand Down
2 changes: 1 addition & 1 deletion app/administrator/components/com_menus/models/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function &getModules()
->select('a.id, a.title, a.params, a.position')
->where('module = ' . $db->quote('mod_menu'))
->select('ag.title AS access_title')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
->join('LEFT', '#__users_roles AS ag ON ag.id = a.access');
$db->setQuery($query);

$modules = $db->loadObjectList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function getListQuery()

// Join over the asset groups.
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
->join('LEFT', '#__users_roles AS ag ON ag.id = a.access');

// Join over the module menus
$query->select('MIN(mm.menuid) AS pages')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected function getListQuery()

// Join over the asset groups.
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
->join('LEFT', '#__users_roles AS ag ON ag.id = a.access');

// Filter by access level.
if ($access = $this->getState('filter.access'))
Expand Down
4 changes: 2 additions & 2 deletions app/administrator/components/com_users/helpers/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public static function getGroups()
->select('a.id AS value')
->select('a.title AS text')
->select('COUNT(DISTINCT b.id) AS level')
->from('#__usergroups as a')
->join('LEFT', '#__usergroups AS b ON a.lft > b.lft AND a.rgt < b.rgt')
->from('#__users_groups as a')
->join('LEFT', '#__users_groups AS b ON a.lft > b.lft AND a.rgt < b.rgt')
->group('a.id, a.title, a.lft, a.rgt')
->order('a.lft ASC');
$db->setQuery($query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function getGroup()
$db = $this->getDbo();
$query = $db->getQuery(true)
->select('id, title')
->from('#__usergroups')
->from('#__users_groups')
->where('id = ' . $groupId);

$db->setQuery($query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function getListQuery()
// Filter the items over the group id if set.
if ($groupId = $this->getState('filter.group_id'))
{
$query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id')
$query->join('LEFT', '#__users_groups_users AS map2 ON map2.user_id = a.id')
->where('map2.group_id = ' . (int) $groupId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ protected function getOptions()
$user = JFactory::getUser();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level')
->from('#__usergroups AS a')
->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
->from('#__users_groups AS a')
->join('LEFT', $db->quoteName('#__users_groups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');

// Prevent parenting to children of this item.
if ($id = $this->form->getValue('id'))
{
$query->join('LEFT', $db->quoteName('#__usergroups') . ' AS p ON p.id = ' . (int) $id)
$query->join('LEFT', $db->quoteName('#__users_groups') . ' AS p ON p.id = ' . (int) $id)
->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
}

Expand Down
6 changes: 3 additions & 3 deletions app/administrator/components/com_users/models/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getItems()

// Count the objects in the user group.
$query->select('map.group_id, COUNT(DISTINCT map.user_id) AS user_count')
->from($db->quoteName('#__user_usergroup_map') . ' AS map')
->from($db->quoteName('#__users_groups_users') . ' AS map')
->where('map.group_id IN (' . implode(',', $groupIds) . ')')
->group('map.group_id');

Expand Down Expand Up @@ -171,11 +171,11 @@ protected function getListQuery()
'a.*'
)
);
$query->from($db->quoteName('#__usergroups') . ' AS a');
$query->from($db->quoteName('#__users_groups') . ' AS a');

// Add the level in the tree.
$query->select('COUNT(DISTINCT c2.id) AS level')
->join('LEFT OUTER', $db->quoteName('#__usergroups') . ' AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt')
->join('LEFT OUTER', $db->quoteName('#__users_groups') . ' AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt')
->group('a.id, a.lft, a.rgt, a.parent_id, a.title');

// Filter the comments over the search string if set.
Expand Down
2 changes: 1 addition & 1 deletion app/administrator/components/com_users/models/levels.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function getListQuery()
'a.*'
)
);
$query->from($db->quoteName('#__viewlevels') . ' AS a');
$query->from($db->quoteName('#__users_roles') . ' AS a');

// Add the level in the tree.
$query->group('a.id, a.title, a.ordering, a.rules');
Expand Down
6 changes: 3 additions & 3 deletions app/administrator/components/com_users/models/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ public function batchUser($group_id, $user_ids, $action)
$query = $db->getQuery(true);

// Remove users from the group
$query->delete($db->quoteName('#__user_usergroup_map'))
$query->delete($db->quoteName('#__users_groups_users'))
->where($db->quoteName('user_id') . ' IN (' . implode(',', $user_ids) . ')');

// Only remove users from selected group
Expand Down Expand Up @@ -702,7 +702,7 @@ public function batchUser($group_id, $user_ids, $action)

// First, we need to check if the user is already assigned to a group
$query->select($db->quoteName('user_id'))
->from($db->quoteName('#__user_usergroup_map'))
->from($db->quoteName('#__users_groups_users'))
->where($db->quoteName('group_id') . ' = ' . (int) $group_id);
$db->setQuery($query);
$users = $db->loadColumn();
Expand All @@ -728,7 +728,7 @@ public function batchUser($group_id, $user_ids, $action)
return false;
}

$query->insert($db->quoteName('#__user_usergroup_map'))
$query->insert($db->quoteName('#__users_groups_users'))
->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
$db->setQuery($query);

Expand Down
10 changes: 5 additions & 5 deletions app/administrator/components/com_users/models/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public function getItems()

// Join over the group mapping table.
$query->select('map.user_id, COUNT(map.group_id) AS group_count')
->from('#__user_usergroup_map AS map')
->from('#__users_groups_users AS map')
->where('map.user_id IN (' . implode(',', $userIds) . ')')
->group('map.user_id')
// Join over the user groups table.
->join('LEFT', '#__usergroups AS g2 ON g2.id = map.group_id');
->join('LEFT', '#__users_groups AS g2 ON g2.id = map.group_id');

$db->setQuery($query);

Expand Down Expand Up @@ -284,7 +284,7 @@ protected function getListQuery()

if ($groupId || isset($groups))
{
$query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id')
$query->join('LEFT', '#__user_groups_map AS map2 ON map2.user_id = a.id')
->group($db->quoteName(array('a.id', 'a.name', 'a.username', 'a.password', 'a.block', 'a.sendEmail', 'a.registerDate', 'a.lastvisitDate', 'a.activation', 'a.params', 'a.email')));

if ($groupId)
Expand Down Expand Up @@ -401,8 +401,8 @@ protected function getListQuery()
function _getUserDisplayedGroups($user_id)
{
$db = JFactory::getDbo();
$query = "SELECT title FROM " . $db->quoteName('#__usergroups') . " ug left join " .
$db->quoteName('#__user_usergroup_map') . " map on (ug.id = map.group_id)" .
$query = "SELECT title FROM " . $db->quoteName('#__users_groups') . " ug left join " .
$db->quoteName('#__users_groups_users') . " map on (ug.id = map.group_id)" .
" WHERE map.user_id=" . (int) $user_id;

$db->setQuery($query);
Expand Down
2 changes: 1 addition & 1 deletion app/administrator/modules/mod_logged/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function getList(&$params)
$user = JFactory::getUser();
$query = $db->getQuery(true)
->select('s.time, s.client_id, u.id, u.name, u.username')
->from('#__session AS s')
->from('#__users_sessions AS s')
->join('LEFT', '#__users AS u ON s.userid = u.id')
->where('s.guest = 0');
$db->setQuery($query, 0, $params->get('count', 5));
Expand Down
4 changes: 2 additions & 2 deletions app/administrator/modules/mod_status/mod_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Get the number of back-end logged in users.
$query = $db->getQuery(true)
->select('COUNT(session_id)')
->from('#__session')
->from('#__users_sessions')
->where('guest = 0 AND client_id = 1');

$db->setQuery($query);
Expand All @@ -26,7 +26,7 @@
// Get the number of frontend logged in users.
$query->clear()
->select('COUNT(session_id)')
->from('#__session')
->from('#__users_sessions')
->where('guest = 0 AND client_id = 0');

$db->setQuery($query);
Expand Down
111 changes: 57 additions & 54 deletions install/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,6 @@ CREATE TABLE IF NOT EXISTS `schemas` (
PRIMARY KEY (`extension_id`,`version_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `session`
--

CREATE TABLE IF NOT EXISTS `session` (
`session_id` varchar(200) NOT NULL DEFAULT '',
`client_id` tinyint(3) unsigned NOT NULL DEFAULT 0,
`guest` tinyint(4) unsigned DEFAULT 1,
`time` varchar(14) DEFAULT '',
`data` mediumtext,
`userid` int(11) DEFAULT 0,
`username` varchar(150) DEFAULT '',
PRIMARY KEY (`session_id`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------

Expand All @@ -249,25 +230,6 @@ CREATE TABLE IF NOT EXISTS `template_styles` (

-- --------------------------------------------------------

--
-- Table structure for table `usergroups`
--

CREATE TABLE IF NOT EXISTS `usergroups` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`parent_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Adjacency List Reference Id',
`lft` int(11) NOT NULL DEFAULT 0 COMMENT 'Nested set lft.',
`rgt` int(11) NOT NULL DEFAULT 0 COMMENT 'Nested set rgt.',
`title` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_usergroup_parent_title_lookup` (`parent_id`,`title`),
KEY `idx_usergroup_title_lookup` (`title`),
KEY `idx_usergroup_adjacency_lookup` (`parent_id`),
KEY `idx_usergroup_nested_set_lookup` (`lft`,`rgt`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--
Expand All @@ -294,13 +256,47 @@ CREATE TABLE IF NOT EXISTS `users` (
KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------


--
-- Table structure for table `user_keys`
-- Table structure for table `users_groups`
--

CREATE TABLE IF NOT EXISTS `user_keys` (
CREATE TABLE IF NOT EXISTS `users_groups` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`parent_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Adjacency List Reference Id',
`lft` int(11) NOT NULL DEFAULT 0 COMMENT 'Nested set lft.',
`rgt` int(11) NOT NULL DEFAULT 0 COMMENT 'Nested set rgt.',
`title` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_usergroup_parent_title_lookup` (`parent_id`,`title`),
KEY `idx_usergroup_title_lookup` (`title`),
KEY `idx_usergroup_adjacency_lookup` (`parent_id`),
KEY `idx_usergroup_nested_set_lookup` (`lft`,`rgt`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `users_groups_users`
--

CREATE TABLE IF NOT EXISTS `users_groups_users` (
`user_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Foreign Key to users.id',
`group_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Foreign Key to usergroups.id',
PRIMARY KEY (`user_id`,`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------

--
-- Table structure for table `users_keys`
--

CREATE TABLE IF NOT EXISTS `users_keys` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` varchar(255) NOT NULL,
`token` varchar(255) NOT NULL,
Expand All @@ -321,7 +317,7 @@ CREATE TABLE IF NOT EXISTS `user_keys` (
-- Table structure for table `user_profiles`
--

CREATE TABLE IF NOT EXISTS `user_profiles` (
CREATE TABLE IF NOT EXISTS `users_profiles` (
`user_id` int(11) NOT NULL,
`profile_key` varchar(100) NOT NULL,
`profile_value` text NOT NULL,
Expand All @@ -332,28 +328,35 @@ CREATE TABLE IF NOT EXISTS `user_profiles` (
-- --------------------------------------------------------

--
-- Table structure for table `user_usergroup_map`
-- Table structure for table `users_roles`
--

CREATE TABLE IF NOT EXISTS `user_usergroup_map` (
`user_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Foreign Key to users.id',
`group_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Foreign Key to usergroups.id',
PRIMARY KEY (`user_id`,`group_id`)
CREATE TABLE IF NOT EXISTS `users_roles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`title` varchar(100) NOT NULL DEFAULT '',
`ordering` int(11) NOT NULL DEFAULT 0,
`rules` varchar(5120) NOT NULL COMMENT 'JSON encoded access control.',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_assetgroup_title_lookup` (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `viewlevels`
-- Table structure for table `session`
--

CREATE TABLE IF NOT EXISTS `viewlevels` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`title` varchar(100) NOT NULL DEFAULT '',
`ordering` int(11) NOT NULL DEFAULT 0,
`rules` varchar(5120) NOT NULL COMMENT 'JSON encoded access control.',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_assetgroup_title_lookup` (`title`)
CREATE TABLE IF NOT EXISTS `users_session` (
`session_id` varchar(200) NOT NULL DEFAULT '',
`client_id` tinyint(3) unsigned NOT NULL DEFAULT 0,
`guest` tinyint(4) unsigned DEFAULT 1,
`time` varchar(14) DEFAULT '',
`data` mediumtext,
`userid` int(11) DEFAULT 0,
`username` varchar(150) DEFAULT '',
PRIMARY KEY (`session_id`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Expand Down
4 changes: 2 additions & 2 deletions lib/libraries/cms/application/administrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ protected function render()
// Get the JInput object
$input = $this->input;

$component = $input->getCmd('option');
$view = $input->getCmd('view');
$component = $input->getCmd('option', 'com_users');
$view = $input->getCmd('view', 'login');
$file = $input->getCmd('tmpl', 'index');

if ($component == 'com_users' && $view == 'login') {
Expand Down
Loading

0 comments on commit d318541

Please sign in to comment.