mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Multi-db support
This commit is contained in:
parent
a52d6a537d
commit
9d560fc24d
@ -60,6 +60,10 @@ class ChargeRenewalInvoices extends Command
|
||||
{
|
||||
$this->info(date('Y-m-d').' ChargeRenewalInvoices...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
$ninjaAccount = $this->accountRepo->getNinjaAccount();
|
||||
$invoices = Invoice::whereAccountId($ninjaAccount->id)
|
||||
->whereDueDate(date('Y-m-d'))
|
||||
@ -120,6 +124,8 @@ class ChargeRenewalInvoices extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,10 @@ class CheckData extends Command
|
||||
{
|
||||
$this->logMessage(date('Y-m-d') . ' Running CheckData...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
if (! $this->option('client_id')) {
|
||||
$this->checkBlankInvoiceHistory();
|
||||
$this->checkPaidToDate();
|
||||
@ -544,6 +548,7 @@ class CheckData extends Command
|
||||
return [
|
||||
['fix', null, InputOption::VALUE_OPTIONAL, 'Fix data', null],
|
||||
['client_id', null, InputOption::VALUE_OPTIONAL, 'Client id', null],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,10 @@ class CreateTestData extends Command
|
||||
$this->info(date('Y-m-d').' Running CreateTestData...');
|
||||
$this->count = $this->argument('count');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
if (filter_var($this->argument('create_account'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
$this->info('Creating new account...');
|
||||
$account = $this->accountRepo->create(
|
||||
@ -218,6 +222,8 @@ class CreateTestData extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class GenerateResources.
|
||||
*/
|
||||
class GenerateResources extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'ninja:generate-resources';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate Resouces';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$texts = File::getRequire(base_path() . '/resources/lang/en/texts.php');
|
||||
|
||||
foreach ($texts as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
echo $key;
|
||||
} else {
|
||||
echo "$key => $value\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace InvoiceNinja\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
|
||||
/**
|
||||
* Class Inspire.
|
||||
*/
|
||||
class Inspire extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'inspire';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Display an inspiring quote';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ class PruneData extends Command
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'ninja:prune-data';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -24,6 +24,10 @@ class PruneData extends Command
|
||||
{
|
||||
$this->info(date('Y-m-d').' Running PruneData...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
// delete accounts who never registered, didn't create any invoices,
|
||||
// hansn't logged in within the past 6 months and isn't linked to another account
|
||||
$sql = 'select a.id
|
||||
@ -42,14 +46,14 @@ class PruneData extends Command
|
||||
having count(i.id) = 0';
|
||||
|
||||
$results = DB::select($sql);
|
||||
|
||||
|
||||
foreach ($results as $result) {
|
||||
$this->info("Deleting {$result->id}");
|
||||
DB::table('accounts')
|
||||
->where('id', '=', $result->id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
|
||||
$this->info('Done');
|
||||
}
|
||||
|
||||
@ -66,6 +70,8 @@ class PruneData extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,18 @@ class RemoveOrphanedDocuments extends Command
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Removes old documents not associated with an expense or invoice';
|
||||
|
||||
|
||||
public function fire()
|
||||
{
|
||||
$this->info(date('Y-m-d').' Running RemoveOrphanedDocuments...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
$documents = Document::whereRaw('invoice_id IS NULL AND expense_id IS NULL AND updated_at <= ?', [new DateTime('-1 hour')])
|
||||
->get();
|
||||
|
||||
|
||||
$this->info(count($documents).' orphaned document(s) found');
|
||||
|
||||
foreach ($documents as $document) {
|
||||
@ -49,6 +53,8 @@ class RemoveOrphanedDocuments extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class ResetData extends Command
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'ninja:reset-data';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -28,8 +28,24 @@ class ResetData extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
Artisan::call('migrate:reset');
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['fix', null, InputOption::VALUE_OPTIONAL, 'Fix data', null],
|
||||
['client_id', null, InputOption::VALUE_OPTIONAL, 'Client id', null],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Invoice;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ResetInvoiceSchemaCounter extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:reset-invoice-schema-counter
|
||||
{account? : The ID of the account}
|
||||
{--force : Force setting the counter back to "1", regardless if the year changed}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Reset the invoice schema counter at the turn of the year.';
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
protected $invoice;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$force = $this->option('force');
|
||||
$account = $this->argument('account');
|
||||
|
||||
$accounts = null;
|
||||
|
||||
if ($account) {
|
||||
$accounts = Account::find($account)->get();
|
||||
} else {
|
||||
$accounts = Account::all();
|
||||
}
|
||||
|
||||
$latestInvoice = $this->invoice->latest()->first();
|
||||
$invoiceYear = Carbon::parse($latestInvoice->created_at)->year;
|
||||
|
||||
if (Carbon::now()->year > $invoiceYear || $force) {
|
||||
$accounts->transform(function ($a) {
|
||||
/* @var Account $a */
|
||||
$a->invoice_number_counter = 1;
|
||||
$a->update();
|
||||
});
|
||||
|
||||
$this->info('The counter has been resetted successfully for '.$accounts->count().' account(s).');
|
||||
}
|
||||
}
|
||||
}
|
@ -61,6 +61,10 @@ class SendRecurringInvoices extends Command
|
||||
$this->info(date('Y-m-d H:i:s') . ' Running SendRecurringInvoices...');
|
||||
$today = new DateTime();
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
// check for counter resets
|
||||
$accounts = Account::where('reset_counter_frequency_id', '>', 0)
|
||||
->orderBy('id', 'asc')
|
||||
@ -130,6 +134,8 @@ class SendRecurringInvoices extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,10 @@ class SendReminders extends Command
|
||||
{
|
||||
$this->info(date('Y-m-d') . ' Running SendReminders...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
$accounts = $this->accountRepo->findWithReminders();
|
||||
$this->info(count($accounts) . ' accounts found');
|
||||
|
||||
@ -103,6 +107,8 @@ class SendReminders extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,10 @@ class SendRenewalInvoices extends Command
|
||||
{
|
||||
$this->info(date('Y-m-d').' Running SendRenewalInvoices...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
}
|
||||
|
||||
// get all accounts with plans expiring in 10 days
|
||||
$companies = Company::whereRaw("datediff(plan_expires, curdate()) = 10 and (plan = 'pro' or plan = 'enterprise')")
|
||||
->orderBy('id')
|
||||
@ -123,6 +127,8 @@ class SendRenewalInvoices extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class Kernel extends ConsoleKernel
|
||||
'App\Console\Commands\SendRenewalInvoices',
|
||||
'App\Console\Commands\ChargeRenewalInvoices',
|
||||
'App\Console\Commands\SendReminders',
|
||||
'App\Console\Commands\GenerateResources',
|
||||
'App\Console\Commands\TestOFX',
|
||||
'App\Console\Commands\MakeModule',
|
||||
'App\Console\Commands\MakeClass',
|
||||
|
@ -229,8 +229,7 @@ if (! defined('APP_NAME')) {
|
||||
define('SESSION_REFERRAL_CODE', 'referralCode');
|
||||
define('SESSION_LEFT_SIDEBAR', 'showLeftSidebar');
|
||||
define('SESSION_RIGHT_SIDEBAR', 'showRightSidebar');
|
||||
define('SESSION_USER_DB_SERVER', 'userDbServer');
|
||||
define('SESSION_CONTACT_DB_SERVER', 'contactDbServer');
|
||||
define('SESSION_DB_SERVER', 'dbServer');
|
||||
|
||||
define('SESSION_LAST_REQUEST_PAGE', 'SESSION_LAST_REQUEST_PAGE');
|
||||
define('SESSION_LAST_REQUEST_TIME', 'SESSION_LAST_REQUEST_TIME');
|
||||
@ -293,7 +292,8 @@ if (! defined('APP_NAME')) {
|
||||
|
||||
define('REQUESTED_PRO_PLAN', 'REQUESTED_PRO_PLAN');
|
||||
define('DEMO_ACCOUNT_ID', 'DEMO_ACCOUNT_ID');
|
||||
define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h');
|
||||
define('NINJA_ACCOUNT_KEY', env('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h'));
|
||||
define('NINJA_ACCOUNT_EMAIL', env('NINJA_ACCOUNT_EMAIL', 'contact@invoiceninja.com'));
|
||||
define('NINJA_LICENSE_ACCOUNT_KEY', 'AsFmBAeLXF0IKf7tmi0eiyZfmWW9hxMT');
|
||||
define('NINJA_GATEWAY_ID', GATEWAY_STRIPE);
|
||||
define('NINJA_GATEWAY_CONFIG', 'NINJA_GATEWAY_CONFIG');
|
||||
|
@ -18,7 +18,7 @@ class DatabaseLookup
|
||||
|
||||
if ($guard == 'user') {
|
||||
// user's value is set when logging in
|
||||
if (! session('SESSION_USER_DB_SERVER')) {
|
||||
if (! session(SESSION_DB_SERVER)) {
|
||||
return redirect('/logout');
|
||||
}
|
||||
} elseif ($guard == 'api') {
|
||||
@ -31,6 +31,8 @@ class DatabaseLookup
|
||||
} elseif (request()->contact_key) {
|
||||
LookupContact::setServerByField('contact_key', request()->contact_key);
|
||||
}
|
||||
} elseif ($guard == 'postmark') {
|
||||
LookupInvitation::setServerByField('message_id', request()->MessageID);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -76,10 +76,13 @@ Route::group(['middleware' => 'cors'], function () {
|
||||
Route::match(['GET', 'POST', 'OPTIONS'], '/buy_now/{gateway_type?}', 'OnlinePaymentController@handleBuyNow');
|
||||
});
|
||||
|
||||
Route::post('/hook/email_bounced', 'AppController@emailBounced');
|
||||
Route::post('/hook/email_opened', 'AppController@emailOpened');
|
||||
Route::post('/hook/bot/{platform?}', 'BotController@handleMessage');
|
||||
Route::group(['middleware' => 'lookup:postmark'], function () {
|
||||
Route::post('/hook/email_bounced', 'AppController@emailBounced');
|
||||
Route::post('/hook/email_opened', 'AppController@emailOpened');
|
||||
});
|
||||
|
||||
Route::post('/payment_hook/{accountKey}/{gatewayId}', 'OnlinePaymentController@handlePaymentWebhook');
|
||||
//Route::post('/hook/bot/{platform?}', 'BotController@handleMessage');
|
||||
|
||||
// Laravel auth routes
|
||||
Route::get('/signup', ['as' => 'signup', 'uses' => 'Auth\AuthController@getRegister']);
|
||||
|
@ -65,10 +65,11 @@ class LookupModel extends Eloquent
|
||||
$className = get_called_class();
|
||||
$className = str_replace('Lookup', '', $className);
|
||||
$key = sprintf('server:%s:%s:%s', $className, $field, $value);
|
||||
$isUser = $className == 'App\Models\User';
|
||||
|
||||
// check if we've cached this lookup
|
||||
if ($server = session($key)) {
|
||||
static::setDbServer($server);
|
||||
static::setDbServer($server, $isUser);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ class LookupModel extends Eloquent
|
||||
if ($value && $lookupUser = static::where($field, '=', $value)->first()) {
|
||||
$entity = new $className();
|
||||
$server = $lookupUser->getDbServer();
|
||||
static::setDbServer($server);
|
||||
static::setDbServer($server, $isUser);
|
||||
|
||||
// check entity is found on the server
|
||||
if (! $entity::where($field, '=', $value)->first()) {
|
||||
@ -91,10 +92,13 @@ class LookupModel extends Eloquent
|
||||
}
|
||||
}
|
||||
|
||||
public static function setDbServer($server)
|
||||
public static function setDbServer($server, $isUser = false)
|
||||
{
|
||||
session(['SESSION_USER_DB_SERVER' => $server]);
|
||||
config(['database.default' => $server]);
|
||||
|
||||
if ($isUser) {
|
||||
session([SESSION_DB_SERVER => $server]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDbServer()
|
||||
|
@ -359,13 +359,12 @@ class AccountRepository
|
||||
$emailSettings = new AccountEmailSettings();
|
||||
$account->account_email_settings()->save($emailSettings);
|
||||
|
||||
$random = strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
$user = new User();
|
||||
$user->registered = true;
|
||||
$user->confirmed = true;
|
||||
$user->email = 'contact@invoiceninja.com';
|
||||
$user->password = $random;
|
||||
$user->username = $random;
|
||||
$user->email = NINJA_ACCOUNT_EMAIL;
|
||||
$user->username = NINJA_ACCOUNT_EMAIL;
|
||||
$user->password = strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
$user->first_name = 'Invoice';
|
||||
$user->last_name = 'Ninja';
|
||||
$user->notify_sent = true;
|
||||
|
Loading…
Reference in New Issue
Block a user