Bugzilla – Attachment 83717 Details for
Bug 21846
Using emoji as tags doesn't discriminate between emoji when calculating weights or searching
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21846: (follow-up) Add maintenance script
Bug-21846-follow-up-Add-maintenance-script.patch (text/plain), 5.06 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-01-08 16:15:25 UTC
(
hide
)
Description:
Bug 21846: (follow-up) Add maintenance script
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-01-08 16:15:25 UTC
Size:
5.06 KB
patch
obsolete
>From d5ad623bfb8eb01264d8fa4699a6823e36d702b3 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 8 Jan 2019 13:13:46 -0300 >Subject: [PATCH] Bug 21846: (follow-up) Add maintenance script > >This patch adds a maintenance script that generates the missing >tags_approval entries based on the tags_all table, and then recalculates >the weights for both tags_approval and tags_index tables. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > .../data/mysql/atomicupdate/bug_21846.perl | 2 + > misc/maintenance/fix_tags_weight.pl | 140 ++++++++++++++++++ > 2 files changed, 142 insertions(+) > create mode 100755 misc/maintenance/fix_tags_weight.pl > >diff --git a/installer/data/mysql/atomicupdate/bug_21846.perl b/installer/data/mysql/atomicupdate/bug_21846.perl >index 6396f19acb..1c41f3f0d4 100644 >--- a/installer/data/mysql/atomicupdate/bug_21846.perl >+++ b/installer/data/mysql/atomicupdate/bug_21846.perl >@@ -23,4 +23,6 @@ if( CheckVersion( $DBversion ) ) { > > SetVersion( $DBversion ); > print "Upgrade to $DBversion done (Bug 21846 - Using emoji as tags has broken weights)\n"; >+ my $maintenance_script = C4::Context->config("intranetdir") . "misc/maintenance/fix_tags_weight.pl"; >+ print "WARNING: (Bug 21846) You need to manually run $maintenance_script to fix possible issues with tags.\n"; > } >diff --git a/misc/maintenance/fix_tags_weight.pl b/misc/maintenance/fix_tags_weight.pl >new file mode 100755 >index 0000000000..549d170614 >--- /dev/null >+++ b/misc/maintenance/fix_tags_weight.pl >@@ -0,0 +1,140 @@ >+#!/usr/bin/perl >+ >+# Copyright 2018 Theke Solutions >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use C4::Context; >+use C4::Tags; >+ >+use Koha::Database; >+use Koha::Tags; >+use Koha::Tags::Approvals; >+use Koha::Tags::Indexes; >+ >+use Getopt::Long; >+use Pod::Usage; >+ >+=head1 NAME >+ >+fix_tags_weight.pl - Fix weight for tags >+ >+=head1 SYNOPSIS >+ >+fix_tags_weight.pl [ --verbose or -v ] [ --help or -h ] >+ >+ Options: >+ --help or -h Brief usage message >+ --verbose or -v Be verbose >+ >+=head1 DESCRIPTION >+ >+This script fixes the calculated weights for the tags introduced by patrons. >+ >+=over 8 >+ >+=item B<--help> >+ >+Prints a brief usage message and exits. >+ >+=item B<--verbose> >+ >+Prints information about the current weight, and the new one for each term/biblionumber. >+ >+=back >+ >+=cut >+ >+binmode( STDOUT, ":encoding(UTF-8)" ); >+ >+my $help; >+my $verbose; >+ >+my $result = GetOptions( >+ 'help|h' => \$help, >+ 'verbose|v' => \$verbose >+); >+ >+if ( not $result or $help ) { >+ pod2usage(); >+ exit 0; >+} >+ >+fix_tags_approval($verbose); >+fix_tags_index( $verbose ); >+ >+sub fix_tags_approval { >+ >+ my ($verbose) = @_; >+ >+ print "Fix tags_approval\n=================\n" if $verbose; >+ >+ my $dbh = C4::Context->dbh; >+ # Search the terms in tags_all that don't exist in tags_approval >+ my $sth = $dbh->prepare( >+ q{ >+ SELECT term >+ FROM ( >+ SELECT DISTINCT(tags_all.term) AS term, tags_approval.term AS approval FROM tags_all >+ LEFT JOIN tags_approval >+ ON (tags_all.term=tags_approval.term)) a >+ WHERE approval IS NULL; >+ } >+ ); >+ $sth->execute(); >+ my $approved = C4::Context->preference('TagsModeration') ? 0 : 1; >+ >+ # Add missing terms to tags_approval >+ while ( my $row = $sth->fetchrow_hashref ) { >+ my $term = $row->{term}; >+ C4::Tags::add_tag_approval( $term, 0, $approved ); >+ print "Added => $term\n"; >+ } >+ >+ my $approvals = Koha::Tags::Approvals->search; >+ # Recalculate weight_total for all tags_approval rows >+ while ( my $approval = $approvals->next ) { >+ my $count = Koha::Tags->search( { term => $approval->term } )->count; >+ print $approval->term . "\t|\t" . $approval->weight_total . "\t=>\t" . $count . "\n" >+ if $verbose; >+ $approval->weight_total($count)->store; >+ } >+} >+ >+sub fix_tags_index { >+ >+ my ($verbose) = @_; >+ my $indexes = Koha::Tags::Indexes->search; >+ >+ print "Fix tags_index\n==============\n" if $verbose; >+ >+ while ( my $index = $indexes->next ) { >+ my $count >+ = Koha::Tags->search( { term => $index->term, biblionumber => $index->biblionumber } ) >+ ->count; >+ print $index->term . "/" >+ . $index->biblionumber . "\t|\t" >+ . $index->weight >+ . "\t=>\t" >+ . $count . "\n" >+ if $verbose; >+ $index->weight($count)->store; >+ } >+} >+ >+1; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21846
:
82621
|
82622
|
82623
|
83717
|
83759
|
83760
|
83761
|
83762
|
85730
|
85740
|
85741
|
85758
|
85759
|
85760
|
85761
|
85762
|
85763
|
85764