2
2
3
3
namespace Leantime \Domain \Notifications \Services {
4
4
5
+ use Illuminate \Support \Facades \Log ;
5
6
use Leantime \Core \Db \Db as DbCore ;
6
7
use Leantime \Core \Language as LanguageCore ;
7
8
use Leantime \Domain \Notifications \Repositories \Notifications as NotificationRepository ;
@@ -46,9 +47,16 @@ public function __construct(
46
47
public function getLatest (int $ userId ): false |\SimpleXMLElement
47
48
{
48
49
49
- $ rss = $ this ->getFeed ();
50
+ try {
51
+ $ rss = $ this ->getFeed ();
52
+ } catch (\Exception $ e ) {
53
+ Log::warning ('Could not connect to news server. ' );
54
+ Log::warning ($ e );
50
55
51
- $ latestGuid = strval ($ rss ?->channel?->item[0 ]?->guid);
56
+ return false ;
57
+ }
58
+
59
+ $ latestGuid = (string ) $ rss ?->channel?->item[0 ]?->guid;
52
60
$ this ->settingService ->saveSetting ('usersettings. ' .$ userId .'.lastNewsGuid ' , strval ($ latestGuid ));
53
61
54
62
// Todo: check last article the user read
@@ -60,13 +68,20 @@ public function getLatest(int $userId): false|\SimpleXMLElement
60
68
public function hasNews (int $ userId ): bool
61
69
{
62
70
63
- $ rss = $ this ->getFeed ();
71
+ try {
72
+ $ rss = $ this ->getFeed ();
73
+ } catch (\Exception $ e ) {
74
+ Log::warning ('Could not connect to news server. ' );
75
+ Log::warning ($ e );
76
+
77
+ return false ;
78
+ }
64
79
65
- $ latestGuid = strval ( $ rss ?->channel?->item[0 ]?->guid) ;
80
+ $ latestGuid = ( string ) $ rss ?->channel?->item[0 ]?->guid;
66
81
67
82
$ lastNewsGuid = $ this ->settingService ->getSetting ('usersettings. ' .$ userId .'.lastNewsGuid ' );
68
83
69
- if ($ lastNewsGuid == false ) {
84
+ if ($ lastNewsGuid === false ) {
70
85
return true ;
71
86
}
72
87
0 commit comments