2020-03-16 11:12:10 +01:00
|
|
|
<?php
|
2020-09-07 12:18:56 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-07 12:18:56 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-07 12:18:56 +02:00
|
|
|
*/
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2021-02-10 03:26:05 +01:00
|
|
|
use App\Libraries\MultiDB;
|
2020-03-16 11:12:10 +01:00
|
|
|
use App\Models\Design;
|
|
|
|
use Illuminate\Console\Command;
|
2020-10-28 11:10:49 +01:00
|
|
|
use stdClass;
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
class DesignUpdate extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'ninja:design-update';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Update the system designs when changes are made.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
2021-02-10 03:26:05 +01:00
|
|
|
{
|
2021-02-10 04:42:02 +01:00
|
|
|
//always return state to first DB
|
2021-02-10 03:26:05 +01:00
|
|
|
|
2021-02-10 04:42:02 +01:00
|
|
|
$current_db = config('database.default');
|
2021-02-10 03:26:05 +01:00
|
|
|
|
|
|
|
if (! config('ninja.db.multi_db_enabled')) {
|
2021-02-10 04:18:23 +01:00
|
|
|
$this->handleOnDb();
|
2021-02-10 03:26:05 +01:00
|
|
|
} else {
|
2021-02-10 04:42:02 +01:00
|
|
|
|
2021-02-10 03:26:05 +01:00
|
|
|
//multiDB environment, need to
|
|
|
|
foreach (MultiDB::$dbs as $db) {
|
|
|
|
MultiDB::setDB($db);
|
|
|
|
|
2021-02-10 04:18:23 +01:00
|
|
|
$this->handleOnDb($db);
|
2021-02-10 03:26:05 +01:00
|
|
|
}
|
2021-02-10 04:42:02 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
MultiDB::setDB($current_db);
|
2021-02-10 03:26:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function handleOnDb()
|
2020-03-16 11:12:10 +01:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach (Design::whereIsCustom(false)->get() as $design) {
|
2021-01-15 13:08:09 +01:00
|
|
|
$invoice_design = new \App\Services\PdfMaker\Design(strtolower($design->name));
|
2020-08-11 18:36:56 +02:00
|
|
|
$invoice_design->document();
|
2020-03-16 11:12:10 +01:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
$design_object = new stdClass;
|
2020-10-07 18:42:41 +02:00
|
|
|
$design_object->includes = $invoice_design->getSectionHTML('style');
|
|
|
|
$design_object->header = $invoice_design->getSectionHTML('header');
|
|
|
|
$design_object->body = $invoice_design->getSectionHTML('body');
|
|
|
|
$design_object->product = '';
|
|
|
|
$design_object->task = '';
|
|
|
|
$design_object->footer = $invoice_design->getSectionHTML('footer');
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
$design->design = $design_object;
|
|
|
|
$design->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|