Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
65f999de
Commit
65f999de
authored
Feb 25, 2005
by
mkanat%kerio.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 281550: Remove RelationSet from userprefs.cgi (and thus fix non-ANSI INSERT)
Patch By Max Kanat-Alexander <mkanat@kerio.com> r=LpSolit, a=myk
parent
12feab49
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
33 deletions
+81
-33
Util.pm
Bugzilla/Util.pm
+48
-13
userprefs.cgi
userprefs.cgi
+33
-20
No files found.
Bugzilla/Util.pm
View file @
65f999de
...
...
@@ -33,6 +33,7 @@ use base qw(Exporter);
html_quote url_quote value_quote xml_quote
css_class_quote
lsearch max min
diff_arrays
trim diff_strings wrap_comment
format_time format_time_decimal
file_mod_time)
;
...
...
@@ -166,6 +167,29 @@ sub min {
return
$min
;
}
sub
diff_arrays
{
my
(
$old_ref
,
$new_ref
)
=
@_
;
my
@old
=
@$old_ref
;
my
@new
=
@$new_ref
;
# For each pair of (old, new) entries:
# If they're equal, set them to empty. When done, @old contains entries
# that were removed; @new contains ones that got added.
foreach
my
$oldv
(
@old
)
{
foreach
my
$newv
(
@new
)
{
next
if
(
$newv
eq
''
);
if
(
$oldv
eq
$newv
)
{
$newv
=
$oldv
=
''
;
}
}
}
my
@removed
=
grep
{
$_
ne
''
}
@old
;
my
@added
=
grep
{
$_
ne
''
}
@new
;
return
(
\
@removed
,
\
@added
);
}
sub
trim
{
my
(
$str
)
=
@_
;
if
(
$str
)
{
...
...
@@ -184,20 +208,10 @@ sub diff_strings {
my
@old
=
split
(
" "
,
$oldstr
);
my
@new
=
split
(
" "
,
$newstr
);
# For each pair of (old, new) entries:
# If they're equal, set them to empty. When done, @old contains entries
# that were removed; @new contains ones that got added.
my
(
$rem
,
$add
)
=
diff_arrays
(
\
@old
,
\
@new
);
foreach
my
$oldv
(
@old
)
{
foreach
my
$newv
(
@new
)
{
next
if
(
$newv
eq
''
);
if
(
$oldv
eq
$newv
)
{
$newv
=
$oldv
=
''
;
}
}
}
my
$removed
=
join
(
", "
,
grep
{
$_
ne
''
}
@old
);
my
$added
=
join
(
", "
,
grep
{
$_
ne
''
}
@new
);
my
$removed
=
join
(
", "
,
@$rem
);
my
$added
=
join
(
", "
,
@$add
);
return
(
$removed
,
$added
);
}
...
...
@@ -303,6 +317,9 @@ Bugzilla::Util - Generic utility functions for bugzilla
$val = max($a, $b, $c);
$val = min($a, $b, $c);
# Data manipulation
($removed, $added) = diff_arrays(\@old, \@new);
# Functions for manipulating strings
$val = trim(" abc ");
($removed, $added) = diff_strings($old, $new);
...
...
@@ -415,6 +432,24 @@ Returns the minimum from a set of values.
=back
=head2 Data Manipulation
=over 4
=item C<diff_arrays(\@old, \@new)>
Description: Takes two arrayrefs, and will tell you what it takes to
get from @old to @new.
Params: @old = array that you are changing from
@new = array that you are changing to
Returns: A list of two arrayrefs. The first is a reference to an
array containing items that were removed from @old. The
second is a reference to an array containing items
that were added to @old. If both returned arrays are
empty, @old and @new contain the same values.
=back
=head2 String Manipulation
=over 4
...
...
userprefs.cgi
View file @
65f999de
...
...
@@ -33,8 +33,6 @@ use Bugzilla::User;
require
"CGI.pl"
;
use
Bugzilla::
RelationSet
;
# Use global template variables.
use
vars
qw($template $vars $userid)
;
...
...
@@ -142,11 +140,14 @@ sub SaveAccount {
sub
DoEmail
{
my
$dbh
=
Bugzilla
->
dbh
;
if
(
Param
(
"supportwatchers"
))
{
my
$watcheduserSet
=
new
Bugzilla::
RelationSet
;
$watcheduserSet
->
mergeFromDB
(
"SELECT watched FROM watch WHERE"
.
" watcher=$userid"
);
$vars
->
{
'watchedusers'
}
=
$watcheduserSet
->
toString
();
my
$watched_ref
=
$dbh
->
selectcol_arrayref
(
"SELECT profiles.login_name FROM watch, profiles"
.
" WHERE watcher = ? AND watch.watched = profiles.userid"
,
undef
,
$userid
);
$vars
->
{
'watchedusers'
}
=
join
(
','
,
@$watched_ref
);
}
SendSQL
(
"SELECT emailflags FROM profiles WHERE userid = $userid"
);
...
...
@@ -232,20 +233,32 @@ sub SaveEmail {
$dbh
->
bz_lock_tables
(
'watch WRITE'
,
'profiles READ'
);
# what the db looks like now
my
$origWatchedUsers
=
new
Bugzilla::
RelationSet
;
$origWatchedUsers
->
mergeFromDB
(
"SELECT watched FROM watch WHERE"
.
" watcher=$userid"
);
# Update the database to look like the form
my
$newWatchedUsers
=
new
Bugzilla::
RelationSet
(
$cgi
->
param
(
'watchedusers'
));
my
@CCDELTAS
=
$origWatchedUsers
->
generateSqlDeltas
(
$newWatchedUsers
,
"watch"
,
"watcher"
,
$userid
,
"watched"
);
(
$CCDELTAS
[
0
]
eq
""
)
||
SendSQL
(
$CCDELTAS
[
0
]);
(
$CCDELTAS
[
1
]
eq
""
)
||
SendSQL
(
$CCDELTAS
[
1
]);
my
$old_watch_ids
=
$dbh
->
selectcol_arrayref
(
"SELECT watched FROM watch"
.
" WHERE watcher = ?"
,
undef
,
$userid
);
# The new information given to us by the user.
my
@new_watch_names
=
split
(
/[,\s]+/
,
$cgi
->
param
(
'watchedusers'
));
my
@new_watch_ids
=
();
foreach
my
$username
(
@new_watch_names
)
{
my
$watched_userid
=
DBNameToIdAndCheck
(
trim
(
$username
));
push
(
@new_watch_ids
,
$watched_userid
);
}
my
(
$removed
,
$added
)
=
diff_arrays
(
$old_watch_ids
,
\
@new_watch_ids
);
# Remove people who were removed.
my
$delete_sth
=
$dbh
->
prepare
(
'DELETE FROM watch WHERE watched = ?'
.
' AND watcher = ?'
);
foreach
my
$remove_me
(
@$removed
)
{
$delete_sth
->
execute
(
$remove_me
,
$userid
);
}
# Add people who were added.
my
$insert_sth
=
$dbh
->
prepare
(
'INSERT INTO watch (watched, watcher)'
.
' VALUES (?, ?)'
);
foreach
my
$add_me
(
@$added
)
{
$insert_sth
->
execute
(
$add_me
,
$userid
);
}
$dbh
->
bz_unlock_tables
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment