89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Setting;
|
|
use App\Article;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use App\Mylog;
|
|
|
|
class ProductLogger
|
|
{
|
|
public $logs = [];
|
|
protected $settingOra;
|
|
|
|
protected $aggiornato = false;
|
|
|
|
public function __construct($settingOraValue)
|
|
{
|
|
$this->settingOra = $settingOraValue;
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
$oraUpdate = Carbon::now();
|
|
$this->logs['start'] = 'Inizio da ' . $this->settingOra . "\n";
|
|
$this->logs['end'] = 'Fino a ' . $oraUpdate->toDateTimeString() . "\n";
|
|
$this->logs['inserted'] = 'PRODOTTI INSERITI' . "\n";
|
|
$this->logs['not_inserted'] = 'EVENTUALI PRODOTTI NON INSERITI' . "\n";
|
|
$this->logs['updated'] = 'PRODOTTI AGGIORNATI' . "\n";
|
|
$this->logs['server_issues'] = 'PRODOTTI NON INSERITI PER PROBLEMI SERVER' . "\n";
|
|
$this->logs['pre_order'] = 'PRODOTTI IN PREVENDITA' . "\n";
|
|
$this->logs['custom'] = ""; // for custom log messages
|
|
}
|
|
|
|
public function updateSettingOra($newOra)
|
|
{
|
|
$this->settingOra = $newOra;
|
|
}
|
|
|
|
public function setLogandSendEmail() {
|
|
$ora_update = Carbon::now();
|
|
|
|
if ($this->settingOra) {
|
|
$this->settingOra->value = $ora_update;
|
|
$this->settingOra->save();
|
|
}
|
|
if ($this->aggiornato) {
|
|
Log::channel('updateproducts')->notice($this->concatenateLogs());
|
|
Mail::raw($this->concatenateLogs(), function ($message) {
|
|
$titolo = "Inserim. nuovi prodotti";
|
|
if (!$this->settingOra) {
|
|
$titolo = "Inserim. prodotto:";
|
|
}
|
|
$message->to(Mylog::getEmail());
|
|
$message->subject(Mylog::getSubjectEmail($titolo));
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
public function addLog($type, $message)
|
|
{
|
|
if (isset($this->logs[$type])) {
|
|
$this->logs[$type] .= $message . "\n";
|
|
}
|
|
}
|
|
|
|
public function getLogs()
|
|
{
|
|
return $this->logs;
|
|
}
|
|
|
|
public function concatenateLogs()
|
|
{
|
|
return implode("", $this->logs);
|
|
}
|
|
|
|
public function setAggiornato($aggiornato) {
|
|
$this->aggiornato = $aggiornato;
|
|
}
|
|
|
|
public function getAggiornato() {
|
|
return $this->aggiornato;
|
|
}
|
|
}
|
|
|