@@ -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 = [];
0 commit comments