Skip to content

Commit

Permalink
Renamed database table 'groups' to 'permission_groups' (keyword in My…
Browse files Browse the repository at this point in the history
…SQL >= 8).
  • Loading branch information
jepf committed Jul 16, 2021
1 parent 27108a2 commit fafd56a
Show file tree
Hide file tree
Showing 44 changed files with 173 additions and 136 deletions.
11 changes: 4 additions & 7 deletions Kernel/System/CustomerGroup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,12 @@ sub GroupMemberList {
%Data = $Kernel::OM->Get('Kernel::System::Group')->GroupList( Valid => 1 );
}
else {
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

# if it's active, return just the permitted groups
my $SQL =
'SELECT g.id, g.name, gu.permission_key, gu.permission_value, gu.user_id'
. ' FROM groups g, group_customer_user gu'
. ' FROM permission_groups g, group_customer_user gu'
. ' WHERE g.valid_id IN ( ' . join ', ', $Kernel::OM->Get('Kernel::System::Valid')->ValidIDsGet() . ')'
. ' AND g.id = gu.group_id AND gu.permission_value = 1'
. " AND gu.permission_key IN (?, 'rw')";
Expand Down Expand Up @@ -639,13 +638,12 @@ sub GroupCustomerList {
%Data = $Kernel::OM->Get('Kernel::System::Group')->GroupList( Valid => 1 );
}
else {
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

# if it's active, return just the permitted groups
my $SQL =
'SELECT g.id, g.name, gc.permission_key, gc.permission_value, gc.customer_id'
. ' FROM groups g, group_customer gc'
. ' FROM permission_groups g, group_customer gc'
. ' WHERE g.valid_id IN ( ' . join ', ', $Kernel::OM->Get('Kernel::System::Valid')->ValidIDsGet() . ')'
. ' AND g.id = gc.group_id AND gc.permission_value = 1'
. " AND gc.permission_key IN (?, 'rw')"
Expand Down Expand Up @@ -904,7 +902,6 @@ sub GroupLookup {
);
return ${$Cache} if ( ref $Cache eq 'SCALAR' );

# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

# get data
Expand All @@ -914,13 +911,13 @@ sub GroupLookup {
if ( $Param{Group} ) {
$Param{What} = $Param{Group};
$Suffix = 'GroupID';
$SQL = 'SELECT id FROM groups WHERE name = ?';
$SQL = 'SELECT id FROM permission_groups WHERE name = ?';
push @Bind, \$Param{Group};
}
else {
$Param{What} = $Param{GroupID};
$Suffix = 'Group';
$SQL = 'SELECT name FROM groups WHERE id = ?';
$SQL = 'SELECT name FROM permission_groups WHERE id = ?';
push @Bind, \$Param{GroupID};
}
return if !$DBObject->Prepare(
Expand Down
18 changes: 10 additions & 8 deletions Kernel/System/Group.pm
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,25 @@ sub GroupAdd {
return;
}

# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

# insert new group
return if !$DBObject->Do(
SQL => 'INSERT INTO groups (name, comments, valid_id, '
SQL => 'INSERT INTO permission_groups (name, comments, valid_id, '
. ' create_time, create_by, change_time, change_by)'
. ' VALUES (?, ?, ?, current_timestamp, ?, current_timestamp, ?)',
Bind => [
\$Param{Name}, \$Param{Comment}, \$Param{ValidID}, \$Param{UserID}, \$Param{UserID},
\$Param{Name},
\$Param{Comment},
\$Param{ValidID},
\$Param{UserID},
\$Param{UserID},
],
);

# get new group id
return if !$DBObject->Prepare(
SQL => 'SELECT id FROM groups WHERE name = ?',
SQL => 'SELECT id FROM permission_groups WHERE name = ?',
Bind => [ \$Param{Name} ],
);

Expand Down Expand Up @@ -277,12 +280,11 @@ sub GroupUpdate {

return 1 if !$ChangeRequired;

# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

# update group in database
return if !$DBObject->Do(
SQL => 'UPDATE groups SET name = ?, comments = ?, valid_id = ?, '
SQL => 'UPDATE permission_groups SET name = ?, comments = ?, valid_id = ?, '
. 'change_time = current_timestamp, change_by = ? WHERE id = ?',
Bind => [
\$Param{Name}, \$Param{Comment}, \$Param{ValidID}, \$Param{UserID}, \$Param{ID},
Expand Down Expand Up @@ -456,12 +458,12 @@ sub GroupDataList {
);
return %{$Cache} if $Cache;

# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

# get all group data from database
return if !$DBObject->Prepare(
SQL => 'SELECT id, name, comments, valid_id, create_time, create_by, change_time, change_by FROM groups',
SQL =>
'SELECT id, name, comments, valid_id, create_time, create_by, change_time, change_by FROM permission_groups',
);

# fetch the result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ sub Run {
Label => Translatable("Roles"),
},
{
SQL => "SELECT count(*) FROM groups",
SQL => "SELECT count(*) FROM permission_groups",
Identifier => 'GroupCount',
Label => Translatable("Groups"),
},
Expand Down Expand Up @@ -128,7 +128,6 @@ sub Run {
},
);

# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

my %Counts;
Expand Down
2 changes: 1 addition & 1 deletion scripts/MigrateToZnuny6_1/MigrateGroups.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sub _MigrateGroupNames {
# Rename group.
my $RenamingOK = $DBObject->Do(
SQL => '
UPDATE groups SET name = ?
UPDATE permission_groups SET name = ?
WHERE id = ?
',
Bind => [
Expand Down
10 changes: 4 additions & 6 deletions scripts/MigrateToZnuny6_1/UpgradeDatabaseStructure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ sub Run {
my $Verbose = $Param{CommandlineOptions}->{Verbose} || 0;

my @Tasks = (

# {
# Message =>
# 'Add table for dynamic field object names and add an index to speed up searching dynamic field text values',
# Module => 'DynamicFieldChanges',
# },
{
Message => 'Renaming database tables',
Module => 'RenameTables',
},
);

print "\n" if $Verbose;
Expand Down
41 changes: 41 additions & 0 deletions scripts/MigrateToZnuny6_1/UpgradeDatabaseStructure/RenameTables.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# --
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
## nofilter(TidyAll::Plugin::OTRS::Perl::Pod::NamePod)

package scripts::MigrateToZnuny6_1::UpgradeDatabaseStructure::RenameTables; ## no critic

use strict;
use warnings;

use parent qw(scripts::MigrateToZnuny6_1::Base);

use Kernel::System::VariableCheck qw(:all);

our @ObjectDependencies;

=head1 NAME
Rename database tables.
=cut

sub Run {
my ( $Self, %Param ) = @_;

my @XML = (
'<TableAlter NameOld="groups" NameNew="permission_groups"/>',
);

return if !$Self->ExecuteXMLDBArray(
XMLArray => \@XML,
);

return 1;
}

1;
14 changes: 7 additions & 7 deletions scripts/database/otrs-initial_insert.mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ INSERT INTO users (id, first_name, last_name, login, pw, valid_id, create_by, cr
VALUES
(1, 'Admin', 'OTRS', 'root@localhost', 'roK20XGbWEsSM', 1, 1, current_timestamp, 1, current_timestamp);
# ----------------------------------------------------------
# insert into table groups
# insert into table permission_groups
# ----------------------------------------------------------
INSERT INTO groups (id, name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (id, name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
(1, 'users', 'Group for default access.', 1, 1, current_timestamp, 1, current_timestamp);
# ----------------------------------------------------------
# insert into table groups
# insert into table permission_groups
# ----------------------------------------------------------
INSERT INTO groups (id, name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (id, name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
(2, 'admin', 'Group of all administrators.', 1, 1, current_timestamp, 1, current_timestamp);
# ----------------------------------------------------------
# insert into table groups
# insert into table permission_groups
# ----------------------------------------------------------
INSERT INTO groups (id, name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (id, name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
(3, 'stats', 'Group for statistics access.', 1, 1, current_timestamp, 1, current_timestamp);
# ----------------------------------------------------------
Expand Down Expand Up @@ -854,7 +854,7 @@ INSERT INTO article_data_mime_plain (id, article_id, body, create_by, create_tim
(1, 1, 'From: Znuny <hello@znuny.org>
To: Your Znuny service desk <znuny@localhost>
Subject: Znuny says hi!
Content-Type: text/plain; charset=utf-8
Content-Type: text/plain\; charset=utf-8
Content-Transfer-Encoding: 8bit
We welcome you to Znuny, our ticketing solution based on the well-known OTRS ((Community Edition)) which we forked to make things different.
Expand Down
12 changes: 6 additions & 6 deletions scripts/database/otrs-initial_insert.oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ INSERT INTO users (first_name, last_name, login, pw, valid_id, create_by, create
VALUES
('Admin', 'OTRS', 'root@localhost', 'roK20XGbWEsSM', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
-- insert into table groups
-- insert into table permission_groups
-- ----------------------------------------------------------
INSERT INTO groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
('users', 'Group for default access.', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
-- insert into table groups
-- insert into table permission_groups
-- ----------------------------------------------------------
INSERT INTO groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
('admin', 'Group of all administrators.', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
-- insert into table groups
-- insert into table permission_groups
-- ----------------------------------------------------------
INSERT INTO groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
('stats', 'Group for statistics access.', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions scripts/database/otrs-initial_insert.postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ INSERT INTO users (first_name, last_name, login, pw, valid_id, create_by, create
VALUES
('Admin', 'OTRS', 'root@localhost', 'roK20XGbWEsSM', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
-- insert into table groups
-- insert into table permission_groups
-- ----------------------------------------------------------
INSERT INTO groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
('users', 'Group for default access.', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
-- insert into table groups
-- insert into table permission_groups
-- ----------------------------------------------------------
INSERT INTO groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
('admin', 'Group of all administrators.', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
-- insert into table groups
-- insert into table permission_groups
-- ----------------------------------------------------------
INSERT INTO groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
INSERT INTO permission_groups (name, comments, valid_id, create_by, create_time, change_by, change_time)
VALUES
('stats', 'Group for statistics access.', 1, 1, current_timestamp, 1, current_timestamp);
-- ----------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions scripts/database/otrs-initial_insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Data Key="change_time">current_timestamp</Data>
</Insert>

<Insert Table="groups">
<Insert Table="permission_groups">
<Data Key="id" Type="AutoIncrement">1</Data>
<Data Key="name" Type="Quote">users</Data>
<Data Key="comments" Type="Quote" Translatable="1">Group for default access.</Data>
Expand All @@ -50,7 +50,7 @@
<Data Key="change_by">1</Data>
<Data Key="change_time">current_timestamp</Data>
</Insert>
<Insert Table="groups">
<Insert Table="permission_groups">
<Data Key="id" Type="AutoIncrement">2</Data>
<Data Key="name" Type="Quote">admin</Data>
<Data Key="comments" Type="Quote" Translatable="1">Group of all administrators.</Data>
Expand All @@ -60,7 +60,7 @@
<Data Key="change_by">1</Data>
<Data Key="change_time">current_timestamp</Data>
</Insert>
<Insert Table="groups">
<Insert Table="permission_groups">
<Data Key="id" Type="AutoIncrement">3</Data>
<Data Key="name" Type="Quote">stats</Data>
<Data Key="comments" Type="Quote" Translatable="1">Group for statistics access.</Data>
Expand Down

0 comments on commit fafd56a

Please sign in to comment.