|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Middleware; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Update\UpgradeController; |
|
6
|
|
|
use App\Http\Controllers\Utility\LibraryController as Utility; |
|
7
|
|
|
use App\Model\Update\BarNotification; |
|
8
|
|
|
use Closure; |
|
9
|
|
|
|
|
10
|
|
|
class CheckUpdate |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Handle an incoming request. |
|
14
|
|
|
* |
|
15
|
|
|
* @param \Illuminate\Http\Request $request |
|
16
|
|
|
* @param \Closure $next |
|
17
|
|
|
* |
|
18
|
|
|
* @return mixed |
|
19
|
|
|
*/ |
|
20
|
|
|
public function handle($request, Closure $next) |
|
21
|
|
|
{ |
|
22
|
|
|
$check = $this->process(); |
|
23
|
|
|
//dd($check); |
|
24
|
|
|
if ($check == true) { |
|
|
|
|
|
|
25
|
|
|
//$this->notificationBar(); |
|
|
|
|
|
|
26
|
|
|
$this->checkNewUpdate(); |
|
27
|
|
|
// if (Utility::getFileVersion() > Utility::getDatabaseVersion()) { |
|
|
|
|
|
|
28
|
|
|
// return redirect('database-update'); |
|
29
|
|
|
// } |
|
30
|
|
|
// if (Utility::getFileVersion() < Utility::getDatabaseVersion()) { |
|
31
|
|
|
// return redirect('file-update'); |
|
32
|
|
|
// } |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $next($request); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function notificationBar() |
|
39
|
|
|
{ |
|
40
|
|
|
$notify = new BarNotification(); |
|
41
|
|
|
$path = base_path('UPDATES'); |
|
42
|
|
|
if (is_dir($path)) { |
|
43
|
|
|
$notify->create(['key' => 'update-ready', 'value' => 'New version has downloaded, click <a href='.url('file-update').'>here</a> to update now']); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function checkNewUpdate() |
|
48
|
|
|
{ |
|
49
|
|
|
$notify = new BarNotification(); |
|
50
|
|
|
if (!\Schema::hasTable('bar_notifications')) { |
|
51
|
|
|
$url = url('database-upgrade'); |
|
52
|
|
|
//$string = "Your Database is outdated please upgrade <a href=$url>Now !</a>"; |
|
|
|
|
|
|
53
|
|
|
echo view('themes.default1.update.database', compact('url')); |
|
54
|
|
|
exit; |
|
55
|
|
|
} |
|
56
|
|
|
$not = $notify->get(); |
|
|
|
|
|
|
57
|
|
|
if ($not->count() > 0) { |
|
58
|
|
|
$now = \Carbon\Carbon::now(); |
|
59
|
|
|
$yesterday = \Carbon\Carbon::yesterday(); |
|
60
|
|
|
$notifications = $notify->whereBetween('created_at', [$yesterday, $now])->lists('value', 'key'); |
|
|
|
|
|
|
61
|
|
|
$todelete = $notify->where('created_at', '<', $yesterday)->get(); |
|
|
|
|
|
|
62
|
|
|
if ($todelete->count() > 0) { |
|
63
|
|
|
foreach ($todelete as $delete) { |
|
64
|
|
|
$delete->delete(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
if (count($notifications) > 0) { |
|
68
|
|
|
if (!array_key_exists('new-version', $notifications)) { |
|
69
|
|
|
$check_version = $this->checkNewVersion(); |
|
70
|
|
|
if ($check_version == true) { |
|
71
|
|
|
$notify->create(['key' => 'new-version', 'value' => 'new version found please click <a href='.url('file-update').'><b>here to download</b></a>']); |
|
72
|
|
|
} |
|
73
|
|
|
} else { |
|
74
|
|
|
$n = $notify->where('key', 'new-version')->first(); |
|
|
|
|
|
|
75
|
|
|
$last = $n->created_at; |
|
76
|
|
|
$now = \Carbon\Carbon::now(); |
|
77
|
|
|
$difference = $now->diffInHours($last); |
|
78
|
|
|
if ($difference >= 24) { |
|
79
|
|
|
$n->delete(); |
|
80
|
|
|
$this->checkNewUpdate(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} else { |
|
85
|
|
|
$check_version = $this->checkNewVersion(); |
|
86
|
|
|
|
|
87
|
|
|
if ($check_version == true) { |
|
88
|
|
|
//dd('if'); |
|
89
|
|
|
$notify->create(['key' => 'new-version', 'value' => 'new version found please click <a href='.url('file-update').'><b>here to download</b></a>', 'created_at' => \Carbon\Carbon::now()]); |
|
90
|
|
|
} else { |
|
91
|
|
|
//dd('else'); |
|
92
|
|
|
$notify->create(['key' => 'new-version', 'value' => '', 'created_at' => \Carbon\Carbon::now()]); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function checkNewVersion() |
|
98
|
|
|
{ |
|
99
|
|
|
$controller = new UpgradeController(); |
|
100
|
|
|
$version_from_billing = $controller->getLatestVersion(); |
|
101
|
|
|
$app_version = Utility::getFileVersion(); |
|
102
|
|
|
if ($version_from_billing > $app_version) { |
|
103
|
|
|
return true; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function process() |
|
108
|
|
|
{ |
|
109
|
|
|
$notify = new BarNotification(); |
|
110
|
|
|
$not = $notify->get(); |
|
|
|
|
|
|
111
|
|
|
if ($not->count() > 0) { |
|
112
|
|
|
$n = $notify->where('key', 'new-version')->first(); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
if ($n) { |
|
115
|
|
|
$now = \Carbon\Carbon::now(); |
|
116
|
|
|
$yesterday = \Carbon\Carbon::yesterday(); |
|
117
|
|
|
$notifications = $notify->where('key', 'new-version')->whereBetween('created_at', [$yesterday, $now])->lists('value', 'key'); |
|
|
|
|
|
|
118
|
|
|
if ($notifications->count() > 0) { |
|
119
|
|
|
return false; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return true; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.