mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Multi-db support
This commit is contained in:
parent
69b49c6ae7
commit
0a6db0d251
@ -5,6 +5,12 @@ namespace App\Console\Commands;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use DB;
|
use DB;
|
||||||
use App\Models\DbServer;
|
use App\Models\DbServer;
|
||||||
|
use App\Models\LookupCompany;
|
||||||
|
use App\Models\LookupAccount;
|
||||||
|
use App\Models\LookupUser;
|
||||||
|
use App\Models\LookupContact;
|
||||||
|
use App\Models\LookupToken;
|
||||||
|
use App\Models\LookupInvitation;
|
||||||
|
|
||||||
class InitLookup extends Command
|
class InitLookup extends Command
|
||||||
{
|
{
|
||||||
@ -41,11 +47,79 @@ class InitLookup extends Command
|
|||||||
{
|
{
|
||||||
$this->info(date('Y-m-d') . ' Running InitLookup...');
|
$this->info(date('Y-m-d') . ' Running InitLookup...');
|
||||||
|
|
||||||
DB::purge(DB::getDefaultConnection());
|
config(['database.default' => DB_NINJA_0]);
|
||||||
DB::Reconnect('db-ninja-0');
|
|
||||||
|
|
||||||
if (! DbServer::count()) {
|
if (DbServer::count()) {
|
||||||
DbServer::create(['name' => 'db-ninja-1']);
|
//exit('db_server record exists!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbServer = DbServer::create(['name' => DB_NINJA_1]);
|
||||||
|
$count = DB::table('companies')->count();
|
||||||
|
|
||||||
|
for ($i=0; $i<$count; $i += 100) {
|
||||||
|
$this->initCompanies($offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function initCompanies($offset = 0)
|
||||||
|
{
|
||||||
|
$this->info(date('Y-m-d') . ' initCompanies - offset: ' . $offset);
|
||||||
|
|
||||||
|
config(['database.default' => DB_NINJA_1]);
|
||||||
|
|
||||||
|
$companies = DB::table('companies')->orderBy('id')->get(['id']);
|
||||||
|
|
||||||
|
foreach ($companies as $company) {
|
||||||
|
$this->parseCompany($dbServer->id, $company->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseCompany($dbServerId, $companyId)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
config(['database.default' => DB_NINJA_1]);
|
||||||
|
|
||||||
|
$accounts = DB::table('accounts')->whereCompanyId($companyId)->orderBy('id')->get(['id']);
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$data[$account->id] = $this->parseAccount($account->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_r($data);exit;
|
||||||
|
config(['database.default' => DB_NINJA_0]);
|
||||||
|
///$lookupCompany = LookupCompany::create(['db_server_id' => $dbServerId]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseAccount($accountId)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'users' => [],
|
||||||
|
'contacts' => [],
|
||||||
|
'invitations' => [],
|
||||||
|
'tokens' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
$users = DB::table('users')->whereAccountId($accountId)->orderBy('id')->get(['email']);
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$data['users'][] = ['email' => $user->email];
|
||||||
|
}
|
||||||
|
|
||||||
|
$contacts = DB::table('contacts')->whereAccountId($accountId)->orderBy('id')->get(['contact_key']);
|
||||||
|
foreach ($contacts as $contact) {
|
||||||
|
$data['contacts'][] = ['contact_key' => $contact->contact_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
$invitations = DB::table('invitations')->whereAccountId($accountId)->orderBy('id')->get(['invitation_key', 'message_id']);
|
||||||
|
foreach ($invitations as $invitation) {
|
||||||
|
$data['invitations'][] = ['invitation_key' => $invitation->invitation_key, 'message_id' => $invitation->message_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tokens = DB::table('account_tokens')->whereAccountId($accountId)->orderBy('id')->get(['token']);
|
||||||
|
foreach ($tokens as $token) {
|
||||||
|
$data['tokens'][] = ['token' => $token->token];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,6 +335,10 @@ if (! defined('APP_NAME')) {
|
|||||||
|
|
||||||
define('BLANK_IMAGE', 'data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=');
|
define('BLANK_IMAGE', 'data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=');
|
||||||
|
|
||||||
|
define('DB_NINJA_0', 'db-ninja-0');
|
||||||
|
define('DB_NINJA_1', 'db-ninja-1');
|
||||||
|
define('DB_NINJA_2', 'db-ninja-2');
|
||||||
|
|
||||||
define('COUNT_FREE_DESIGNS', 4);
|
define('COUNT_FREE_DESIGNS', 4);
|
||||||
define('COUNT_FREE_DESIGNS_SELF_HOST', 5); // include the custom design
|
define('COUNT_FREE_DESIGNS_SELF_HOST', 5); // include the custom design
|
||||||
define('PRODUCT_ONE_CLICK_INSTALL', 1);
|
define('PRODUCT_ONE_CLICK_INSTALL', 1);
|
||||||
|
25
app/Models/LookupAccount.php
Normal file
25
app/Models/LookupAccount.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpenseCategory.
|
||||||
|
*/
|
||||||
|
class LookupAccount extends Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'lookup_company_id',
|
||||||
|
'account_key',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
24
app/Models/LookupCompany.php
Normal file
24
app/Models/LookupCompany.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpenseCategory.
|
||||||
|
*/
|
||||||
|
class LookupCompany extends Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'db_server_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
25
app/Models/LookupContact.php
Normal file
25
app/Models/LookupContact.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpenseCategory.
|
||||||
|
*/
|
||||||
|
class LookupContact extends Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'lookup_account_id',
|
||||||
|
'contact_key',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
26
app/Models/LookupInvitation.php
Normal file
26
app/Models/LookupInvitation.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpenseCategory.
|
||||||
|
*/
|
||||||
|
class LookupInvitation extends Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'lookup_account_id',
|
||||||
|
'invitation_key',
|
||||||
|
'message_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
25
app/Models/LookupToken.php
Normal file
25
app/Models/LookupToken.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpenseCategory.
|
||||||
|
*/
|
||||||
|
class LookupToken extends Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'lookup_account_id',
|
||||||
|
'token',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
25
app/Models/LookupUser.php
Normal file
25
app/Models/LookupUser.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpenseCategory.
|
||||||
|
*/
|
||||||
|
class LookupUser extends Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'lookup_account_id',
|
||||||
|
'email',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user