aggiornamento log
This commit is contained in:
@@ -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);
|
||||
$productLogger = new ProductLogger($settingora, 'updateproducts');
|
||||
echo "SettingOra: " . $settingora;
|
||||
$fromtime = str_replace('-', '', $settingora->value);
|
||||
|
||||
@@ -90,7 +90,7 @@ class ProductUpdateGm extends Command
|
||||
setProductFromGM($article, true, $productLogger);
|
||||
}
|
||||
|
||||
$productLogger->setLogandSendEmail();
|
||||
$productLogger->setLogandSendEmail('Aggiornamento Prodotti');
|
||||
|
||||
echo "************** Finito **************";
|
||||
|
||||
@@ -99,7 +99,7 @@ class ProductUpdateGm extends Command
|
||||
|
||||
if ($productLogger) {
|
||||
$productLogger->addLog('Error', $e->getMessage());
|
||||
$productLogger->setLogandSendEmail();
|
||||
$productLogger->setLogandSendEmail('Aggiornamento Prodotti');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
use App\Setting;
|
||||
use App\Article;
|
||||
use App\Mylog;
|
||||
use App\Services\ProductLogger;
|
||||
use App\Stock;
|
||||
use Codexshaper\WooCommerce\Models\Product as ModelsProduct;
|
||||
use Codexshaper\WooCommerce\Facades\Variation;
|
||||
@@ -59,10 +60,11 @@ class TestPao extends Command
|
||||
$aggiornato = false;
|
||||
set_time_limit(0);
|
||||
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);
|
||||
|
||||
$log .= "Articoli: \n";
|
||||
$productLogger->addLog('info', "Articoli: \n");
|
||||
|
||||
echo "\nArticoli: \n";
|
||||
|
||||
@@ -94,7 +96,7 @@ class TestPao extends Command
|
||||
if ($articles) {
|
||||
// log the count of the articles
|
||||
echo "Num Articoli: " . $articles->count();
|
||||
$log .= "Quanti Articoli: " . $articles->count();
|
||||
$productLogger->addLog('info', "Quanti Articoli: " . $articles->count());
|
||||
|
||||
|
||||
$ind = 0;
|
||||
@@ -116,7 +118,7 @@ class TestPao extends Command
|
||||
$strarticolo = json_encode($article, JSON_PRETTY_PRINT);
|
||||
if ($strarticolo !== false) {
|
||||
echo $strarticolo;
|
||||
$log .= $strarticolo;
|
||||
$productLogger->addLog('info', $strarticolo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +222,7 @@ class TestPao extends Command
|
||||
} catch (\Exception $e) {
|
||||
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();
|
||||
|
||||
$log .= '\n';
|
||||
$productLogger->addLog('info', '\n');
|
||||
|
||||
foreach ($lastrecordStock as $stock) {
|
||||
$log .= "Codice: " . $stock->Codice;
|
||||
$log .= " QtaDisp: " . $stock->QtaDisponibile;
|
||||
$log .= " DataOra: " . $stock->DataOra;
|
||||
$productLogger->addLog('info', "Codice: " . $stock->Codice);
|
||||
$productLogger->addLog('info', " QtaDisp: " . $stock->QtaDisponibile);
|
||||
$productLogger->addLog('info', " DataOra: " . $stock->DataOra);
|
||||
|
||||
// Get the productsku record by $stock->Codice
|
||||
$productsku = Product::where('sku', $stock->Codice)->first();
|
||||
@@ -244,10 +246,10 @@ class TestPao extends Command
|
||||
// log the productsku record
|
||||
$productskustr = json_encode($productsku, JSON_PRETTY_PRINT);
|
||||
echo $productskustr;
|
||||
$log .= "\n" . $productskustr;
|
||||
$productLogger->addLog('info', "\n" . $productskustr);
|
||||
}
|
||||
|
||||
$log .= "\n";
|
||||
$productLogger->addLog('info', "\n");
|
||||
}
|
||||
|
||||
echo "************** FINE *********** ";
|
||||
@@ -255,11 +257,11 @@ class TestPao extends Command
|
||||
// Select all the fields of the Stock table
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$log .= $e->getMessage();
|
||||
$productLogger->addLog('info', $e->getMessage());
|
||||
echo "Error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
Log::channel('testpao')->notice($log);
|
||||
$productLogger->setLogandSendEmail('Test Paolo');
|
||||
|
||||
if (true) {
|
||||
// Send the email
|
||||
|
||||
@@ -512,7 +512,7 @@ function libriInPrevendita()
|
||||
function setProductFromGM($article, $initlog, ProductLogger &$passproductLogger)
|
||||
{
|
||||
if ($initlog) {
|
||||
$productLogger = new ProductLogger(null);
|
||||
$productLogger = new ProductLogger(null, '');
|
||||
} else {
|
||||
$productLogger = $passproductLogger;
|
||||
}
|
||||
@@ -1519,7 +1519,7 @@ function getArticoloById($idarticolo)
|
||||
|
||||
function updateArticoloFromGM($idarticolo)
|
||||
{
|
||||
$productLogger = new ProductLogger(null);
|
||||
$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) {
|
||||
|
||||
@@ -14,11 +14,14 @@ class ProductLogger
|
||||
public $logs = [];
|
||||
protected $settingOra = null;
|
||||
|
||||
protected $channel = "";
|
||||
|
||||
protected $aggiornato = false;
|
||||
|
||||
public function __construct($settingOra)
|
||||
public function __construct($settingOra, $channel)
|
||||
{
|
||||
$this->settingOra = $settingOra;
|
||||
$this->channel = $channel;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
@@ -44,7 +47,7 @@ class ProductLogger
|
||||
$this->settingOra = $newOra;
|
||||
}
|
||||
|
||||
public function setLogandSendEmail()
|
||||
public function setLogandSendEmail($descr)
|
||||
{
|
||||
if (is_object($this->settingOra) && method_exists($this->settingOra, 'save')) {
|
||||
$ora_update = Carbon::now();
|
||||
@@ -56,17 +59,11 @@ class ProductLogger
|
||||
}
|
||||
|
||||
if ($this->aggiornato) {
|
||||
Log::channel('updateproducts')->notice($this->concatenateLogs());
|
||||
Log::channel($this->channel)->notice($this->concatenateLogs());
|
||||
|
||||
Mail::raw($this->concatenateLogs(), function ($message) {
|
||||
|
||||
if (!$this->settingOra) {
|
||||
$titolo = "Inserim. prodotto:";
|
||||
} else {
|
||||
$titolo = "Inserim. nuovi prodotti";
|
||||
}
|
||||
Mail::raw($this->concatenateLogs(), function ($message) use ($descr) {
|
||||
$message->to(Mylog::getEmail());
|
||||
$message->subject(Mylog::getSubjectEmail($titolo));
|
||||
$message->subject(Mylog::getSubjectEmail($descr));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user