aggiornamento log

This commit is contained in:
paoloar77
2024-06-19 18:40:07 +02:00
parent 80c6c7518a
commit d570b477a7
4 changed files with 28 additions and 29 deletions

View File

@@ -51,7 +51,7 @@ class ProductUpdateGm extends Command
set_time_limit(0); set_time_limit(0);
ini_set("memory_limit", "512M"); ini_set("memory_limit", "512M");
$settingora = Setting::where('key', 'update_products')->first(); $settingora = Setting::where('key', 'update_products')->first();
$productLogger = new ProductLogger($settingora); $productLogger = new ProductLogger($settingora, 'updateproducts');
echo "SettingOra: " . $settingora; echo "SettingOra: " . $settingora;
$fromtime = str_replace('-', '', $settingora->value); $fromtime = str_replace('-', '', $settingora->value);
@@ -90,7 +90,7 @@ class ProductUpdateGm extends Command
setProductFromGM($article, true, $productLogger); setProductFromGM($article, true, $productLogger);
} }
$productLogger->setLogandSendEmail(); $productLogger->setLogandSendEmail('Aggiornamento Prodotti');
echo "************** Finito **************"; echo "************** Finito **************";
@@ -99,7 +99,7 @@ class ProductUpdateGm extends Command
if ($productLogger) { if ($productLogger) {
$productLogger->addLog('Error', $e->getMessage()); $productLogger->addLog('Error', $e->getMessage());
$productLogger->setLogandSendEmail(); $productLogger->setLogandSendEmail('Aggiornamento Prodotti');
} }
} }

View File

@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
use App\Setting; use App\Setting;
use App\Article; use App\Article;
use App\Mylog; use App\Mylog;
use App\Services\ProductLogger;
use App\Stock; use App\Stock;
use Codexshaper\WooCommerce\Models\Product as ModelsProduct; use Codexshaper\WooCommerce\Models\Product as ModelsProduct;
use Codexshaper\WooCommerce\Facades\Variation; use Codexshaper\WooCommerce\Facades\Variation;
@@ -59,10 +60,11 @@ class TestPao extends Command
$aggiornato = false; $aggiornato = false;
set_time_limit(0); set_time_limit(0);
ini_set("memory_limit", "512M"); ini_set("memory_limit", "512M");
$settingora = Setting::where('key', 'update_products_qta')->first(); $settingora = Setting::where('key', 'testpao')->first();
$productLogger = new ProductLogger($settingora, 'testpao');
$fromtime = str_replace('-', '', $settingora->value); $fromtime = str_replace('-', '', $settingora->value);
$log .= "Articoli: \n"; $productLogger->addLog('info', "Articoli: \n");
echo "\nArticoli: \n"; echo "\nArticoli: \n";
@@ -94,7 +96,7 @@ class TestPao extends Command
if ($articles) { if ($articles) {
// log the count of the articles // log the count of the articles
echo "Num Articoli: " . $articles->count(); echo "Num Articoli: " . $articles->count();
$log .= "Quanti Articoli: " . $articles->count(); $productLogger->addLog('info', "Quanti Articoli: " . $articles->count());
$ind = 0; $ind = 0;
@@ -116,7 +118,7 @@ class TestPao extends Command
$strarticolo = json_encode($article, JSON_PRETTY_PRINT); $strarticolo = json_encode($article, JSON_PRETTY_PRINT);
if ($strarticolo !== false) { if ($strarticolo !== false) {
echo $strarticolo; echo $strarticolo;
$log .= $strarticolo; $productLogger->addLog('info', $strarticolo);
} }
} }
@@ -220,7 +222,7 @@ class TestPao extends Command
} catch (\Exception $e) { } catch (\Exception $e) {
echo "Error: " . $e->getMessage(); echo "Error: " . $e->getMessage();
$log .= $e->getMessage(); $productLogger->addLog('info', $e->getMessage());
} }
} }
} }
@@ -230,12 +232,12 @@ class TestPao extends Command
$lastrecordStock = Stock::latest('DataOra')->take(1)->get(); $lastrecordStock = Stock::latest('DataOra')->take(1)->get();
$log .= '\n'; $productLogger->addLog('info', '\n');
foreach ($lastrecordStock as $stock) { foreach ($lastrecordStock as $stock) {
$log .= "Codice: " . $stock->Codice; $productLogger->addLog('info', "Codice: " . $stock->Codice);
$log .= " QtaDisp: " . $stock->QtaDisponibile; $productLogger->addLog('info', " QtaDisp: " . $stock->QtaDisponibile);
$log .= " DataOra: " . $stock->DataOra; $productLogger->addLog('info', " DataOra: " . $stock->DataOra);
// Get the productsku record by $stock->Codice // Get the productsku record by $stock->Codice
$productsku = Product::where('sku', $stock->Codice)->first(); $productsku = Product::where('sku', $stock->Codice)->first();
@@ -244,10 +246,10 @@ class TestPao extends Command
// log the productsku record // log the productsku record
$productskustr = json_encode($productsku, JSON_PRETTY_PRINT); $productskustr = json_encode($productsku, JSON_PRETTY_PRINT);
echo $productskustr; echo $productskustr;
$log .= "\n" . $productskustr; $productLogger->addLog('info', "\n" . $productskustr);
} }
$log .= "\n"; $productLogger->addLog('info', "\n");
} }
echo "************** FINE *********** "; echo "************** FINE *********** ";
@@ -255,11 +257,11 @@ class TestPao extends Command
// Select all the fields of the Stock table // Select all the fields of the Stock table
} catch (\Exception $e) { } catch (\Exception $e) {
$log .= $e->getMessage(); $productLogger->addLog('info', $e->getMessage());
echo "Error: " . $e->getMessage(); echo "Error: " . $e->getMessage();
} }
Log::channel('testpao')->notice($log); $productLogger->setLogandSendEmail('Test Paolo');
if (true) { if (true) {
// Send the email // Send the email

View File

@@ -512,7 +512,7 @@ function libriInPrevendita()
function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger) function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
{ {
if ($initlog) { if ($initlog) {
$productLogger = new ProductLogger(null); $productLogger = new ProductLogger(null, '');
} else { } else {
$productLogger = $passproductLogger; $productLogger = $passproductLogger;
} }
@@ -1519,7 +1519,7 @@ function getArticoloById($idarticolo)
function updateArticoloFromGM($idarticolo) function updateArticoloFromGM($idarticolo)
{ {
$productLogger = new ProductLogger(null); $productLogger = new ProductLogger(null, '');
try { try {
$articles = Article::join(DB::raw('(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b'), function ($join) { $articles = Article::join(DB::raw('(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b'), function ($join) {

View File

@@ -14,11 +14,14 @@ class ProductLogger
public $logs = []; public $logs = [];
protected $settingOra = null; protected $settingOra = null;
protected $channel = "";
protected $aggiornato = false; protected $aggiornato = false;
public function __construct($settingOra) public function __construct($settingOra, $channel)
{ {
$this->settingOra = $settingOra; $this->settingOra = $settingOra;
$this->channel = $channel;
$this->init(); $this->init();
} }
@@ -44,7 +47,7 @@ class ProductLogger
$this->settingOra = $newOra; $this->settingOra = $newOra;
} }
public function setLogandSendEmail() public function setLogandSendEmail($descr)
{ {
if (is_object($this->settingOra) && method_exists($this->settingOra, 'save')) { if (is_object($this->settingOra) && method_exists($this->settingOra, 'save')) {
$ora_update = Carbon::now(); $ora_update = Carbon::now();
@@ -56,17 +59,11 @@ class ProductLogger
} }
if ($this->aggiornato) { if ($this->aggiornato) {
Log::channel('updateproducts')->notice($this->concatenateLogs()); Log::channel($this->channel)->notice($this->concatenateLogs());
Mail::raw($this->concatenateLogs(), function ($message) { Mail::raw($this->concatenateLogs(), function ($message) use ($descr) {
if (!$this->settingOra) {
$titolo = "Inserim. prodotto:";
} else {
$titolo = "Inserim. nuovi prodotti";
}
$message->to(Mylog::getEmail()); $message->to(Mylog::getEmail());
$message->subject(Mylog::getSubjectEmail($titolo)); $message->subject(Mylog::getSubjectEmail($descr));
}); });
} }
} }