@@ -22,6 +22,8 @@ class installerConfig extends waAppConfig
2222 const INIT_DATA_CACHE_TTL = 10800 ; // 3 hours
2323 const INIT_DATA_CACHE_TTL_DEBUG = 900 ; // 15 mins
2424
25+ private static $ model ;
26+
2527 protected $ application_config = array ();
2628
2729 public function init ()
@@ -44,7 +46,7 @@ public function onCount()
4446 $ args = func_get_args ();
4547 $ force = array_shift ($ args );
4648
47- $ model = new waAppSettingsModel ();
49+ $ model = self :: getAppSettingsModel ();
4850 $ app_id = $ this ->getApplication ();
4951 $ count = null ;
5052
@@ -76,7 +78,7 @@ public function onCount()
7678
7779 public function setCount ($ n = null )
7880 {
79- $ model = new waAppSettingsModel ();
81+ $ model = self :: getAppSettingsModel ();
8082 $ model ->ping ();
8183 $ app_id = $ this ->getApplication ();
8284 $ model ->set ($ app_id , 'update_counter ' , $ n );
@@ -171,23 +173,18 @@ public function explainLogs($logs)
171173 */
172174 public function loadInitData ($ locale )
173175 {
174- $ net_options = array (
175- 'timeout ' => 7 ,
176- 'format ' => waNet::FORMAT_JSON ,
177- );
178- $ net = new waNet ($ net_options );
176+ return installerHelper::getInstaller ()->zonedNetQuery ([$ this , 'getInitDataUrl ' ], 7 , $ locale );
177+ }
179178
179+ public function getInitDataUrl ($ locale )
180+ {
180181 $ wa_installer = installerHelper::getInstaller ();
181-
182- $ init_url_params = array (
182+ $ init_url_params = [
183183 'locale ' => $ locale ,
184184 'hash ' => $ wa_installer ->getHash (),
185185 'domain ' => $ this ->getDomainFromRouting (),
186- );
187-
188- $ init_url = $ wa_installer ->getInstallerInitUrl ();
189- $ init_url .= '? ' .http_build_query ($ init_url_params );
190- return $ net ->query ($ init_url );
186+ ];
187+ return $ wa_installer ->getInstallerInitUrl ().'? ' .http_build_query ($ init_url_params );
191188 }
192189
193190 /**
@@ -216,6 +213,11 @@ public function getInitData($locale = null)
216213 return $ function_cache ->call ($ locale );
217214 }
218215
216+ public function clearInitDataCache ()
217+ {
218+ waFunctionCache::clearNamespace ('installer/init_data ' );
219+ }
220+
219221 /**
220222 * Load token from remote Update server, required to initialize the Installer app.
221223 * Received data is recommended to be cached. For example using waFunctionCache (see method getToken).
@@ -225,37 +227,28 @@ public function getInitData($locale = null)
225227 */
226228 protected function loadTokenData ()
227229 {
228- $ net_options = array (
229- 'timeout ' => 7 ,
230- 'format ' => waNet::FORMAT_JSON ,
231- );
232- $ net = new waNet ($ net_options );
233-
234- $ wa_installer = installerHelper::getInstaller ();
235-
236- $ init_url_params = array (
237- 'hash ' => $ wa_installer ->getHash (),
238- 'domain ' => $ this ->getDomainFromRouting (),
239- );
240- if ($ previous_hash = $ wa_installer ->getGenericConfig ('previous_hash ' )) {
241- $ init_url_params ['previous_hash ' ] = $ previous_hash ;
242- }
243-
244- $ init_url = $ wa_installer ->getInstallerTokenUrl ();
245- $ init_url .= '? ' .http_build_query ($ init_url_params );
246- $ res = $ net ->query ($ init_url );
230+ $ res = installerHelper::getInstaller ()->zonedNetQuery ([$ this , 'getTokenDataUrl ' ], 7 );
247231
248232 if (!empty ($ res ['token ' ])) {
249233 // Save the last received token in the app settings
250234 $ token_data = array ('token ' => $ res ['token ' ]['key ' ], 'expire_datetime ' => $ res ['token ' ]['expire_datetime ' ]);
251- $ asm = new waAppSettingsModel ();
252235 $ app_id = $ this ->getApplication ();
253- $ asm ->set ($ app_id , 'token_data ' , json_encode ($ token_data ));
236+ self :: getAppSettingsModel () ->set ($ app_id , 'token_data ' , json_encode ($ token_data ));
254237 }
255238
256239 return $ res ;
257240 }
258241
242+ public function getTokenDataUrl ()
243+ {
244+ $ wa_installer = installerHelper::getInstaller ();
245+ $ init_url_params = [
246+ 'hash ' => $ wa_installer ->getHash (),
247+ 'domain ' => $ this ->getDomainFromRouting (),
248+ ];
249+ return $ wa_installer ->getInstallerTokenUrl ().'? ' .http_build_query ($ init_url_params );
250+ }
251+
259252 /**
260253 * The method of caching and receiving the installation token
261254 * for working with a remote Store.
@@ -296,37 +289,15 @@ protected function loadAnnouncements()
296289 return ;
297290 }
298291
299- $ net_options = array (
300- 'timeout ' => 7 ,
301- 'format ' => waNet::FORMAT_JSON ,
302- );
303- $ net = new waNet ($ net_options );
304-
305- $ wa_installer = installerHelper::getInstaller ();
306-
307- $ url_params = array (
308- 'hash ' => $ wa_installer ->getHash (),
309- 'domain ' => $ this ->getDomainFromRouting (),
310- 'locale ' => wa ()->getLocale (),
311- );
312- $ token_data = (new waAppSettingsModel ())->get ('installer ' , 'token_data ' , false );
313- if ($ token_data ) {
314- $ token_data = waUtils::jsonDecode ($ token_data , true );
315- $ url_params ['token ' ] = ifset ($ token_data , 'token ' , null );
316- }
317-
318- $ init_url = $ wa_installer ->getInstallerAnnounceUrl ();
319- $ init_url .= '? ' .http_build_query ($ url_params );
320-
321- $ res = $ net ->query ($ init_url );
292+ $ res = installerHelper::getInstaller ()->zonedNetQuery ([$ this , 'getAnnouncementsUrl ' ], 7 );
322293 if (!$ res || !array_key_exists ('data ' , $ res )) {
323294 return ;
324295 }
325296 $ cache ->get ();
326297
327298 $ cache ->set ($ res );
328299
329- $ wasm = new waAppSettingsModel ();
300+ $ wasm = self :: getAppSettingsModel ();
330301
331302 if (!$ res ['data ' ]) {
332303 $ this ->clearBanners ();
@@ -363,6 +334,22 @@ protected function loadAnnouncements()
363334 }
364335 }
365336
337+ public function getAnnouncementsUrl ()
338+ {
339+ $ wa_installer = installerHelper::getInstaller ();
340+ $ init_url_params = [
341+ 'hash ' => $ wa_installer ->getHash (),
342+ 'domain ' => $ this ->getDomainFromRouting (),
343+ 'locale ' => wa ()->getLocale (),
344+ ];
345+ $ token_data = self ::getAppSettingsModel ()->get ('installer ' , 'token_data ' , false );
346+ if ($ token_data ) {
347+ $ token_data = waUtils::jsonDecode ($ token_data , true );
348+ $ init_url_params ['token ' ] = ifset ($ token_data , 'token ' , null );
349+ }
350+ return $ wa_installer ->getInstallerAnnounceUrl ().'? ' .http_build_query ($ init_url_params );
351+ }
352+
366353 public function clearAnnouncementsCache ()
367354 {
368355 $ this ->clearBanners ();
@@ -386,44 +373,39 @@ public function loadLicenses()
386373 $ cache = new waVarExportCache ('licenses ' , self ::LICENSE_CACHE_TTL , $ this ->getApplication ());
387374 $ cache_data = $ cache ->get ();
388375 if (!$ cache ->isCached () || time () - ifempty ($ cache_data , 'timestamp ' , 0 ) >= self ::LICENSE_CACHE_TTL ) {
389- $ net_options = array (
390- 'timeout ' => 7 ,
391- 'format ' => waNet::FORMAT_JSON ,
392- );
393- $ net = new waNet ($ net_options );
394- $ wa_installer = installerHelper::getInstaller ();
395-
396- $ init_url_params = array (
397- 'hash ' => $ wa_installer ->getHash (),
398- 'domain ' => $ this ->getDomainFromRouting (),
399- );
400- if ($ previous_hash = $ wa_installer ->getGenericConfig ('previous_hash ' )) {
401- $ init_url_params ['previous_hash ' ] = $ previous_hash ;
402- }
403- $ app_settings_model = new waAppSettingsModel ();
404- $ token_data = $ app_settings_model ->get ('installer ' , 'token_data ' , false );
405- if ($ token_data ) {
406- $ token_data = waUtils::jsonDecode ($ token_data , true );
407- $ init_url_params ['token ' ] = ifset ($ token_data , 'token ' , null );
408- }
409-
410- $ init_url = $ wa_installer ->getInstallerLicenseUrl ();
411- $ init_url .= '? ' . http_build_query ($ init_url_params );
412- $ res = $ net ->query ($ init_url );
376+ $ res = installerHelper::getInstaller ()->zonedNetQuery ([$ this , 'getLicensesUrl ' ], 7 );
413377
414378 if (!empty ($ res ['data ' ])) {
415379 $ data = [
416380 'data ' => $ res ['data ' ],
417381 'timestamp ' => time ()
418382 ];
419383 $ cache ->set ($ data );
420- $ app_settings_model ->set ('installer ' , 'licenses_data ' , json_encode ($ data ));
384+ self :: getAppSettingsModel () ->set ('installer ' , 'licenses_data ' , json_encode ($ data ));
421385 }
422386
423387 return $ res ;
424388 }
425389 }
426390
391+ public function getLicensesUrl ()
392+ {
393+ $ wa_installer = installerHelper::getInstaller ();
394+ $ init_url_params = [
395+ 'hash ' => $ wa_installer ->getHash (),
396+ 'domain ' => $ this ->getDomainFromRouting (),
397+ ];
398+ if ($ previous_hash = $ wa_installer ->getGenericConfig ('previous_hash ' )) {
399+ $ init_url_params ['previous_hash ' ] = $ previous_hash ;
400+ }
401+ $ token_data = self ::getAppSettingsModel ()->get ('installer ' , 'token_data ' , false );
402+ if ($ token_data ) {
403+ $ token_data = waUtils::jsonDecode ($ token_data , true );
404+ $ init_url_params ['token ' ] = ifset ($ token_data , 'token ' , null );
405+ }
406+ return $ wa_installer ->getInstallerLicenseUrl ().'? ' .http_build_query ($ init_url_params );
407+ }
408+
427409 /** @since 2.9.0 */
428410 public function getDomainFromRouting ()
429411 {
@@ -445,8 +427,7 @@ public function getDomainFromRouting()
445427 }
446428
447429 protected function getLocale () {
448- $ app_settings_model = new waAppSettingsModel ();
449- $ locale = $ app_settings_model ->get ('webasyst ' , 'locale ' );
430+ $ locale = self ::getAppSettingsModel ()->get ('webasyst ' , 'locale ' );
450431 if (empty ($ locale )) {
451432 $ locale = wa ()->getLocale ();
452433 }
@@ -455,4 +436,12 @@ protected function getLocale() {
455436 }
456437 return $ locale ;
457438 }
439+
440+ protected static function getAppSettingsModel ()
441+ {
442+ if (!self ::$ model ) {
443+ self ::$ model = new waAppSettingsModel ();
444+ }
445+ return self ::$ model ;
446+ }
458447}
0 commit comments