From a26e86ee1efdc73c91f6be3fd0132ce84ceb2ba9 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 1 Sep 2015 13:44:21 +0000 Subject: [PATCH] Change egw_addressbook.contact_pubkey to 16k as an ascii-armored 4096 bit PGP key is ~12k --- phpgwapi/setup/setup.inc.php | 3 ++- phpgwapi/setup/tables_current.inc.php | 2 +- phpgwapi/setup/tables_update.inc.php | 38 +++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/phpgwapi/setup/setup.inc.php b/phpgwapi/setup/setup.inc.php index a9d1b9b72d..f799f1a839 100755 --- a/phpgwapi/setup/setup.inc.php +++ b/phpgwapi/setup/setup.inc.php @@ -12,7 +12,7 @@ /* Basic information about this app */ $setup_info['phpgwapi']['name'] = 'phpgwapi'; $setup_info['phpgwapi']['title'] = 'EGroupware API'; -$setup_info['phpgwapi']['version'] = '14.3.902'; +$setup_info['phpgwapi']['version'] = '14.3.903'; $setup_info['phpgwapi']['versions']['current_header'] = '1.29'; $setup_info['phpgwapi']['enable'] = 3; $setup_info['phpgwapi']['app_order'] = 1; @@ -73,3 +73,4 @@ $setup_info['groupdav']['license'] = 'GPL'; $setup_info['groupdav']['hooks']['preferences'] = 'groupdav_hooks::menus'; $setup_info['groupdav']['hooks']['settings'] = 'groupdav_hooks::settings'; + diff --git a/phpgwapi/setup/tables_current.inc.php b/phpgwapi/setup/tables_current.inc.php index a7bf2b9c9d..b078e4a2e6 100644 --- a/phpgwapi/setup/tables_current.inc.php +++ b/phpgwapi/setup/tables_current.inc.php @@ -270,7 +270,7 @@ $phpgw_baseline = array( 'contact_note' => array('type' => 'varchar','precision' => '8192','comment' => 'notes field'), 'contact_tz' => array('type' => 'varchar','precision' => '8','comment' => 'timezone difference'), 'contact_geo' => array('type' => 'ascii','precision' => '32','comment' => 'currently not used'), - 'contact_pubkey' => array('type' => 'ascii','precision' => '8192','comment' => 'public key'), + 'contact_pubkey' => array('type' => 'ascii','precision' => '16384','comment' => 'public key'), 'contact_created' => array('type' => 'int','meta' => 'timestamp','precision' => '8','comment' => 'timestamp of the creation'), 'contact_creator' => array('type' => 'int','meta' => 'user','precision' => '4','nullable' => False,'comment' => 'account id of the creator'), 'contact_modified' => array('type' => 'int','meta' => 'timestamp','precision' => '8','nullable' => False,'comment' => 'timestamp of the last modified'), diff --git a/phpgwapi/setup/tables_update.inc.php b/phpgwapi/setup/tables_update.inc.php index c855d4d3fb..5a7fb7723e 100644 --- a/phpgwapi/setup/tables_update.inc.php +++ b/phpgwapi/setup/tables_update.inc.php @@ -525,11 +525,17 @@ function phpgwapi_upgrade14_2_017() 'precision' => '32', 'comment' => 'currently not used' )); - $GLOBALS['egw_setup']->oProc->AlterColumn('egw_addressbook','contact_pubkey',array( - 'type' => 'ascii', - 'precision' => '8192', - 'comment' => 'public key' - )); + // only shorten pubkey to varchar(16384), if it does NOT contain longer input and it can be stored as varchar + $max_pubkey_length = $GLOBALS['egw']->db->query('SELECT MAX(LENGTH(contact_pubkey)) FROM egw_addressbook')->fetchColumn(); + // returns NULL, if there are no rows! + if ((int)$max_pubkey_length <= 16384 && $GLOBALS['egw_setup']->oProc->max_varchar_length >= 16384) + { + $GLOBALS['egw_setup']->oProc->AlterColumn('egw_addressbook','contact_pubkey',array( + 'type' => 'ascii', + 'precision' => '16384', + 'comment' => 'public key' + )); + } $GLOBALS['egw_setup']->oProc->AlterColumn('egw_addressbook','contact_uid',array( 'type' => 'ascii', 'precision' => '128', @@ -895,3 +901,25 @@ function phpgwapi_upgrade14_3_901() } return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '14.3.902'; } + +/** + * Change egw_addressbook.contact_pubkey to 16k as an ascii-armored 4096 bit PGP key is ~12k + * + * @return type + */ +function phpgwapi_upgrade14_3_902() +{ + // only shorten pubkey to varchar(16384), if it does NOT contain longer input and it can be stored as varchar + $max_pubkey_length = $GLOBALS['egw']->db->query('SELECT MAX(LENGTH(contact_pubkey)) FROM egw_addressbook')->fetchColumn(); + // returns NULL, if there are no rows! + if ((int)$max_pubkey_length <= 16384 && $GLOBALS['egw_setup']->oProc->max_varchar_length >= 16384) + { + $GLOBALS['egw_setup']->oProc->AlterColumn('egw_addressbook','contact_pubkey',array( + 'type' => 'ascii', + 'precision' => '16384', + 'comment' => 'public key' + )); + } + + return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '14.3.903'; +}