Skip to content

Commit d6fed67

Browse files
author
Leonid Vakulenko
committed
Webasyst Framework v.3.8.4
* Added system setting for the Webasyst services geozone selection. * Fixed auto updating of personal information in the profiles of users authorized with Webasyst ID. * A few visual improvements in the Installer app.
1 parent a5964d0 commit d6fed67

File tree

16 files changed

+154
-27
lines changed

16 files changed

+154
-27
lines changed

wa-apps/installer/js/installer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ String.prototype.translate = function () {
651651
success_handler(data.data);
652652
}
653653
if (data.data.redirect) {
654+
if (data.data.nothing_to_update && data.data.error) {
655+
alert(data.data.error);
656+
}
654657
location.href = data.data.redirect;
655658
}
656659
break;

wa-apps/installer/lib/actions/update/installerUpdateExecute.controller.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,23 @@ public function execute()
179179
}
180180
}
181181
} else {
182-
$updater->flush();
183-
throw new waException(sprintf('Nothing to update at thread %s', $this->thread_id));
182+
try {
183+
$updater->flush();
184+
} catch (Exception $ex) {
185+
// ignore unlink errors during cleanup
186+
}
187+
$this->response = [
188+
'nothing_to_update' => true,
189+
'error' => _w('Не удалось получить информацию о ходе процесса. Перезапустите, пожалуйста, процесс установки.'),
190+
'redirect' => wa()->getUrl('installer').'updates/',
191+
];
184192
}
185193
} else {
186-
throw new waException('Empty thread id');
194+
$this->response = [
195+
'nothing_to_update' => true,
196+
'error' => _w('Ошибка обновления. Перезапустите, пожалуйста, процесс установки.'),
197+
'redirect' => wa()->getUrl('installer').'updates/',
198+
];
187199
}
188200

189201
} catch (Exception $ex) {

wa-apps/installer/lib/config/app.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
'description' => 'Install new apps from the Webasyst Store',
55
'icon' => 'img/installer.svg',
66
'mobile' => false,
7-
'version' => '3.8.3',
8-
'critical' => '3.8.3',
7+
'version' => '3.8.4',
8+
'critical' => '3.8.4',
99
'system' => true,
1010
'vendor' => 'webasyst',
1111
'csrf' => true,

wa-installer/lib/classes/wainstallerapps.class.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public function __construct($license = null, $locale = null, $ttl = 600, $force
300300
}
301301

302302
if (isset($this->sources['zones'])) {
303-
$installer_zone = null;
304-
if (class_exists('waAppSettingsModel')) {
303+
$installer_zone = self::getGenericConfig('zone_jail', 'auto');
304+
if ((empty($installer_zone) || $installer_zone === 'auto') && class_exists('waAppSettingsModel')) {
305305
try {
306306
$installer_zone = $this->getAppSettingsModel()->get('webasyst', self::ENDPOINTS_ZONE_KEY);
307307
} catch (Exception $e) {
@@ -2347,6 +2347,11 @@ public function syncSourcesEndpoints($force = false)
23472347
}
23482348
}
23492349
$this->sources_all_zones = $sources;
2350+
2351+
$zone_jail = self::getGenericConfig('zone_jail', null);
2352+
if (!empty($this->sources_all_zones['zone_jail']) && empty($zone_jail)) {
2353+
self::updateGenericConfig(['zone_jail' => $this->sources_all_zones['zone_jail']]);
2354+
}
23502355
}
23512356
}
23522357
$this->getAppSettingsModel()->set('webasyst', self::ENDPOINTS_SYNC_TIME_KEY, time());
@@ -2403,6 +2408,14 @@ public function detectBestZone()
24032408
return null;
24042409
}
24052410

2411+
$zone_jail = self::getGenericConfig('zone_jail', 'auto');
2412+
if (!empty($zone_jail) && $zone_jail !== 'auto') {
2413+
return [
2414+
'is_zone_changed' => false,
2415+
'zone' => $zone_jail,
2416+
];
2417+
}
2418+
24062419
$endpoints_zones = array_keys($this->sources_all_zones['zones']);
24072420
$endpoints_zones[] = 'default';
24082421
$zoned_urls = array_reduce($endpoints_zones, function ($result, $zone) {

wa-installer/lib/config/sources.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,17 @@
33
return array (
44
'apps' => 'https://updates.webasyst.com/download/apps/list/',
55
'system' => 'https://updates.webasyst.com/download/system/list/',
6+
'zones' =>
7+
array (
8+
'en' =>
9+
array (
10+
'apps' => 'https://www.webasyst.com/download/apps/list/',
11+
'system' => 'https://www.webasyst.com/download/system/list/',
12+
),
13+
'ru' =>
14+
array (
15+
'apps' => 'https://www.webasyst.ru/download/apps/list/',
16+
'system' => 'https://www.webasyst.ru/download/system/list/',
17+
),
18+
),
619
);

wa-system/api/waAPIController.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ protected function checkToken()
217217

218218
protected function hasAppLicense($app)
219219
{
220+
if (!wa()->appExists('installer')) {
221+
return true;
222+
}
220223
waSystem::getInstance('installer');
221224
$ann_list = (new installerAnnouncementList)->withFilteredByApp($app)->getTopHeaderList();
222225
$ann_list = array_filter($ann_list, function ($a) use ($app) {

wa-system/api/waAPIException.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function __construct($error, $error_description = null, $status_code = nu
1414
$error_description = null;
1515
}
1616
$this->message = $this->error = $error;
17+
$this->message .= ': '.$error_description;
1718
$this->code = $this->status_code = $status_code;
1819
$this->error_description = $error_description;
1920

wa-system/util/waCSV.class.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ public function getFields()
8787
public function upload($name)
8888
{
8989
if (!isset($_FILES[$name]) || $_FILES[$name]['error']) {
90-
throw new waException(_("Error uploading file"));
90+
throw new waException(_ws("Error uploading file"));
9191
}
9292

9393
$file_info = explode(".", $_FILES[$name]['name']);
9494
if (!in_array(strtolower(end($file_info)), $this->extensions)) {
95-
throw new waException(_("Unknown extension *.").end($file_info));
95+
throw new waException(_ws("Unknown extension *.").end($file_info));
9696
}
9797

9898
$file = uniqid("csv").".csv";
9999
if (move_uploaded_file($_FILES[$name]['tmp_name'], $this->getPath($file))) {
100100
$this->file = $this->getPath($file);
101101
} else {
102-
throw new waException(_('Error moving file'));
102+
throw new waException(_ws('Error moving file'));
103103
}
104104
return $file;
105105
}
@@ -116,7 +116,7 @@ public function saveContent($content)
116116
if (file_put_contents($this->getPath($file), $content)) {
117117
$this->file = $this->getPath($file);
118118
} else {
119-
throw new waException(_('Error moving file'));
119+
throw new waException(_ws('Error moving file'));
120120
}
121121
return $file;
122122
}
@@ -134,11 +134,11 @@ public function saveContent($content)
134134
public function getInfo()
135135
{
136136
if (!$this->file || !file_exists($this->file)) {
137-
throw new waException(_('File does not exist'));
137+
throw new waException(_ws('File does not exist'));
138138
}
139139
$h = fopen($this->file, "r");
140140
if (!$h) {
141-
throw new waException(_("Error open file"));
141+
throw new waException(_ws("Error open file"));
142142
}
143143
// Read the first string
144144
$string = fgets($h, $this->length);
@@ -248,7 +248,7 @@ public function import($limit = 50)
248248
if (!$this->handler) {
249249
$this->handler = fopen($this->file, "r");
250250
if (!$this->handler) {
251-
throw new waException(_("Error open file"));
251+
throw new waException(_ws("Error open file"));
252252
}
253253
if (!$this->first_line) {
254254
$fields = $this->encodeArray(fgetcsv($this->handler, $this->length, $this->delimiter));

wa-system/waid/waWebasystIDApi.class.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,29 @@ protected function tryGetProfileInfo(waContact $contact, $force_refresh = false)
131131
public function getProfileUpdated(waContact $contact, $code)
132132
{
133133
$token_params = $contact->getWebasystTokenParams();
134-
$ok = $this->refreshTokenWhenExpired($token_params, $contact->getId());
135-
if (!$ok) {
134+
if (empty($token_params)) {
135+
$this->logError([
136+
'method' => __METHOD__,
137+
'error' => sprintf("There is no WAID token for contact %s", $contact->getId())
138+
]);
139+
} elseif (!$this->refreshTokenWhenExpired($token_params, $contact->getId())) {
140+
$token_params = null;
141+
$this->logError([
142+
'method' => __METHOD__,
143+
'error' => sprintf("Can't refresh token for contact %s", $contact->getId())
144+
]);
145+
}
146+
147+
$access_token = empty($token_params) ? (new waWebasystIDClientManager)->getSystemAccessToken() : $token_params['access_token'];
148+
if (empty($access_token)) {
149+
$this->logError([
150+
'method' => __METHOD__,
151+
'error' => "Can't get system token",
152+
]);
136153
return null;
137154
}
138155

139-
$response = $this->requestApiMethod('profile-updated', $token_params['access_token'], ['code' => $code]);
156+
$response = $this->requestApiMethod('profile-updated', $access_token, ['code' => $code]);
140157
if ($response['status'] == 200) {
141158
return $response['response'];
142159
}
@@ -572,7 +589,7 @@ protected function requestApiUrl($url, $access_token, array $params = [], $http_
572589
$headers = [
573590
'Authorization' => "Bearer {$access_token}"
574591
];
575-
592+
576593
$net = new waNet($net_options, $headers);
577594

578595
$exception = null;

wa-system/waid/waWebasystIDConfig.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public function getEndpoints()
9494

9595
protected function getEndpointsZone()
9696
{
97+
$config_path = waSystem::getInstance()->getConfigPath().'/config.php';
98+
$config = file_exists($config_path) ? include($config_path) : [];
99+
if (!is_array($config)) {
100+
$config = [];
101+
}
102+
$zone_jail = isset($config['zone_jail']) ? $config['zone_jail'] : null;
103+
if (!empty($zone_jail) && $zone_jail !== 'auto') {
104+
return $zone_jail;
105+
}
106+
97107
if (!class_exists('waInstallerApps')) {
98108
$autoload = waAutoload::getInstance();
99109
$autoload->add('waInstallerApps', 'wa-installer/lib/classes/wainstallerapps.class.php');

0 commit comments

Comments
 (0)