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
bfe1550b
Commit
bfe1550b
authored
Jan 31, 2011
by
Max Kanat-Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redesign the Install::DB code for migrating queries to tags, including adding
a transaction and indicate_progress.
https://bugzilla.mozilla.org/show_bug.cgi?id=616185
parent
8d21fa4e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
27 deletions
+52
-27
DB.pm
Bugzilla/Install/DB.pm
+51
-27
strings.txt.pl
template/en/default/setup/strings.txt.pl
+1
-0
No files found.
Bugzilla/Install/DB.pm
View file @
bfe1550b
...
@@ -32,6 +32,9 @@ use Bugzilla::Series;
...
@@ -32,6 +32,9 @@ use Bugzilla::Series;
use
Date::
Parse
;
use
Date::
Parse
;
use
Date::
Format
;
use
Date::
Format
;
use
IO::
File
;
use
IO::
File
;
use
List::
MoreUtils
qw(uniq)
;
use
URI
;
use
URI::
QueryParam
;
# NOTE: This is NOT the function for general table updates. See
# NOTE: This is NOT the function for general table updates. See
# update_table_definitions for that. This is only for the fielddefs table.
# update_table_definitions for that. This is only for the fielddefs table.
...
@@ -3471,50 +3474,71 @@ sub _migrate_user_tags {
...
@@ -3471,50 +3474,71 @@ sub _migrate_user_tags {
my
$dbh
=
Bugzilla
->
dbh
;
my
$dbh
=
Bugzilla
->
dbh
;
return
unless
$dbh
->
bz_column_info
(
'namedqueries'
,
'query_type'
);
return
unless
$dbh
->
bz_column_info
(
'namedqueries'
,
'query_type'
);
my
$tags
=
$dbh
->
selectall_arrayref
(
'SELECT userid, name, query
my
$tags
=
$dbh
->
selectall_arrayref
(
'SELECT
id,
userid, name, query
FROM namedqueries
FROM namedqueries
WHERE query_type != 0'
);
WHERE query_type != 0'
);
my
$sth_tags
=
$dbh
->
prepare
(
'INSERT INTO tags (user_id, name) VALUES (?, ?)'
);
my
$sth_tags
=
$dbh
->
prepare
(
'INSERT INTO tags (user_id, name) VALUES (?, ?)'
);
my
$sth_tag_id
=
$dbh
->
prepare
(
'SELECT id FROM tags WHERE user_id = ? AND name = ?'
);
my
$sth_bug_tag
=
$dbh
->
prepare
(
'INSERT INTO bug_tag (bug_id, tag_id)
my
$sth_bug_tag
=
$dbh
->
prepare
(
'INSERT INTO bug_tag (bug_id, tag_id)
VALUES (?, ?)'
);
VALUES (?, ?)'
);
my
$sth_nq
=
$dbh
->
prepare
(
'UPDATE namedqueries SET query = ?
my
$sth_nq
=
$dbh
->
prepare
(
'UPDATE namedqueries SET query = ?
WHERE userid = ? AND name = ?'
);
WHERE id = ?'
);
my
$sth_nq_footer
=
$dbh
->
prepare
(
'DELETE FROM namedqueries_link_in_footer
WHERE user_id = ? AND namedquery_id = ?'
);
if
(
scalar
@$tags
)
{
print
install_string
(
'update_queries_to_tags'
),
"\n"
;
}
my
$total
=
scalar
(
@$tags
);
my
$current
=
0
;
$dbh
->
bz_start_transaction
();
foreach
my
$tag
(
@$tags
)
{
foreach
my
$tag
(
@$tags
)
{
my
(
$user_id
,
$name
,
$query
)
=
@$tag
;
my
(
$
query_id
,
$
user_id
,
$name
,
$query
)
=
@$tag
;
# Tags are all lowercase.
# Tags are all lowercase.
my
$tag_name
=
lc
(
$name
);
my
$tag_name
=
lc
(
$name
);
# Some queries were incorrectly parsed when _migrate_user_tags()
$sth_tags
->
execute
(
$user_id
,
$tag_name
);
# was first implemented, and so some tags may have already been
# added to the DB. We don't want to crash in that case.
my
$tag_id
=
$dbh
->
selectrow_array
(
$sth_tag_id
,
eval
{
$sth_tags
->
execute
(
$user_id
,
$tag_name
);
};
undef
,
$user_id
,
$tag_name
);
my
$tag_id
=
$dbh
->
selectrow_array
(
'SELECT id FROM tags WHERE user_id = ? AND name = ?'
,
indicate_progress
({
current
=>
++
$current
,
total
=>
$total
,
undef
,
(
$user_id
,
$tag_name
));
every
=>
25
});
my
$columnlist
=
""
;
my
$uri
=
URI
->
new
(
"buglist.cgi?$query"
,
'http'
);
if
(
$query
=~
/^bug_id=([^&;]+)(.*)$/
)
{
my
$bug_id_list
=
$uri
->
query_param_delete
(
'bug_id'
);
my
$buglist
=
$1
;
if
(
!
$bug_id_list
)
{
$columnlist
=
$2
if
$2
;
warn
"No bug_id param for tag $name from user $user_id: $query"
;
# Commas in Bugzilla 3.x are encoded as %2C, but not in 2.22.
next
;
$buglist
=~
s/%2C/,/g
;
}
my
@bug_ids
=
split
(
/[\s,]+/
,
$buglist
);
my
@bug_ids
=
split
(
/[\s,]+/
,
$bug_id_list
);
foreach
my
$bug_id
(
@bug_ids
)
{
# Make sure that things like "001" get converted to "1"
# Some sanity check. We never know.
@bug_ids
=
map
{
int
(
$_
)
}
@bug_ids
;
next
unless
detaint_natural
(
$bug_id
);
# And remove duplicates
# For the same reason as above, let's do it in an eval.
@bug_ids
=
uniq
@bug_ids
;
eval
{
$sth_bug_tag
->
execute
(
$bug_id
,
$tag_id
);
};
foreach
my
$bug_id
(
@bug_ids
)
{
}
# If "int" above failed this might be undef. We also
# don't want to accept bug 0.
next
if
!
$bug_id
;
$sth_bug_tag
->
execute
(
$bug_id
,
$tag_id
);
}
}
# Existing tags may be used in whines, or shared with
# Existing tags may be used in whines, or shared with
# other users. So we convert them rather than delete them.
# other users. So we convert them rather than delete them.
my
$encoded_name
=
url_quote
(
$tag_name
);
$uri
->
query_param
(
'tag'
,
$tag_name
);
$sth_nq
->
execute
(
"tag=$encoded_name$columnlist"
,
$user_id
,
$name
);
$sth_nq
->
execute
(
$uri
->
query
,
$query_id
);
# But we don't keep showing them in the footer.
$sth_nq_footer
->
execute
(
$user_id
,
$query_id
);
}
}
$dbh
->
bz_commit_transaction
();
$dbh
->
bz_drop_column
(
'namedqueries'
,
'query_type'
);
$dbh
->
bz_drop_column
(
'namedqueries'
,
'query_type'
);
}
}
...
...
template/en/default/setup/strings.txt.pl
View file @
bfe1550b
...
@@ -424,6 +424,7 @@ the database, and that file has been renamed to ##data##/comments.bak
...
@@ -424,6 +424,7 @@ the database, and that file has been renamed to ##data##/comments.bak
You
may
delete
the
renamed
file
once
you
have
confirmed
that
all
your
You
may
delete
the
renamed
file
once
you
have
confirmed
that
all
your
quips
were
moved
successfully
.
quips
were
moved
successfully
.
END
END
update_queries_to_tags
=>
"Populating the new tags table:"
,
webdot_bad_htaccess
=>
<<
END
,
webdot_bad_htaccess
=>
<<
END
,
WARNING:
Dependency
graph
images
are
not
accessible
.
WARNING:
Dependency
graph
images
are
not
accessible
.
Delete
##dir##/.htaccess and re-run checksetup.pl.
Delete
##dir##/.htaccess and re-run checksetup.pl.
...
...
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