@@ -66,16 +66,15 @@ class JwLocator_Location extends PerchAPI_Base
6666 */
6767 public function update ($ data , $ force_geocoding = false , $ ignore_timestamp = false )
6868 {
69- if (! $ ignore_timestamp ) {
70- $ this ->set_status (1 );
71- $ data ['locationUpdatedAt ' ] = date ("Y-m-d H:i:s " );
69+ $ this -> reset_attempts ();
70+ $ this ->set_status (1 );
71+ $ data ['locationUpdatedAt ' ] = date ("Y-m-d H:i:s " );
7272
73- // Move here, as this is a 'normal' update
74- $ Error = $ this ->get_error ();
73+ // Move here, as this is a 'normal' update
74+ $ Error = $ this ->get_error ();
7575
76- if (is_object ($ Error )) {
77- $ Error ->delete ();
78- }
76+ if (is_object ($ Error )) {
77+ $ Error ->delete ();
7978 }
8079
8180 $ result = parent ::update ($ data );
@@ -280,11 +279,12 @@ public function geocode()
280279 $ Marker ->update ($ marker_data );
281280 }
282281
283- $ this ->update (array (
284- 'locationProcessedAt ' => date ("Y-m-d H:i:s " )
285- ), false , true );
282+ $ this ->db ->update ($ this ->table , array (
283+ 'locationProcessedAt ' => date ("Y-m-d H:i:s " ),
284+ 'locationProcessingStatus ' => self ::STATUS_SYNCED ,
285+ 'locationProcessingAttempts ' => 0
286+ ), $ this ->pk , $ this ->id ());
286287
287- $ this ->set_status (3 );
288288 } else {
289289 $ status = $ response ['status ' ];
290290
@@ -307,6 +307,7 @@ public function geocode()
307307 break ;
308308 }
309309
310+ $ this ->increment_attempts ();
310311 $ this ->set_status (4 );
311312 }
312313 }
@@ -340,16 +341,38 @@ public function map_preview()
340341 return '<img class="map-preview" src=" ' . $ base_url . http_build_query ($ parameters ) . '" /> ' ;
341342 }
342343
344+ /**
345+ * Reset attempts counter to zero
346+ */
347+ private function reset_attempts ()
348+ {
349+ $ this ->db ->update ($ this ->table , array (
350+ 'locationProcessingAttempts ' => 0
351+ ), $ this ->pk , $ this ->id ());
352+
353+ $ this ->details ['locationProcessingAttempts ' ] = 0 ;
354+ }
355+
356+ /**
357+ * Update the location processing attempts column
358+ */
359+ private function increment_attempts ()
360+ {
361+ $ this ->db ->update ($ this ->table , array (
362+ 'locationProcessingAttempts ' => ($ this ->locationProcessingAttempts () + 1 )
363+ ), $ this ->pk , $ this ->id ());
364+ }
365+
343366 /**
344367 * Set job status code
345368 *
346369 * @param int $status_code 1: queued, 2: processing, 3: synced, 4: Failed
347370 */
348371 private function set_status ($ status_code = 1 )
349372 {
350- $ this ->update (array (
373+ $ this ->db -> update ($ this -> table , array (
351374 'locationProcessingStatus ' => $ status_code
352- ), false , true );
375+ ), $ this -> pk , $ this -> id () );
353376 }
354377
355378 /**
@@ -362,9 +385,9 @@ private function set_marker($data)
362385 $ Markers = new JwLocator_Markers ($ this ->api );
363386 $ Marker = $ Markers ->create ($ data );
364387
365- $ this ->update (array (
388+ $ this ->db -> update ($ this -> table , array (
366389 'markerID ' => $ Marker ->id ()
367- ), false , true );
390+ ), $ this -> pk , $ this -> id () );
368391 }
369392
370393 /**
@@ -385,5 +408,4 @@ private function set_error($error_message)
385408
386409 return $ Error ;
387410 }
388-
389411}
0 commit comments