mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-01 03:49:24 +08:00 
			
		
		
		
	Merge pull request #3311 from tarun7singh/monitor-group-fix
Added fix to remove children when type changed
This commit is contained in:
		| @@ -1463,6 +1463,17 @@ class Monitor extends BeanModel { | |||||||
|         return childrenIDs; |         return childrenIDs; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Unlinks all children of the the group monitor | ||||||
|  |      * @param {number} groupID ID of group to remove children of | ||||||
|  |      * @returns {Promise<void>} | ||||||
|  |      */ | ||||||
|  |     static async unlinkAllChildren(groupID) { | ||||||
|  |         return await R.exec("UPDATE `monitor` SET parent = ? WHERE parent = ? ", [ | ||||||
|  |             null, groupID | ||||||
|  |         ]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| 	 * Checks recursive if parent (ancestors) are active | 	 * Checks recursive if parent (ancestors) are active | ||||||
| 	 * @param {number} monitorID ID of the monitor to get | 	 * @param {number} monitorID ID of the monitor to get | ||||||
|   | |||||||
| @@ -676,6 +676,7 @@ let needSetup = false; | |||||||
|         // Edit a monitor |         // Edit a monitor | ||||||
|         socket.on("editMonitor", async (monitor, callback) => { |         socket.on("editMonitor", async (monitor, callback) => { | ||||||
|             try { |             try { | ||||||
|  |                 let removeGroupChildren = false; | ||||||
|                 checkLogin(socket); |                 checkLogin(socket); | ||||||
|  |  | ||||||
|                 let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]); |                 let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]); | ||||||
| @@ -684,7 +685,7 @@ let needSetup = false; | |||||||
|                     throw new Error("Permission denied."); |                     throw new Error("Permission denied."); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 // Check if Parent is Decendant (would cause endless loop) |                 // Check if Parent is Descendant (would cause endless loop) | ||||||
|                 if (monitor.parent !== null) { |                 if (monitor.parent !== null) { | ||||||
|                     const childIDs = await Monitor.getAllChildrenIDs(monitor.id); |                     const childIDs = await Monitor.getAllChildrenIDs(monitor.id); | ||||||
|                     if (childIDs.includes(monitor.parent)) { |                     if (childIDs.includes(monitor.parent)) { | ||||||
| @@ -692,6 +693,11 @@ let needSetup = false; | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |                 // Remove children if monitor type has changed (from group to non-group) | ||||||
|  |                 if (bean.type === "group" && monitor.type !== bean.type) { | ||||||
|  |                     removeGroupChildren = true; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 bean.name = monitor.name; |                 bean.name = monitor.name; | ||||||
|                 bean.description = monitor.description; |                 bean.description = monitor.description; | ||||||
|                 bean.parent = monitor.parent; |                 bean.parent = monitor.parent; | ||||||
| @@ -752,6 +758,10 @@ let needSetup = false; | |||||||
|  |  | ||||||
|                 await R.store(bean); |                 await R.store(bean); | ||||||
|  |  | ||||||
|  |                 if (removeGroupChildren) { | ||||||
|  |                     await Monitor.unlinkAllChildren(monitor.id); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 await updateMonitorNotification(bean.id, monitor.notificationIDList); |                 await updateMonitorNotification(bean.id, monitor.notificationIDList); | ||||||
|  |  | ||||||
|                 if (bean.isActive()) { |                 if (bean.isActive()) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user