process();
//dd($check);
if ($check == true) {
//$this->notificationBar();
$this->checkNewUpdate();
// if (Utility::getFileVersion() > Utility::getDatabaseVersion()) {
// return redirect('database-update');
// }
// if (Utility::getFileVersion() < Utility::getDatabaseVersion()) {
// return redirect('file-update');
// }
}
return $next($request);
}
public function notificationBar()
{
$notify = new BarNotification();
$path = base_path('UPDATES');
if (is_dir($path)) {
$notify->create(['key' => 'update-ready', 'value' => 'New version has downloaded, click here to update now']);
}
}
public function checkNewUpdate()
{
$notify = new BarNotification();
if (!\Schema::hasTable('bar_notifications')) {
$url = url('database-upgrade');
//$string = "Your Database is outdated please upgrade Now !";
echo view('themes.default1.update.database', compact('url'));
exit;
}
$not = $notify->get();
if ($not->count() > 0) {
$now = \Carbon\Carbon::now();
$yesterday = \Carbon\Carbon::yesterday();
$notifications = $notify->whereBetween('created_at', [$yesterday, $now])->lists('value', 'key');
$todelete = $notify->where('created_at', '<', $yesterday)->get();
if ($todelete->count() > 0) {
foreach ($todelete as $delete) {
$delete->delete();
}
}
if (count($notifications) > 0) {
if (!array_key_exists('new-version', $notifications)) {
$check_version = $this->checkNewVersion();
if ($check_version == true) {
$notify->create(['key' => 'new-version', 'value' => 'new version found please click here to download']);
}
} else {
$n = $notify->where('key', 'new-version')->first();
$last = $n->created_at;
$now = \Carbon\Carbon::now();
$difference = $now->diffInHours($last);
if ($difference >= 24) {
$n->delete();
$this->checkNewUpdate();
}
}
}
} else {
$check_version = $this->checkNewVersion();
if ($check_version == true) {
//dd('if');
$notify->create(['key' => 'new-version', 'value' => 'new version found please click here to download', 'created_at' => \Carbon\Carbon::now()]);
} else {
//dd('else');
$notify->create(['key' => 'new-version', 'value' => '', 'created_at' => \Carbon\Carbon::now()]);
}
}
}
public function checkNewVersion()
{
$controller = new UpgradeController();
$version_from_billing = $controller->getLatestVersion();
$app_version = Utility::getFileVersion();
if ($version_from_billing > $app_version) {
return true;
}
}
public function process()
{
$notify = new BarNotification();
$not = $notify->get();
if ($not->count() > 0) {
$n = $notify->where('key', 'new-version')->first();
if ($n) {
$now = \Carbon\Carbon::now();
$yesterday = \Carbon\Carbon::yesterday();
$notifications = $notify->where('key', 'new-version')->whereBetween('created_at', [$yesterday, $now])->lists('value', 'key');
if ($notifications->count() > 0) {
return false;
}
}
}
return true;
}
}