mirror of https://github.com/louislam/uptime-kuma
				
				
				
			Fixed negative retention time values
Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>pull/2569/head
							parent
							
								
									f3d3e064f8
								
							
						
					
					
						commit
						32f7a0084a
					
				| 
						 | 
					@ -25,15 +25,20 @@ const DEFAULT_KEEP_PERIOD = 180;
 | 
				
			||||||
        parsedPeriod = DEFAULT_KEEP_PERIOD;
 | 
					        parsedPeriod = DEFAULT_KEEP_PERIOD;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    log(`Clearing Data older than ${parsedPeriod} days...`);
 | 
					    if (parsedPeriod < 1) {
 | 
				
			||||||
 | 
					        log(`Data deletion has been disabled as period is less than 1. Period is ${parsedPeriod} days.`);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					        log(`Clearing Data older than ${parsedPeriod} days...`);
 | 
				
			||||||
        await R.exec(
 | 
					
 | 
				
			||||||
            "DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
 | 
					        try {
 | 
				
			||||||
            [ parsedPeriod ]
 | 
					            await R.exec(
 | 
				
			||||||
        );
 | 
					                "DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
 | 
				
			||||||
    } catch (e) {
 | 
					                [ parsedPeriod ]
 | 
				
			||||||
        log(`Failed to clear old data: ${e.message}`);
 | 
					            );
 | 
				
			||||||
 | 
					        } catch (e) {
 | 
				
			||||||
 | 
					            log(`Failed to clear old data: ${e.message}`);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    exit();
 | 
					    exit();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@
 | 
				
			||||||
                        settings.keepDataPeriodDays,
 | 
					                        settings.keepDataPeriodDays,
 | 
				
			||||||
                    ])
 | 
					                    ])
 | 
				
			||||||
                }}
 | 
					                }}
 | 
				
			||||||
 | 
					                {{ $t("infiniteRetention") }}
 | 
				
			||||||
            </label>
 | 
					            </label>
 | 
				
			||||||
            <input
 | 
					            <input
 | 
				
			||||||
                id="keepDataPeriodDays"
 | 
					                id="keepDataPeriodDays"
 | 
				
			||||||
| 
						 | 
					@ -14,9 +15,12 @@
 | 
				
			||||||
                type="number"
 | 
					                type="number"
 | 
				
			||||||
                class="form-control"
 | 
					                class="form-control"
 | 
				
			||||||
                required
 | 
					                required
 | 
				
			||||||
                min="1"
 | 
					                min="0"
 | 
				
			||||||
                step="1"
 | 
					                step="1"
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
 | 
					            <div v-if="settings.keepDataPeriodDays < 0" class="form-text">
 | 
				
			||||||
 | 
					                {{ $t("dataRetentionTimeError") }}
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="my-4">
 | 
					        <div class="my-4">
 | 
				
			||||||
            <button class="btn btn-primary" type="button" @click="saveSettings()">
 | 
					            <button class="btn btn-primary" type="button" @click="saveSettings()">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -675,4 +675,6 @@ export default {
 | 
				
			||||||
    "General Monitor Type": "General Monitor Type",
 | 
					    "General Monitor Type": "General Monitor Type",
 | 
				
			||||||
    "Passive Monitor Type": "Passive Monitor Type",
 | 
					    "Passive Monitor Type": "Passive Monitor Type",
 | 
				
			||||||
    "Specific Monitor Type": "Specific Monitor Type",
 | 
					    "Specific Monitor Type": "Specific Monitor Type",
 | 
				
			||||||
 | 
					    dataRetentionTimeError: "Retention period must be 0 or greater",
 | 
				
			||||||
 | 
					    infiniteRetention: "Set to 0 for infinite retention.",
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -189,14 +189,36 @@ export default {
 | 
				
			||||||
         * @param {string} [currentPassword] Only need for disableAuth to true
 | 
					         * @param {string} [currentPassword] Only need for disableAuth to true
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        saveSettings(callback, currentPassword) {
 | 
					        saveSettings(callback, currentPassword) {
 | 
				
			||||||
            this.$root.getSocket().emit("setSettings", this.settings, currentPassword, (res) => {
 | 
					            let valid = this.validateSettings();
 | 
				
			||||||
                this.$root.toastRes(res);
 | 
					            if (valid.success) {
 | 
				
			||||||
                this.loadSettings();
 | 
					                this.$root.getSocket().emit("setSettings", this.settings, currentPassword, (res) => {
 | 
				
			||||||
 | 
					                    this.$root.toastRes(res);
 | 
				
			||||||
 | 
					                    this.loadSettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (callback) {
 | 
					                    if (callback) {
 | 
				
			||||||
                    callback();
 | 
					                        callback();
 | 
				
			||||||
                }
 | 
					                    }
 | 
				
			||||||
            });
 | 
					                });
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                this.$root.toastError(valid.msg);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * Ensure settings are valid
 | 
				
			||||||
 | 
					         * @returns {Object} Contains success state and error msg
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        validateSettings() {
 | 
				
			||||||
 | 
					            if (this.settings.keepDataPeriodDays < 0) {
 | 
				
			||||||
 | 
					                return {
 | 
				
			||||||
 | 
					                    success: false,
 | 
				
			||||||
 | 
					                    msg: this.$t("dataRetentionTimeError"),
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return {
 | 
				
			||||||
 | 
					                success: true,
 | 
				
			||||||
 | 
					                msg: "",
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue