mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-19 16:01:34 +02:00
Sync Accounts between v4 and v5
This commit is contained in:
parent
c9acbc3688
commit
e56846131f
@ -101,6 +101,7 @@ class ExportMigrations extends Command
|
|||||||
'expenses' => $this->getExpenses(),
|
'expenses' => $this->getExpenses(),
|
||||||
'tasks' => $this->getTasks(),
|
'tasks' => $this->getTasks(),
|
||||||
'documents' => $this->getDocuments(),
|
'documents' => $this->getDocuments(),
|
||||||
|
'ninja_tokens' => $this->getNinjaToken(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$file = storage_path("migrations/{$fileName}.zip");
|
$file = storage_path("migrations/{$fileName}.zip");
|
||||||
|
82
app/Console/Commands/SyncAccounts.php
Normal file
82
app/Console/Commands/SyncAccounts.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Libraries\Utils;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class SyncAccounts extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'ninja:sync-v5';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Sync accounts to v5 - (Hosted function only)';
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!Utils::isNinjaProd())
|
||||||
|
return;
|
||||||
|
|
||||||
|
config(['database.default' => DB_NINJA_1]);
|
||||||
|
|
||||||
|
$this->updateAccounts();
|
||||||
|
|
||||||
|
config(['database.default' => DB_NINJA_2]);
|
||||||
|
|
||||||
|
$this->updateAccounts();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateAccounts()
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
$a = Company::whereIn('plan', ['pro', 'enterprise'])
|
||||||
|
->with('accounts')
|
||||||
|
->chunk(100)->each(function ($company) use ($data){
|
||||||
|
|
||||||
|
$accounts = $company->accounts->pluck('account_key');
|
||||||
|
|
||||||
|
$data[] = [
|
||||||
|
'plan' => $company->plan,
|
||||||
|
'plan_term' => $company->plan_term,
|
||||||
|
'plan_started' => $company->plan_started,
|
||||||
|
'plan_paid' => $company->plan_paid,
|
||||||
|
'plan_expires' => $company->plan_expires,
|
||||||
|
'num_users' => $company->num_users,
|
||||||
|
'accounts' => $accounts
|
||||||
|
];
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//post DATA
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
|
use App\Libraries\Utils;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
use Utils;
|
use Utils;
|
||||||
@ -32,6 +33,7 @@ class Kernel extends ConsoleKernel
|
|||||||
'App\Console\Commands\CalculatePayouts',
|
'App\Console\Commands\CalculatePayouts',
|
||||||
'App\Console\Commands\UpdateKey',
|
'App\Console\Commands\UpdateKey',
|
||||||
'App\Console\Commands\ExportMigrations',
|
'App\Console\Commands\ExportMigrations',
|
||||||
|
'App\Console\Commands\SyncAccounts',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,5 +57,15 @@ class Kernel extends ConsoleKernel
|
|||||||
->command('ninja:send-reminders --force')
|
->command('ninja:send-reminders --force')
|
||||||
->sendOutputTo($logFile)
|
->sendOutputTo($logFile)
|
||||||
->daily();
|
->daily();
|
||||||
|
|
||||||
|
if(Utils::isNinjaProd())
|
||||||
|
{
|
||||||
|
|
||||||
|
$schedule
|
||||||
|
->command('ninja:sync-v5')
|
||||||
|
->withoutOverlapping()
|
||||||
|
->daily();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,6 +631,8 @@ if (! defined('APP_NAME')) {
|
|||||||
define('INVOICE_FIELDS_PRODUCT', 'product_fields');
|
define('INVOICE_FIELDS_PRODUCT', 'product_fields');
|
||||||
define('INVOICE_FIELDS_TASK', 'task_fields');
|
define('INVOICE_FIELDS_TASK', 'task_fields');
|
||||||
|
|
||||||
|
define('NINJA_V5_TOKEN', env('NINJA_V5_TOKEN',false));
|
||||||
|
|
||||||
$creditCards = [
|
$creditCards = [
|
||||||
1 => ['card' => 'images/credit_cards/Test-Visa-Icon.png', 'text' => 'Visa'],
|
1 => ['card' => 'images/credit_cards/Test-Visa-Icon.png', 'text' => 'Visa'],
|
||||||
2 => ['card' => 'images/credit_cards/Test-MasterCard-Icon.png', 'text' => 'Master Card'],
|
2 => ['card' => 'images/credit_cards/Test-MasterCard-Icon.png', 'text' => 'Master Card'],
|
||||||
|
Loading…
Reference in New Issue
Block a user