Skip to content

Commit 903a4de

Browse files
author
Leonid Vakulenko
committed
Webasyst Framework v.3.0.0
1 parent 832bfa9 commit 903a4de

File tree

41 files changed

+656
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+656
-213
lines changed

wa-apps/installer/api/v1/installer.product.install.method.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function prepareInstall($slug)
9292
'status' => false,
9393
'details' => [
9494
'error' => 'product_not_found',
95-
'error_description' => _w('Product not found'),
95+
'error_description' => _w('Product not found.'),
9696
]
9797
];
9898
}
@@ -105,7 +105,7 @@ protected function prepareInstall($slug)
105105
'status' => false,
106106
'details' => [
107107
'error' => 'cant_resolve_download_url',
108-
'error_description' => _w('Download url can not resolve download url')
108+
'error_description' => _w('Cannot resolve the download URL.')
109109
],
110110
];
111111
}
@@ -119,7 +119,7 @@ protected function prepareInstall($slug)
119119
if ($warnings && $warnings[$slug]) {
120120
$error_description = join("\n", $warnings[$slug]);
121121
} else {
122-
$error_description = _w('Requirements not satisfied');
122+
$error_description = _w('The requirements are not satisfied.');
123123
}
124124

125125
$updater->flush();
@@ -206,7 +206,7 @@ protected function install($slug)
206206
'status' => false,
207207
'details' => [
208208
'error' => 'product_not_found',
209-
'error_description' => _w('Product not found'),
209+
'error_description' => _w('Product not found.'),
210210
],
211211
];
212212
}

wa-apps/installer/js/store.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@ var InstallerStore = (function ($) {
403403
fields.push({name: 'app_id['+ slug +']', value: data.vendor});
404404
});
405405

406-
that.initForm(url, fields);
406+
if (!that.options.in_app) {
407+
that.initForm(url, fields);
408+
return;
409+
}
410+
411+
that.initInstallationDialog(fields);
407412
};
408413

409414
InstallerStore.prototype.productRemove = function (data) {
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
<?php
2+
/**
3+
* Usage:
4+
* php cli.php installer update check
5+
* php cli.php installer update <slug>
6+
* php cli.php installer update everything
7+
*/
8+
class installerUpdateCli extends waCliController
9+
{
10+
protected $stderr;
11+
12+
protected function preExecute()
13+
{
14+
$this->stderr = fopen('php://stderr', 'w');
15+
$this->setupInstallationDomain();
16+
}
17+
18+
protected function postExecute()
19+
{
20+
fclose($this->stderr);
21+
}
22+
23+
public function execute()
24+
{
25+
try {
26+
$this->unsafeExecute();
27+
} catch (Throwable $e) {
28+
fwrite($this->stderr, "ERROR\n".((string)$e));
29+
}
30+
}
31+
32+
public function unsafeExecute()
33+
{
34+
$update_check = $update_everything = false;
35+
$update_list = waRequest::param();
36+
switch (ifset($update_list, 0, '')) {
37+
case 'everything':
38+
$update_everything = true;
39+
$update_list = [];
40+
break;
41+
case 'list':
42+
array_shift($update_list);
43+
if (!$update_list) {
44+
return $this->usage();
45+
}
46+
break;
47+
case 'check':
48+
$update_check = true;
49+
$update_list = [];
50+
break;
51+
default:
52+
return $this->usage();
53+
}
54+
55+
$items = installerHelper::getUpdates();
56+
list($items, $inapplicable_count, $applicable_slugs) = $this->filterInapplicable($items);
57+
if ($update_check) {
58+
echo join(PHP_EOL, $applicable_slugs);
59+
return;
60+
}
61+
62+
$urls = $this->prepareInstallationUrls($items);
63+
64+
$this->executeUpdate($urls);
65+
66+
$items = installerHelper::getUpdates();
67+
echo "PENDING ".$inapplicable_count."\n";
68+
}
69+
70+
protected function usage()
71+
{
72+
73+
fwrite($this->stderr, "Usage:
74+
> php cli.php installer update check
75+
team
76+
shop
77+
shop/plugin/brands
78+
shop/theme/hypermarket
79+
80+
> php cli.php installer update shop shop/plugin/brands shop/theme/hypermarket
81+
UPDATED 3
82+
PENDING 1
83+
84+
> php cli.php installer update everything
85+
UPDATED 1
86+
PENDING 0
87+
");
88+
}
89+
90+
protected function setupInstallationDomain()
91+
{
92+
$domain = getenv('WA_INSTALLATION_DOMAIN');
93+
if (!$domain) {
94+
$sql = "
95+
SELECT cs.value
96+
FROM wa_contact_settings AS cs
97+
JOIN wa_contact AS c
98+
ON c.id=cs.contact_id
99+
WHERE c.is_user >= 1
100+
AND cs.app_id='webasyst'
101+
AND cs.name='backend_url'
102+
ORDER BY c.last_datetime DESC
103+
LIMIT 1
104+
";
105+
$backend_url = (new waModel())->query($sql)->fetchField();
106+
if ($backend_url) {
107+
$domain = parse_url($backend_url, PHP_URL_HOST);
108+
}
109+
}
110+
111+
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'] = $domain;
112+
}
113+
114+
protected function filterInapplicable($items)
115+
{
116+
$execute_actions = array(
117+
waInstallerApps::ACTION_INSTALL, // update may be ACTION_INSTALL if vendor changed or licence type changed (normal -> premium)
118+
waInstallerApps::ACTION_CRITICAL_UPDATE,
119+
waInstallerApps::ACTION_UPDATE,
120+
);
121+
122+
$applicable_slugs = [];
123+
$inapplicable_count = 0;
124+
$checkItem = function(&$info) use ($execute_actions, &$applicable_slugs, &$inapplicable_count) {
125+
if (!in_array($info['action'], $execute_actions)
126+
|| empty($info['applicable'])
127+
|| (!empty($info['commercial']) && empty($info['purchased']))
128+
) {
129+
$inapplicable_count++;
130+
return false;
131+
} else {
132+
$applicable_slugs[] = $info['slug'];
133+
return true;
134+
}
135+
};
136+
137+
foreach ($items as $app_id => &$info) {
138+
if (!empty($info['download_url'])) {
139+
if (!$checkItem($info)) {
140+
unset($info['download_url']);
141+
}
142+
}
143+
144+
foreach (array('themes', 'plugins', 'widgets') as $type) {
145+
if (empty($info[$type]) || !is_array($info[$type])) {
146+
unset($info[$type]);
147+
continue;
148+
}
149+
150+
foreach ($info[$type] as $extra_id => $extras_info) {
151+
if (empty($extras_info['download_url']) || !$checkItem($extras_info)) {
152+
unset($info[$type][$extra_id]);
153+
}
154+
}
155+
}
156+
}
157+
unset($info);
158+
159+
return [$items, $inapplicable_count, $applicable_slugs];
160+
}
161+
162+
protected function prepareInstallationUrls($items)
163+
{
164+
$urls = [];
165+
$add = function($target, $info, $item_id = null) use (&$urls) {
166+
$urls[$target] = array(
167+
'source' => $info['download_url'],
168+
'target' => $target,
169+
'slug' => $target,
170+
'real_slug' => $info['slug'],
171+
'md5' => !empty($info['md5']) ? $info['md5'] : null,
172+
);
173+
174+
if ($item_id) {
175+
$urls[$target] = array_merge($urls[$target], array(
176+
'slug' => $item_id,
177+
'real_slug' => $info['slug'],
178+
'pass' => false,
179+
'name' => $info['name'],
180+
'icon' => $info['icon'],
181+
'update' => !empty($info['installed']),
182+
'subject' => empty($info['subject']) ? 'system' : $info['subject'],
183+
'edition' => empty($info['edition']) ? true : $info['edition'],
184+
));
185+
}
186+
};
187+
188+
foreach ($items as $app_id => $info) {
189+
if (!empty($info['download_url'])) {
190+
$info['subject'] = 'app';
191+
if ($app_id == 'installer') {
192+
foreach ($info['download_url'] as $target => $url) {
193+
$_info = $info;
194+
$_info['download_url'] = $url;
195+
$_info['name'] = _w('Webasyst framework').' ('.$target.')';
196+
$add($target, $_info);
197+
unset($_info);
198+
}
199+
} else {
200+
$target = 'wa-apps/'.$app_id;
201+
$add($target, $info, $app_id);
202+
}
203+
}
204+
205+
foreach (array('themes', 'plugins', 'widgets') as $type) {
206+
foreach (ifset($info, $type, []) as $extra_id => $extras_info) {
207+
$extras_info['subject'] = 'app_'.$type;
208+
if ($type == 'themes' && is_array($extras_info['download_url'])) {
209+
foreach ($extras_info['download_url'] as $target => $url) {
210+
$__info = $extras_info;
211+
$__info['download_url'] = $url;
212+
$__info['slug'] = preg_replace('@^wa-apps/@', '', $target);
213+
$__info['app'] = preg_replace('@^wa-apps/([^/]+)/.+$@', '$1', $target);
214+
215+
if (!isset($urls[$target])) {
216+
if (($__info['app'] == $app_id) || empty($items[$__info['app']]['themes'][$extra_id])) {
217+
if (!empty($items[$__info['app']]['themes'][$extra_id]['name'])) {
218+
$__info['name'] .= " ({$info['name']})";
219+
} elseif ( ( $app_info = wa()->getAppInfo($__info['app']))) {
220+
$__info['name'] .= " ({$app_info['name']})";
221+
} else {
222+
$__info['name'] .= " ({$__info['app']})";
223+
}
224+
$add($target, $__info);
225+
}
226+
}
227+
}
228+
} else {
229+
if (!empty($info['name'])) {
230+
$extras_info['name'] .= " ({$info['name']})";
231+
}
232+
if (strpos($app_id, '/')) {
233+
//system plugins
234+
$target = $app_id.'/'.$extra_id;
235+
} elseif (($app_id == 'webasyst') && ($type == 'widgets')) {
236+
$target = 'wa-widgets/'.$extra_id;
237+
} elseif (($app_id == 'wa-widgets')) {
238+
$target = 'wa-widgets/'.$extra_id;
239+
} else {
240+
$target = 'wa-apps/'.$app_id.'/'.$type.'/'.$extra_id;
241+
}
242+
$add($target, $extras_info, $target);
243+
}
244+
}
245+
}
246+
unset($info);
247+
}
248+
249+
return $urls;
250+
}
251+
252+
protected function logError($message)
253+
{
254+
waLog::log($message, 'installer.cli.update.log');
255+
}
256+
257+
protected function executeUpdate($urls)
258+
{
259+
$updater = new waInstaller(waInstaller::LOG_WARNING);
260+
$app_settings_model = new waAppSettingsModel();
261+
$updater->init();
262+
$app_settings_model->ping();
263+
264+
$urls = $updater->update($urls);
265+
$app_settings_model->ping();
266+
267+
$updated_urls = [];
268+
$updated_slugs = [];
269+
foreach ($urls as $item) {
270+
if (empty($item['skipped'])) {
271+
$updated_urls[] = $item;
272+
if (!empty($item['real_slug'])) {
273+
$updated_slugs[] = $item['real_slug'];
274+
}
275+
}
276+
}
277+
echo "UPDATED ".count($updated_urls)."\n";
278+
if (empty($updated_urls)) {
279+
return;
280+
}
281+
if (!empty($updated_slugs)) {
282+
$sender = new installerUpdateFact(installerUpdateFact::ACTION_ADD, $updated_slugs);
283+
$sender->query();
284+
}
285+
286+
//update themes
287+
foreach ($updated_urls as $url) {
288+
if (preg_match('@(wa-apps/)?(.+)/themes/(.+)@', $url['slug'], $matches)) {
289+
try {
290+
$theme = new waTheme($matches[3], $matches[2]);
291+
$theme->update();
292+
} catch (Exception $ex) {
293+
$this->logError(sprintf('Error during theme %s@%s update: %s', $matches[3], $matches[2], $ex->getMessage())."\n".$e->getTraceAsString());
294+
}
295+
}
296+
}
297+
298+
$app_settings_model->ping();
299+
installerHelper::flushCache();
300+
$app_settings_model->ping();
301+
302+
wa('installer')->event('end_installation', $urls);
303+
}
304+
305+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'description' => 'Install new apps from the Webasyst Store',
55
'icon' => 'img/installer.svg',
66
'mobile' => false,
7-
'version' => '3.0.0', // developer preview
7+
'version' => '3.0.0',
88
'critical' => '3.0.0',
99
'system' => true,
1010
'vendor' => 'webasyst',

wa-apps/installer/lib/config/installerConfig.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ public function onCount()
7474

7575
public function setCount($n = null)
7676
{
77-
wa()->getStorage()->open();
7877
$model = new waAppSettingsModel();
7978
$model->ping();
8079
$app_id = $this->getApplication();
8180
$model->set($app_id, 'update_counter', $n);
8281
$model->set($app_id, 'update_counter_timestamp', ($n === false) ? 0 : time());
82+
83+
if (wa()->getEnv() !== 'backend') {
84+
return;
85+
}
86+
wa()->getStorage()->open();
8387
parent::setCount($n);
8488
}
8589

692 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)