Skip to content

Commit 38389bd

Browse files
committed
!588 - Fixed adding of custom data.
1 parent e49ae67 commit 38389bd

File tree

4 files changed

+55
-43
lines changed

4 files changed

+55
-43
lines changed

system/Base/Installer/Packages/Setup/Register/Basepackages/Geo/Countries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function register($db, $ff, $localContent, $helper)
5151
if ($ff) {
5252
$countryStore = $ff->store('basepackages_geo_countries');
5353

54-
$countryStore->updateOrInsert($countryToInsert);
54+
$countryStore->updateOrInsert($countryToInsert, false);
5555
}
5656
}
5757

system/Base/Providers/BasepackagesServiceProvider/Packages/Geo/GeoCities.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class GeoCities extends BasePackage
1515

1616
public function addCity(array $data)
1717
{
18-
if ($this->add($data)) {
18+
$this->setFFAddUsingUpdateOrInsert(true);
1919

20+
if ($this->add($data)) {
2021
if (!isset($data['id'])) {
2122
if ($this->config->databasetype === 'db') {
2223
$this->updateSeq();

system/Base/Providers/BasepackagesServiceProvider/Packages/Geo/GeoCountries.php

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ public function addCountry(array $data)
6161
$data['installed'] = '1';
6262
}
6363

64-
if ($this->add($data)) {
64+
$data['id'] = $this->getNextIdFromDB();
6565

66-
if (!isset($data['id'])) {
67-
if ($this->config->databasetype === 'db') {
68-
$this->updateSeq();
69-
}
66+
if ($this->add($data)) {
67+
if ($this->config->databasetype !== 'db') {
68+
$this->ffStore->count(true);
7069
}
7170

7271
$this->addResponse('Added country ' . $data['name']);
@@ -75,21 +74,34 @@ public function addCountry(array $data)
7574
}
7675
}
7776

78-
protected function updateSeq()
77+
protected function getNextIdFromDB()
7978
{
80-
$lastCountryId = $this->modelToUse::maximum(['column' => 'id']);
79+
if ($this->config->databasetype === 'db') {
80+
$model = new $this->modelToUse;
81+
$table = $model->getSource();
82+
$sql = "SELECT id FROM {$table} ORDER BY id DESC LIMIT 1";
8183

82-
if ($lastCountryId && (int) $lastCountryId > 1000) {
83-
return;
84-
}
84+
$lastDBId = $this->executeSql($sql);
85+
$lastDBId->setFetchMode(\Phalcon\Db\Enum::FETCH_ASSOC);
8586

86-
$model = new $this->modelToUse;
87+
if ((int) $lastDBId->fetch()['id'] < 1000) {
88+
return 1001;
89+
} else {
90+
return (int) $lastDBId->fetch()['id'] + 1;
91+
}
92+
} else {
93+
$this->ffStore = $this->ff->store($this->ffStoreToUse);
8794

88-
$table = $model->getSource();
95+
$this->ffStore->count(true);
8996

90-
$sql = "UPDATE `{$table}` SET `id` = ? WHERE `{$table}`.`id` = ?";
97+
$this->setFFAddUsingUpdateOrInsert(true);
9198

92-
$this->db->execute($sql, [1001, $this->packagesData->last['id']]);
99+
if ((int) $this->ffStore->getLastInsertedId() < 1000) {
100+
return 1001;
101+
} else {
102+
return (int) $this->ffStore->getLastInsertedId() + 1;
103+
}
104+
}
93105
}
94106

95107
public function updateCountry(array $data)
@@ -140,7 +152,7 @@ protected function downloadCountryData($country)
140152
$this->remoteWebContent
141153
->request(
142154
'GET',
143-
'https://dev.bazaari.com.au/sp-public/geodata/raw/branch/master/' . $country . '.zip',
155+
'https://github.com/oyeaussie/sp-geodata/raw/main/' . $country . '.zip',
144156
['verify' => false]
145157
)->getBody()->getContents()
146158
);
@@ -160,7 +172,7 @@ protected function extractCountryData($country)
160172

161173
try {
162174
if ($zip->open(base_path($this->sourceDir . $country . '.zip'))) {
163-
if (!$zip->extractTo('/')) {
175+
if (!$zip->extractTo(base_path($this->sourceDir))) {
164176
$this->addResponse('Country zip file corrupt.', 1);
165177

166178
return false;
@@ -181,21 +193,6 @@ protected function extractCountryData($country)
181193
}
182194
}
183195

184-
// protected function registerTimezones($timezonesData, $country_id)
185-
// {
186-
// foreach ($timezonesData as $key => $timezone) {
187-
// $geoTimezone = [];
188-
// $geoTimezone['country_id'] = $country_id;
189-
// $geoTimezone['zone_name'] = $timezone['zoneName'];
190-
// $geoTimezone['gmt_offset'] = $timezone['gmtOffset'];
191-
// $geoTimezone['gmt_offset_name'] = $timezone['gmtOffsetName'];
192-
// $geoTimezone['abbreviation'] = $timezone['abbreviation'];
193-
// $geoTimezone['tz_name'] = $timezone['tzName'];
194-
195-
// $this->basepackages->geoTimezones->add($geoTimezone);
196-
// }
197-
// }
198-
199196
protected function registerStates($statesData, $country_id)
200197
{
201198
$searchByCities = [];

system/Base/Providers/BasepackagesServiceProvider/Packages/Geo/GeoStates.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class GeoStates extends BasePackage
1515

1616
public function addState(array $data)
1717
{
18-
if ($this->add($data)) {
18+
$data['id'] = $this->getNextIdFromDB();
1919

20+
if ($this->add($data)) {
2021
if (!isset($data['id'])) {
2122
if ($this->config->databasetype === 'db') {
2223
$this->updateSeq();
@@ -29,21 +30,34 @@ public function addState(array $data)
2930
}
3031
}
3132

32-
protected function updateSeq()
33+
protected function getNextIdFromDB()
3334
{
34-
$lastStateId = $this->modelToUse::maximum(['column' => 'id']);
35+
if ($this->config->databasetype === 'db') {
36+
$model = new $this->modelToUse;
37+
$table = $model->getSource();
38+
$sql = "SELECT id FROM {$table} ORDER BY id DESC LIMIT 1";
3539

36-
if ($lastStateId && (int) $lastStateId > 100000) {
37-
return;
38-
}
40+
$lastDBId = $this->executeSql($sql);
41+
$lastDBId->setFetchMode(\Phalcon\Db\Enum::FETCH_ASSOC);
3942

40-
$model = new $this->modelToUse;
43+
if ((int) $lastDBId->fetch()['id'] < 1000) {
44+
return 1001;
45+
} else {
46+
return (int) $lastDBId->fetch()['id'] + 1;
47+
}
48+
} else {
49+
$this->ffStore = $this->ff->store($this->ffStoreToUse);
4150

42-
$table = $model->getSource();
51+
$this->ffStore->count(true);
4352

44-
$sql = "UPDATE `{$table}` SET `id` = ? WHERE `{$table}`.`id` = ?";
53+
$this->setFFAddUsingUpdateOrInsert(true);
4554

46-
$this->db->execute($sql, [100001, $this->packagesData->last['id']]);
55+
if ((int) $this->ffStore->getLastInsertedId() < 10000) {
56+
return 10001;
57+
} else {
58+
return (int) $this->ffStore->getLastInsertedId() + 1;
59+
}
60+
}
4761
}
4862

4963
public function updateState(array $data)

0 commit comments

Comments
 (0)