`weathermap_repair_maps()` destroys maps instead of repairing them
https://github.com/Cacti/plugin_weathermap/blob/3c6e0e94a954e66a24ba0e81d17b419553575eaf/lib/poller-common.php#L100-L263
This function is being called whenever you open the weathermap map list (console > management > weathermaps). Back in the day, background and icon images were stored in the images subfolder of the plugin. At some point, it was decided to put them into the subfolders images/backgrounds/ and images/objects/.
The only purpose of this function is to migrate old configs by moving the images into their new subfolders and update the paths in the config. However, it destroys them in the process:
For each weathermap config file, it reads the config and loops over all lines.
For each line of the current config,
- if
BACKGROUNDis in the line, it validates if it's in the newimages/backgroundsfolder and the path is referencing it there.- if the image is still in
/imagesinstead of/images/backgrounds, it moves it and updates the path. - if the image is already in the
/images/backgroundsfolder but the path is still pointing to the oldimageslocation, it only updates the path. - The altered
BACKGROUNDline is added to the$outcontentsarray. It then indicates it changed something by doing$changes++
- if the image is still in
- The same treatment is applied to all lines containing
ICON
Finally, if ($changes), it overwrites the config file with the contents of the $outcontents array. However, because only lines containing BACKGROUND and ICON have been looked at, all other lines of the config haven't been added to the $outcontents array, so they get lost. The config is reduced to only containing BACKGROUND and ICON lines, effectively destroying that weathermap.
Additionally, there's a copy-paste error, $objfile should be $bgfile here:
https://github.com/Cacti/plugin_weathermap/blob/3c6e0e94a954e66a24ba0e81d17b419553575eaf/lib/poller-common.php#L176
Also, before renaming (moving) the background image, it tries to check if the new file name $new is writeable, but this cannot be true if the file does not exist.
https://github.com/Cacti/plugin_weathermap/blob/3c6e0e94a954e66a24ba0e81d17b419553575eaf/lib/poller-common.php#L162
How about a pull request on this please?
@Jay2k1 , Pull request?