From f5aeed444d80a5510fa146b964fca354c8aa33e6 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 24 Oct 2017 14:19:25 -0400 Subject: [PATCH] Increase mail column size of Contacts quick tables Fixes #4322 --- SOPE/GDLContentStore/contact-oracle.ocs | 2 +- SOPE/GDLContentStore/contact.ocs | 2 +- Scripts/sql-update-3.2.10_to_3.3.0-mysql.sh | 22 ++++++++- Scripts/sql-update-3.2.10_to_3.3.0.sh | 53 +++++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100755 Scripts/sql-update-3.2.10_to_3.3.0.sh diff --git a/SOPE/GDLContentStore/contact-oracle.ocs b/SOPE/GDLContentStore/contact-oracle.ocs index 6028f9ed2..22d23e97c 100644 --- a/SOPE/GDLContentStore/contact-oracle.ocs +++ b/SOPE/GDLContentStore/contact-oracle.ocs @@ -76,7 +76,7 @@ }, { columnName = c_mail; - sqlType = "VARCHAR2(255)"; + sqlType = "CLOB"; allowsNull = YES; }, { diff --git a/SOPE/GDLContentStore/contact.ocs b/SOPE/GDLContentStore/contact.ocs index c2f17528c..db06e1dac 100644 --- a/SOPE/GDLContentStore/contact.ocs +++ b/SOPE/GDLContentStore/contact.ocs @@ -76,7 +76,7 @@ }, { columnName = c_mail; - sqlType = "VARCHAR(255)"; + sqlType = "TEXT"; allowsNull = YES; }, { diff --git a/Scripts/sql-update-3.2.10_to_3.3.0-mysql.sh b/Scripts/sql-update-3.2.10_to_3.3.0-mysql.sh index 89c3ec255..086910d53 100755 --- a/Scripts/sql-update-3.2.10_to_3.3.0-mysql.sh +++ b/Scripts/sql-update-3.2.10_to_3.3.0-mysql.sh @@ -10,6 +10,11 @@ set -e defaultusername=$USER defaulthostname=127.0.0.1 defaultdatabase=sogo +indextable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSFolderInfoURL =/ {print $2}' | awk -F/ '{print $NF}') +if [ -z "$indextable" ]; then + echo "Couldn't fetch OCSFolderInfoURL value, aborting" >&2 + exit 1 +fi read -p "Username ($defaultusername): " username read -p "Hostname ($defaulthostname): " hostname @@ -42,8 +47,23 @@ function growUserProfile() { IFS="$oldIFS" } -echo "This script will ask for the sql password twice" >&2 +function growContactsQuick() { + oldIFS="$IFS" + IFS=" " + part="`echo -e \"ALTER TABLE $table MODIFY c_mail text;\\n\"`"; + sqlscript="$sqlscript$part" + IFS="$oldIFS" +} + +echo "This script will ask for the database password twice" >&2 echo "Converting c_content from TEXT to LONGTEXT in the sogo_user_profile table" >&2 growUserProfile +echo "Converting c_mail from VARCHAR(255) to TEXT in Contacts quick tables" >&2 +tables=`mysql -p -s -u $username -h $hostname $database -e "select SUBSTRING_INDEX(c_quick_location, '/', -1) from $indextable where c_path3 = 'Contacts';"` +for table in $tables; +do + growContactsQuick +done + echo "$sqlscript" | mysql -p -s -u $username -h $hostname $database diff --git a/Scripts/sql-update-3.2.10_to_3.3.0.sh b/Scripts/sql-update-3.2.10_to_3.3.0.sh new file mode 100755 index 000000000..b38bd1f4c --- /dev/null +++ b/Scripts/sql-update-3.2.10_to_3.3.0.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -e +# This script only works with PostgreSQL +# updates c_mail to text in Contacts quick table +# http://www.sogo.nu/bugs/view.php?id=4322 + +defaultusername=$USER +defaulthostname=localhost +defaultdatabase=sogo +indextable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSFolderInfoURL =/ {print $2}' | awk -F/ '{print $NF}') +if [ -z "$indextable" ]; then + echo "Couldn't fetch OCSFolderInfoURL value, aborting" >&2 + exit 1 +fi + +read -p "Username ($defaultusername): " username +read -p "Hostname ($defaulthostname): " hostname +read -p "Database ($defaultdatabase): " database + +if [ -z "$username" ] +then + username=$defaultusername +fi +if [ -z "$hostname" ] +then + hostname=$defaulthostname +fi +if [ -z "$database" ] +then + database=$defaultdatabase +fi + +sqlscript="" + +function growContactsQuick() { + oldIFS="$IFS" + IFS=" " + part="`echo -e \"ALTER TABLE $table ALTER COLUMN c_mail TYPE TEXT;\\n\"`"; + sqlscript="$sqlscript$part" + IFS="$oldIFS" +} + +echo "This script will ask for the database password twice" >&2 +echo "Converting c_mail from VARCHAR(255) to TEXT in Contacts quick tables" >&2 +tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_quick_location, '/', 5) from $indextable where c_path3 = 'Contacts';"` + +for table in $tables; +do + growContactsQuick +done + +echo "$sqlscript" | psql -q -e -U $username -h $hostname $database