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 BACKGROUND is in the line, it validates if it's in the new images/backgrounds folder and the path is referencing it there.
if the image is still in /images instead of /images/backgrounds, it moves it and updates the path.
if the image is already in the /images/backgrounds folder but the path is still pointing to the old images location, it only updates the path.
The altered BACKGROUND line is added to the $outcontents array. It then indicates it changed something by doing $changes++
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.
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 subfoldersimages/backgrounds/
andimages/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,
BACKGROUND
is in the line, it validates if it's in the newimages/backgrounds
folder and the path is referencing it there./images
instead of/images/backgrounds
, it moves it and updates the path./images/backgrounds
folder but the path is still pointing to the oldimages
location, it only updates the path.BACKGROUND
line is added to the$outcontents
array. It then indicates it changed something by doing$changes++
ICON
Finally,
if ($changes)
, it overwrites the config file with the contents of the$outcontents
array. However, because only lines containingBACKGROUND
andICON
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 containingBACKGROUND
andICON
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#L176Also, 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