Skip to content

Commit 6a646aa

Browse files
author
James Wigger
authored
Merge pull request #22 from RootStudio/v1.1.2-batch-fix
V1.1.2 batch fix
2 parents e31711b + 4e533ae commit 6a646aa

File tree

8 files changed

+121
-19
lines changed

8 files changed

+121
-19
lines changed

perch/addons/apps/jw_locator/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
if ($CurrentUser->logged_in() && $CurrentUser->has_priv('jw_locator')) {
4-
$this->register_app('jw_locator', 'Locator', 1, 'Store / Location finder', '1.1.1');
4+
$this->register_app('jw_locator', 'Locator', 1, 'Store / Location finder', '1.1.2');
55
$this->require_version('jw_locator', 2.8);
66
$this->add_create_page('jw_locator', 'edit');
77

perch/addons/apps/jw_locator/classes/JwLocator_Location.class.php

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

perch/addons/apps/jw_locator/classes/JwLocator_Locations.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class JwLocator_Locations extends PerchAPI_Factory
6767
'markerID'
6868
);
6969

70+
/**
71+
* Maximum attempts to geocode before erroring
72+
*
73+
* @var int
74+
*/
75+
const MAX_ATTEMPTS = 3;
76+
7077
/**
7178
* Fetch locations in array of IDs
7279
*
@@ -194,6 +201,7 @@ public function get_queued($batch_limit = 25)
194201
{
195202
$sql = 'SELECT * FROM ' . $this->table;
196203
$sql .= ' WHERE `locationUpdatedAt` > `locationProcessedAt`';
204+
$sql .= ' AND `locationProcessingAttempts` < ' . $this->db->pdb(self::MAX_ATTEMPTS);
197205
$sql .= ' ORDER BY `locationUpdatedAt` ASC';
198206
$sql .= ' LIMIT ' . $batch_limit;
199207

perch/addons/apps/jw_locator/modes/errors.list.post.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<th class="score-title">
3535
<?php echo $Lang->get('Error'); ?>
3636
</th>
37+
<th class="score-title" style="text-align: center">
38+
<?php echo $Lang->get('Tries'); ?>
39+
</th>
3740
<th class="score-title">
3841
<?php echo $Lang->get('Date'); ?>
3942
</th>
@@ -52,6 +55,9 @@
5255
echo $HTML->encode($Error ? $Error->errorMessage() : null);
5356
?>
5457
</td>
58+
<td style="text-align: center">
59+
<?php echo $HTML->encode($Location->locationProcessingAttempts()); ?>
60+
</td>
5561
<td>
5662
<?php
5763
$Error = $Location->get_error();

perch/addons/apps/jw_locator/modes/locations.list.pre.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
22

3-
$HTML = $API->get('HTML');
43
$Settings = $API->get('Settings');
4+
5+
if ($Settings->get('jw_locator_update')->val() != '1.1.2') {
6+
PerchUtil::redirect($API->app_path() . '/update/');
7+
}
8+
9+
$HTML = $API->get('HTML');
510
$Paging = $API->get('Paging');
611
$Paging->set_per_page('20');
712

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="main">
2+
<div class="body">
3+
<div class="inner">
4+
<h1>Software Update</h1>
5+
<?php
6+
if (!$Paging->is_last_page()) {
7+
echo '<ul class="updates">';
8+
echo '<li class="icon success">Updating posts ' . $Paging->lower_bound() . ' to ' . $Paging->upper_bound() . ' of ' . $Paging->total() . '.</li>';
9+
echo '</ul>';
10+
} else {
11+
echo '<p class="info"><a href="' . $API->app_path() . '" class="button">Continue</a></p>';
12+
}
13+
?>
14+
</div>
15+
</div>
16+
<?php
17+
if (!$Paging->is_last_page()) {
18+
$paging = $Paging->to_array();
19+
echo "<script>
20+
window.setTimeout(function(){
21+
window.location='" . PerchUtil::html($paging['next_url'], true) . "';
22+
}, 0);
23+
</script>";
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$Settings = $API->get('Settings');
4+
$Paging = $API->get('Paging');
5+
$Paging->set_per_page(10);
6+
7+
if ($Paging->is_first_page()) {
8+
$db = $API->get('DB');
9+
10+
// v1.1.2
11+
$sql = 'ALTER TABLE `'. PERCH_DB_PREFIX .'jw_locator_locations` ADD `locationProcessingAttempts` INT(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `locationProcessingStatus`';
12+
$db->execute($sql);
13+
14+
$Settings->set('jw_locator_update', '1.1.2');
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php include('../../../../core/inc/api.php');
2+
3+
// Perch API
4+
$API = new PerchAPI(1.0, 'jw_locator');
5+
6+
// Language instance
7+
$Lang = $API->get('Lang');
8+
9+
// Page Meta
10+
$Perch->page_title = $Lang->get('Updating Locator');
11+
12+
// Page Initialising
13+
include('../modes/update.pre.php');
14+
15+
// Perch Frame
16+
include(PERCH_CORE . '/inc/top.php');
17+
18+
// Page
19+
include('../modes/update.post.php');
20+
21+
// Perch Frame
22+
include(PERCH_CORE . '/inc/btm.php');

0 commit comments

Comments
 (0)