Skip to content

Commit

Permalink
Convert pruning time span from RC6 to number of hours
Browse files Browse the repository at this point in the history
  • Loading branch information
kasimi committed Oct 16, 2016
1 parent 4a663a4 commit 41db107
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
36 changes: 35 additions & 1 deletion migrations/mchat_2_0_0_rc7.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 41db107

Please sign in to comment.