From 94c98718ef9a862a4aafca0aa58a9952a047ca16 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 17 Aug 2021 09:15:25 +0200 Subject: [PATCH] update script to remove hashes/non-email-addresses from egw_history_log.share_email --- api/setup/setup.inc.php | 2 +- api/setup/tables_update.inc.php | 15 ++++++++++++++- api/src/Storage/History.php | 11 ++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/api/setup/setup.inc.php b/api/setup/setup.inc.php index b169d6feeb..ab8a48d38b 100644 --- a/api/setup/setup.inc.php +++ b/api/setup/setup.inc.php @@ -11,7 +11,7 @@ /* Basic information about this app */ $setup_info['api']['name'] = 'api'; $setup_info['api']['title'] = 'EGroupware API'; -$setup_info['api']['version'] = '21.1'; +$setup_info['api']['version'] = '21.1.001'; $setup_info['api']['versions']['current_header'] = '1.29'; // maintenance release in sync with changelog in doc/rpm-build/debian.changes $setup_info['api']['versions']['maintenance_release'] = '21.1.20210723'; diff --git a/api/setup/tables_update.inc.php b/api/setup/tables_update.inc.php index 33af6b1778..7d4893e720 100644 --- a/api/setup/tables_update.inc.php +++ b/api/setup/tables_update.inc.php @@ -789,5 +789,18 @@ function api_upgrade20_1_002() */ function api_upgrade20_1_003() { - return $GLOBALS['setup_info']['activesync']['currentver'] = '21.1'; + return $GLOBALS['setup_info']['api']['currentver'] = '21.1'; +} + +/** + * Remove non-email addresses from egw_history_log.share_email + * + * @return string + */ +function api_upgrade21_1() +{ + $GLOBALS['egw_setup']->db->query("UPDATE egw_history_log SET share_email=NULL, history_timestamp=history_timestamp". + " WHERE share_email is NOT NULL AND share_email NOT LIKE '%@%'", __LINE__, __FILE__); + + return $GLOBALS['setup_info']['api']['currentver'] = '21.1.001'; } diff --git a/api/src/Storage/History.php b/api/src/Storage/History.php index 25a9aa5171..3e6d778efb 100644 --- a/api/src/Storage/History.php +++ b/api/src/Storage/History.php @@ -21,7 +21,7 @@ use EGroupware\Api; /** * Record history logging service * - * This class need to be instanciated for EACH app, which wishes to use it! + * This class need to be instantiated for EACH app, which wishes to use it! */ class History { @@ -59,8 +59,8 @@ class History */ function __construct($appname = '', $user = null) { - $this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp']; - $this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id']; + $this->appname = $appname ?: $GLOBALS['egw_info']['flags']['currentapp']; + $this->user = $user ?: $GLOBALS['egw_info']['user']['account_id']; if(is_object($GLOBALS['egw_setup']->db)) { @@ -148,6 +148,7 @@ class History if($new_value != $old_value) { $share_with = static::get_share_with($appname, $id); + $GLOBALS['egw']->db->insert(self::TABLE, array( 'history_record_id' => $id, 'history_appname' => $appname, @@ -172,11 +173,11 @@ class History * @param $appname * @param $id * - * @return string + * @return ?string */ static function get_share_with($appname, $id) { - $share_with = ''; + $share_with = null; foreach(isset($GLOBALS['egw']->sharing) ? $GLOBALS['egw']->sharing : [] as $token => $share_obj) { // Make sure share is of the correct type to access an entry, and it is the correct entry