Author:   Lars Michelsen <[email protected]>
Date:     Wed Jun 27 12:49:36 2012 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Wed Jun 27 12:49:36 2012 +0200

Bugfix: Fixed re-fetching of background image after changed geomap source file

---

 ChangeLog                            |    1 +
 share/server/core/sources/geomap.php |   31 ++++++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1359fd5..e12f411 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@ Core
   * Bugfix: Better catching of exceptions on nested maps
   * Bugfix: Map configs can be edited using the GUI even in case of source 
errors
   * Bugfix: Fixed re-rendering of geomaps after map source changes
+  * Bugfix: Fixed re-fetching of background image after changed geomap source 
file
 
 Frontend
   * Added new map config option (global section) event_on_load to raise 
frontend events
diff --git a/share/server/core/sources/geomap.php 
b/share/server/core/sources/geomap.php
index 2af1af2..bd921d5 100644
--- a/share/server/core/sources/geomap.php
+++ b/share/server/core/sources/geomap.php
@@ -2,9 +2,13 @@
 
 class GeomapError extends MapSourceError {}
 
+function geomap_source_file($p) {
+    return cfg('paths', 'geomap') . '/' . $p['source_file'] . '.csv';
+}
+
 function geomap_get_locations($p) {
     $locations = array();
-    $f = cfg('paths', 'geomap') . '/' . $p['source_file'] . '.csv';
+    $f = geomap_source_file($p);
 
     if($p['source_file'] == '')
         throw new GeomapError(l('No location source file given. Terminate 
rendering geomap.'));
@@ -196,14 +200,15 @@ function process_geomap($MAPCFG, $map_name, &$map_config) 
{
     //file_put_contents('/tmp/123', $url);
 
     // Fetch the background image when needed
-    if(!file_exists($image_path)) {
+    if(!file_exists($image_path) || filemtime(geomap_source_file($params)) > 
filemtime($image_path)) {
+        error_log('(re)loading map image');
         // Allow/enable proxy
         $contents = geomap_get_contents($url);
         file_put_contents($image_path, $contents);
     }
 
     // Fetch the map bounds when needed
-    if(!file_exists($data_path)) {
+    if(!file_exists($data_path) || filemtime(geomap_source_file($params)) > 
filemtime($data_path)) {
         // Get the lat/long of the image bounds. The api adds a border area to 
the
         // generated image. This is good since this makes the outer nodes not 
touch
         // the border of the image. But this makes calculation of the x/y 
coords
@@ -258,18 +263,30 @@ function process_geomap($MAPCFG, $map_name, &$map_config) 
{
 }
 
 /**
- * Report as changed when the source file is newer than the compare_time
- * or when either the image file or the data file do not exist
+ * Report as changed when
+ * a) either the image file or the data file do not exist
+ * b) or when the source file is newer than the compare_time
+ * c) or when the image/data files are older than the source file
  */
 function changed_geomap($MAPCFG, $compare_time) {
     $params = $MAPCFG->getSourceParams();
 
     list($image_name, $image_path, $data_path) = geomap_files($params);
+
+    // a)
     if(!file_exists($image_path) || !file_exists($data_path))
         return true;
 
-    $t = filemtime(cfg('paths', 'geomap') . '/' . $params['source_file'] . 
'.csv');
-    return $t > $compare_time;
+    // b)
+    $t = filemtime(geomap_source_file($params));
+    if($t > $compare_time)
+        return true;
+
+    // c)
+    if($t > filemtime($image_path) || $t > filemtime($data_path))
+        return true;
+
+    return false;
 }
 
 ?>


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to