Skip to content

Commit dd1fafa

Browse files
committed
Increased curl timeout to avoid server timeout for update check and themes/plugins marketplace listing and display error message instead of exception on connect error
1 parent 042692f commit dd1fafa

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

admin/component/news.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,31 @@
2222

2323
namespace Vvveb\Component;
2424

25+
use function Vvveb\getUrl;
2526
use Vvveb\System\Cache;
2627
use Vvveb\System\Component\ComponentBase;
2728
use Vvveb\System\Event;
2829
use Vvveb\System\Import\Rss;
29-
use function Vvveb\getUrl;
3030

3131
class News extends ComponentBase {
3232
protected $domain = 'https://blog.vvveb.com';
3333

3434
protected $url = '/feed/news';
3535

3636
public static $defaultOptions = [
37-
'start' => 0,
37+
'page' => 0,
3838
'limit' => 10,
3939
];
4040

4141
public $options = [];
4242

4343
function getNews() {
44-
45-
$feed = getUrl($this->domain . $this->url, true, 604800, 1, false);
44+
$feed = getUrl($this->domain . $this->url, true, 604800, 3, false);
4645

4746
if ($feed) {
4847
$rss = new Rss($feed);
4948

50-
$result = $rss->get(1, $this->options['limit']);
49+
$result = $rss->get($this->options['page'], $this->options['limit']);
5150

5251
return $result;
5352
}
@@ -68,7 +67,7 @@ function results() {
6867
'domain' => $this->domain,
6968
'url' => $this->url,
7069
'news' => $news,
71-
'count' => $this->options['limit'],
70+
'count' => count($news),
7271
];
7372

7473
list($results) = Event::trigger(__CLASS__, __FUNCTION__, $results);

admin/controller/content/edit.php

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ function index() {
226226
$template = isset($post['template']) && $post['template'] ? $post['template'] : $defaultTemplate;
227227
$themeFolder = $this->getThemeFolder();
228228

229+
$design_url = '';
230+
229231
if (isset($post['url'])) {
230232
$design_url = \Vvveb\url(['module' => 'editor/editor', 'url' => $post['url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
231233
$post['design_url'] = $design_url;

admin/controller/plugin/market.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ function index() {
107107
foreach ($plugins['plugins'] as &$plugin) {
108108
$plugin['installed'] = isset($installed[$plugin['slug']]);
109109
}
110-
} catch (\ErrorException $e) {
111-
$view->errors[] = $e->getMessage();
110+
} catch (\Exception $e) {
111+
$view->warning[] = __('Failed to connect to marketplace');
112+
113+
if (DEBUG) {
114+
$view->errors[] = $e->getMessage();
115+
}
112116
}
113117

114118
$admin_path = \Vvveb\adminPath();

admin/controller/theme/market.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ function index() {
100100
foreach ($themes['themes'] as &$theme) {
101101
$theme['installed'] = isset($installed[$theme['slug']]);
102102
}
103-
} catch (\ErrorException $e) {
104-
$view->errors[] = $e->getMessage();
103+
} catch (\Exception $e) {
104+
$view->warning[] = __('Failed to connect to marketplace');
105+
106+
if (DEBUG) {
107+
$view->errors[] = $e->getMessage();
108+
}
105109
}
106110

107111
$view->set($themes);

admin/controller/tools/update.php

+8-27
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,13 @@ function checkPermissions() {
164164
$this->view->info[] = __('Permissions ok!');
165165
} else {
166166
$this->view->errors[] = sprintf(__('%s not writable!'), $result);
167+
167168
return false;
168169
}
169170

170171
return $result;
171-
}
172-
172+
}
173+
173174
function backup() {
174175
$result = false;
175176

@@ -355,35 +356,15 @@ function update() {
355356
function index() {
356357
$updateInfo = $this->checkUpdates();
357358

359+
if (isset($updateInfo['error']) && $updateInfo['error']) {
360+
$this->view->errors[] = $updateInfo['error'];
361+
}
362+
358363
$info = [
359364
'core' => [
360365
'current' => V_VERSION,
361366
'latest' => $updateInfo['version'] ?? '',
362-
'hasUpdate' => $updateInfo['hasUpdate'],
363-
],
364-
'themes' => [
365-
[
366-
'mytheme' => [
367-
'current' => V_VERSION,
368-
'latest' => V_VERSION,
369-
],
370-
'mytheme2' => [
371-
'current' => V_VERSION,
372-
'latest' => V_VERSION,
373-
],
374-
],
375-
],
376-
'plugins' => [
377-
[
378-
'myplugin' => [
379-
'current' => V_VERSION,
380-
'latest' => V_VERSION,
381-
],
382-
'myplugin2' => [
383-
'current' => V_VERSION,
384-
'latest' => V_VERSION,
385-
],
386-
],
367+
'hasUpdate' => $updateInfo['hasUpdate'] ?? false,
387368
],
388369
];
389370

system/functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ function download($url) {
14961496
return $result;
14971497
}
14981498

1499-
function getUrl($url, $cache = true, $expire = 604800, $timeout = 1, $exception = true) {
1499+
function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception = true) {
15001500
$cacheDriver = System\Cache :: getInstance();
15011501
$cacheKey = md5($url);
15021502
$result = false;

system/update.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ function checkUpdates($type = 'core', $force = false) {
4545
$cacheDriver->delete('url', $cacheKey);
4646
}
4747

48+
$error = '';
49+
$result = false;
4850
//cache results for one week
4951
try {
50-
$result = getUrl($this->url, true, 604800, 1, false);
52+
$result = getUrl($this->url, true);
5153
} catch (\Exception $e) {
52-
$result = '{}';
54+
if (DEBUG) {
55+
$error = $e->getMessage();
56+
}
5357
}
5458

59+
$info = ['hasUpdate' => false];
60+
5561
if ($result) {
5662
$info = json_decode($result, true);
5763

@@ -62,7 +68,11 @@ function checkUpdates($type = 'core', $force = false) {
6268
return $info;
6369
}
6470

65-
return [];
71+
if ($error) {
72+
$info['error'] = $error;
73+
}
74+
75+
return $info;
6676
}
6777

6878
private function checkFolderPermissions($dir) {

0 commit comments

Comments
 (0)