diff --git a/app/Console/Commands/ProductUpdateGm.php b/app/Console/Commands/ProductUpdateGm.php
index 0917fb5f..f321810d 100644
--- a/app/Console/Commands/ProductUpdateGm.php
+++ b/app/Console/Commands/ProductUpdateGm.php
@@ -51,7 +51,7 @@ class ProductUpdateGm extends Command
set_time_limit(0);
ini_set("memory_limit", "512M");
$settingora = Setting::where('key', 'update_products')->first();
- $productLogger = new ProductLogger($settingora->value);
+ $productLogger = new ProductLogger($settingora);
echo "SettingOra: " . $settingora;
$fromtime = str_replace('-', '', $settingora->value);
diff --git a/app/CustomFuncPao.php b/app/CustomFuncPao.php
index a0cf9326..8536849b 100644
--- a/app/CustomFuncPao.php
+++ b/app/CustomFuncPao.php
@@ -1515,7 +1515,7 @@ function getArticoloById($idarticolo) {
function updateArticoloFromGM($idarticolo)
{
- $productLogger = new ProductLogger("");
+ $productLogger = new ProductLogger(null);
try {
$articles = Article::join(DB::raw('(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b'), function ($join) {
diff --git a/app/Services/ProductLogger.php b/app/Services/ProductLogger.php
index 4cc60fa4..b5ee8f9f 100644
--- a/app/Services/ProductLogger.php
+++ b/app/Services/ProductLogger.php
@@ -12,13 +12,13 @@ use App\Mylog;
class ProductLogger
{
public $logs = [];
- protected $settingOra;
+ protected $settingOra = null;
protected $aggiornato = false;
- public function __construct($settingOraValue)
+ public function __construct($settingOra)
{
- $this->settingOra = $settingOraValue;
+ $this->settingOra = $settingOra;
$this->init();
}
@@ -26,7 +26,7 @@ class ProductLogger
{
$oraUpdate = Carbon::now();
if ($this->settingOra) {
- $this->logs['start'] = 'Inizio da ' . $this->settingOra . "\n
";
+ $this->logs['start'] = 'Inizio da ' . $this->settingOra->value . "\n
";
$this->logs['end'] = 'Fino a ' . $oraUpdate->toDateTimeString() . "\n
";
} else {
$this->logs['start'] = 'Iniziato: ' . $oraUpdate->toDateTimeString() . "\n
";
@@ -46,9 +46,15 @@ class ProductLogger
public function setLogandSendEmail()
{
- if ($this->settingOra) {
+ if (is_object($this->settingOra) && method_exists($this->settingOra, 'save')) {
+ $ora_update = Carbon::now();
+ $this->settingOra->value = $ora_update->toDateTimeString();
$this->settingOra->save();
+ } else {
+ // Gestisci il caso in cui $this->settingOra non è un oggetto o non ha il metodo save
+ Log::warning('Impossibile eseguire il metodo save() su $this->settingOra, non è un oggetto o il metodo non esiste.');
}
+
if ($this->aggiornato) {
Log::channel('updateproducts')->notice($this->concatenateLogs());