private/cron.log, private/cron_error.log are rotated multiple times

Summary

Users cron log files private/cron.log, private/cron_error.log, are rotated multiple times every night if there are multiple records in table web_domain of type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias'.

Steps to reproduce

  1. [First step]
  2. [Second step]
  3. [and so on...]

see https://www.howtoforge.com/community/threads/many-user-cron-log-files.86937/#post-422325

Correct behaviour

private/cron.log, private/cron_error.log should be rotated only once every night.

Environment

Server OS + version: (Debian 10/Ubuntu 20.04/CentOS 8/...)
ISPConfig version: (3.1.15p3/3.2.3/3.2dev/...)

Software version of the related software:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster

define('ISPC_APP_VERSION', '3.2.4');
$conf['app_version'] = ISPC_APP_VERSION;

Server version: Apache/2.4.38 (Debian)
Server built:   2020-08-25T20:08:29

PHP 7.3.28-1+0~20210503.84+debian10~1.gbp6819da (cli) (built: May  3 2021 11:59:15) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.28, Copyright (c) 1998-2018 Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.4.5, Copyright (c) 2002-2020, by ionCube Ltd.
    with Zend OPcache v7.3.28-1+0~20210503.84+debian10~1.gbp6819da, Copyright (c) 1999-2018, by Zend Technologies

Proposed fix

optional, of course.
if you want to post code snippets, please use

*** 200-logfiles.inc-orig-324.php	2021-05-09 14:47:49.000000000 +0200
--- 200-logfiles.inc.php	2021-05-09 15:25:34.000000000 +0200
***************
*** 71,76 ****
--- 71,79 ----

  		$sql = "SELECT domain_id, domain, type, document_root, web_folder, parent_domain_id, log_retention FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') AND server_id = ?";
  		$records = $app->db->queryAllRecords($sql, $conf['server_id']);
+ 		// ikasp
+ 		// rotate user cron files once
+ 		$cron_logfile_rotated = [];
  		foreach($records as $rec) {

  			//* create traffic statistics based on yesterdays access log file
***************
*** 126,131 ****
--- 129,139 ----
  			foreach($cron_logfiles as $cron_logfile) {
  				$cron_logfile = $rec['document_root'].'/private/' . $cron_logfile;

+ 				// ikasp
+ 				// check if already rotated
+ 				if (isset($cron_logfile_rotated[$cron_logfile]) and $cron_logfile_rotated[$cron_logfile]) continue;
+ 				$cron_logfile_rotated[$cron_logfile] = true;
+
  				// rename older files (move up by one)
  				$num = $log_retention;
  				while($num >= 1) {

or attach a code file. Best is to create a merge request of course.

References

if you know of related bugs or feature requests, please reference them by using #<issuenumber>, e. g. #6105 (closed) if you have done a merge request already, please reference it by using !<mergenumber>, e. g. !1444 (merged) if you know of a forum post on howtoforge.com that deals with this topic, just add the link to the forum topic here

Screenshots

optional, of course.
Add screenshots of the problem by clicking "Attach a file" on the bottom right.

Related log entries