From 41db1079ac4f1c9f6a1efb269b00c251b94641e4 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sun, 16 Oct 2016 13:01:59 +0200 Subject: [PATCH] Convert pruning time span from RC6 to number of hours --- composer.json | 2 +- migrations/mchat_2_0_0_rc7.php | 36 +++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d3fca26..bcb8f7e 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "mChat", "homepage": "https://github.com/kasimi/mChat", "version": "2.0.0-RC7", - "time": "2016-10-03", + "time": "2016-10-16", "keywords": ["phpbb", "extension", "mchat"], "license": "GPL-2.0", "authors": [ diff --git a/migrations/mchat_2_0_0_rc7.php b/migrations/mchat_2_0_0_rc7.php index 08d7ffe..3a28d23 100644 --- a/migrations/mchat_2_0_0_rc7.php +++ b/migrations/mchat_2_0_0_rc7.php @@ -26,8 +26,42 @@ public function update_data() return array( array('config.update', array('mchat_version', '2.0.0-RC7')), - array('config.update', array('mchat_prune', 0)), array('config.add', array('mchat_prune_mode', 0)), + array('custom', array(array($this, 'fix_pruning_time_span'))), ); } + + /** + * In 2.0.0-RC6 it was possible to specify a time span like '45 minutes' or '4 days' to + * keep the messages from that time span when pruning messages. Since 2.0.0-RC7 it is + * only possible to specify the number of hours, days or weeks. If such a time span is + * defined in the mchat_prune_num config value it is converted here to the number of + * hours, rounded up to the next full hour. + */ + public function fix_pruning_time_span() + { + $prune_num = $this->config['mchat_prune_num']; + + if (false === filter_var($prune_num, FILTER_VALIDATE_INT)) + { + $time_span = strtotime($prune_num, 0); + + if ($time_span !== false) + { + // A time span is specified. Convert it to number of hours. + $hours = ceil($time_span / 60 / 60); + + $sql = 'UPDATE ' . CONFIG_TABLE . ' + SET config_value = ' . (int) $hours . " + WHERE config_name = 'mchat_prune_num'"; + $this->sql_query($sql); + + // Set to 'hours' mode + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 1 + WHERE config_name = 'mchat_prune_mode'"; + $this->sql_query($sql); + } + } + } }