mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 20:04:29 -04:00
Reworked query caching for L5
This commit is contained in:
parent
bb27ca7178
commit
4750bacd71
@ -11,6 +11,7 @@ use Utils;
|
||||
use Validator;
|
||||
use View;
|
||||
use stdClass;
|
||||
use Cache;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Activity;
|
||||
@ -129,30 +130,16 @@ class AccountController extends BaseController
|
||||
public function showSection($section = ACCOUNT_DETAILS, $subSection = false)
|
||||
{
|
||||
if ($section == ACCOUNT_DETAILS) {
|
||||
/* Update Remember Function
|
||||
$data = [
|
||||
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'timezones' => Timezone::remember(DEFAULT_QUERY_CACHE)->orderBy('location')->get(),
|
||||
'dateFormats' => DateFormat::remember(DEFAULT_QUERY_CACHE)->get(),
|
||||
'datetimeFormats' => DatetimeFormat::remember(DEFAULT_QUERY_CACHE)->get(),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'languages' => Language::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id,
|
||||
];
|
||||
*/
|
||||
$data = [
|
||||
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
||||
'countries' => Country::orderBy('name')->get(),
|
||||
'sizes' => Size::orderBy('id')->get(),
|
||||
'industries' => Industry::orderBy('name')->get(),
|
||||
'timezones' => Timezone::orderBy('location')->get(),
|
||||
'dateFormats' => DateFormat::get(),
|
||||
'datetimeFormats' => DatetimeFormat::get(),
|
||||
'currencies' => Currency::orderBy('name')->get(),
|
||||
'languages' => Language::orderBy('name')->get(),
|
||||
'countries' => Cache::get('countries'),
|
||||
'sizes' => Cache::get('sizes'),
|
||||
'industries' => Cache::get('industries'),
|
||||
'timezones' => Cache::get('timezones'),
|
||||
'dateFormats' => Cache::get('dateFormats'),
|
||||
'datetimeFormats' => Cache::get('datetimeFormats'),
|
||||
'currencies' => Cache::get('currencies'),
|
||||
'languages' => Cache::get('languages'),
|
||||
'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id,
|
||||
];
|
||||
|
||||
@ -210,8 +197,6 @@ class AccountController extends BaseController
|
||||
$invoice->invoice_items = [$invoiceItem];
|
||||
|
||||
$data['invoice'] = $invoice;
|
||||
//$data['invoiceDesigns'] = InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId())
|
||||
// ->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get();
|
||||
$data['invoiceDesigns'] = InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get();
|
||||
} else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) {
|
||||
$data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE);
|
||||
@ -391,7 +376,7 @@ class AccountController extends BaseController
|
||||
$count = 0;
|
||||
$hasHeaders = Input::get('header_checkbox');
|
||||
|
||||
$countries = Country::remember(DEFAULT_QUERY_CACHE)->get();
|
||||
$countries = Cache::get('countries');
|
||||
$countryMap = [];
|
||||
|
||||
foreach ($countries as $country) {
|
||||
|
@ -9,6 +9,7 @@ use Validator;
|
||||
use Input;
|
||||
use Session;
|
||||
use Redirect;
|
||||
use Cache;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\Client;
|
||||
@ -178,23 +179,12 @@ class ClientController extends BaseController
|
||||
|
||||
private static function getViewModel()
|
||||
{
|
||||
/* Remember function no longer works
|
||||
return [
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'customLabel1' => Auth::user()->account->custom_client_label1,
|
||||
'customLabel2' => Auth::user()->account->custom_client_label2,
|
||||
];
|
||||
*/
|
||||
return [
|
||||
'sizes' => Size::orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']),
|
||||
'industries' => Industry::orderBy('name')->get(),
|
||||
'currencies' => Currency::orderBy('name')->get(),
|
||||
'countries' => Country::orderBy('name')->get(),
|
||||
'sizes' => Cache::get('sizes'),
|
||||
'paymentTerms' => Cache::get('paymentTerms'),
|
||||
'industries' => Cache::get('industries'),
|
||||
'currencies' => Cache::get('currencies'),
|
||||
'countries' => Cache::get('countries'),
|
||||
'customLabel1' => Auth::user()->account->custom_client_label1,
|
||||
'customLabel2' => Auth::user()->account->custom_client_label2,
|
||||
];
|
||||
|
@ -7,7 +7,7 @@ use Session;
|
||||
use Utils;
|
||||
use View;
|
||||
use Validator;
|
||||
|
||||
zz
|
||||
use App\Models\Client;
|
||||
|
||||
use App\Ninja\Repositories\CreditRepository;
|
||||
@ -84,7 +84,6 @@ class CreditController extends BaseController
|
||||
'method' => 'POST',
|
||||
'url' => 'credits',
|
||||
'title' => trans('texts.new_credit'),
|
||||
//'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
//'invoices' => Invoice::scope()->with('client', 'invoice_status')->orderBy('invoice_number')->get(),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
|
||||
|
||||
@ -102,7 +101,6 @@ class CreditController extends BaseController
|
||||
'method' => 'PUT',
|
||||
'url' => 'credits/'.$publicId,
|
||||
'title' => 'Edit Credit',
|
||||
//'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
|
||||
|
||||
return View::make('credit.edit', $data);
|
||||
|
@ -321,43 +321,17 @@ class InvoiceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
return [
|
||||
'account' => Auth::user()->account,
|
||||
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
||||
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId())
|
||||
->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
'frequencies' => array(
|
||||
1 => 'Weekly',
|
||||
2 => 'Two weeks',
|
||||
3 => 'Four weeks',
|
||||
4 => 'Monthly',
|
||||
5 => 'Three months',
|
||||
6 => 'Six months',
|
||||
7 => 'Annually',
|
||||
),
|
||||
'recurringHelp' => $recurringHelp
|
||||
];
|
||||
*/
|
||||
|
||||
return [
|
||||
'account' => Auth::user()->account,
|
||||
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
|
||||
'countries' => Country::orderBy('name')->get(),
|
||||
'countries' => Cache::get('countries'),
|
||||
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
||||
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
||||
'currencies' => Cache::get('currencies'),
|
||||
'sizes' => Size::orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']),
|
||||
'industries' => Industry::orderBy('name')->get(),
|
||||
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
'sizes' => Cache::get('sizes'),
|
||||
'paymentTerms' => Cache::get('paymentTerms'),
|
||||
'industries' => Cache::get('industries'),
|
||||
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
'frequencies' => array(
|
||||
1 => 'Weekly',
|
||||
2 => 'Two weeks',
|
||||
@ -593,7 +567,7 @@ class InvoiceController extends BaseController
|
||||
'invoice' => $invoice,
|
||||
'versionsJson' => json_encode($versionsJson),
|
||||
'versionsSelect' => $versionsSelect,
|
||||
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId())->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
];
|
||||
|
||||
return View::make('invoices.history', $data);
|
||||
|
@ -10,6 +10,7 @@ use Validator;
|
||||
use Omnipay;
|
||||
use CreditCard;
|
||||
use URL;
|
||||
use Cache;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Invitation;
|
||||
@ -151,8 +152,7 @@ class PaymentController extends BaseController
|
||||
'method' => 'POST',
|
||||
'url' => "payments",
|
||||
'title' => trans('texts.new_payment'),
|
||||
//'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTypes' => PaymentType::orderBy('id')->get(),
|
||||
'paymentTypes' => Cache::get('paymentTypes'),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
|
||||
|
||||
return View::make('payments.edit', $data);
|
||||
@ -172,8 +172,7 @@ class PaymentController extends BaseController
|
||||
'method' => 'PUT',
|
||||
'url' => 'payments/'.$publicId,
|
||||
'title' => trans('texts.edit_payment'),
|
||||
//'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTypes' => PaymentType::orderBy('id')->get(),
|
||||
'paymentTypes' => Cache::get('paymentTypes'),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
|
||||
|
||||
return View::make('payments.edit', $data);
|
||||
@ -368,8 +367,7 @@ class PaymentController extends BaseController
|
||||
'paymentLibrary' => $paymentLibrary,
|
||||
'gateway' => $gateway,
|
||||
'acceptedCreditCardTypes' => $acceptedCreditCardTypes,
|
||||
//'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'countries' => Country::orderBy('name')->get(),
|
||||
'countries' => Cache::get('countries'),
|
||||
'currencyId' => $client->currency_id,
|
||||
'account' => $client->account
|
||||
];
|
||||
@ -418,8 +416,7 @@ class PaymentController extends BaseController
|
||||
'paymentLibrary' => $paymentLibrary,
|
||||
'gateway' => $gateway,
|
||||
'acceptedCreditCardTypes' => $acceptedCreditCardTypes,
|
||||
//'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'countries' => Country::orderBy('name')->get(),
|
||||
'countries' => Cache::get('countries'),
|
||||
'currencyId' => 1,
|
||||
'paymentTitle' => $affiliate->payment_title,
|
||||
'paymentSubtitle' => $affiliate->payment_subtitle,
|
||||
|
@ -5,6 +5,7 @@ use Input;
|
||||
use Redirect;
|
||||
use Utils;
|
||||
use View;
|
||||
use Cache;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
@ -139,35 +140,17 @@ class QuoteController extends BaseController
|
||||
|
||||
private static function getViewModel()
|
||||
{
|
||||
/*
|
||||
return [
|
||||
'entityType' => ENTITY_QUOTE,
|
||||
'account' => Auth::user()->account,
|
||||
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
||||
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId())
|
||||
->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
'invoiceLabels' => Auth::user()->account->getInvoiceLabels()
|
||||
];
|
||||
*/
|
||||
// TODO: Add Remember Cache
|
||||
return [
|
||||
'entityType' => ENTITY_QUOTE,
|
||||
'account' => Auth::user()->account,
|
||||
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
|
||||
'countries' => Country::orderBy('name')->get(),
|
||||
'countries' => Cache::get('countries'),
|
||||
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
||||
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
||||
'currencies' => Currency::orderBy('name')->get(),
|
||||
'sizes' => Size::orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']),
|
||||
'industries' => Industry::orderBy('name')->get(),
|
||||
'currencies' => Cache::get('currencies'),
|
||||
'sizes' => Cache::get('sizes'),
|
||||
'paymentTerms' => Cache::get('paymentTerms'),
|
||||
'industries' => Cache::get('industries'),
|
||||
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
'invoiceLabels' => Auth::user()->account->getInvoiceLabels()
|
||||
];
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php namespace App\Http\Middleware;
|
||||
<?php namespace app\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Utils;
|
||||
@ -9,151 +9,149 @@ use Redirect;
|
||||
use Cache;
|
||||
use Session;
|
||||
use Event;
|
||||
|
||||
use App\Models\Currency;
|
||||
use App\Events\UserSettingsChanged;
|
||||
|
||||
class StartupCheck {
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Ensure all request are over HTTPS in production
|
||||
if (App::environment() == ENV_PRODUCTION)
|
||||
{
|
||||
if (!Request::secure())
|
||||
{
|
||||
return Redirect::secure(Request::getRequestUri());
|
||||
}
|
||||
}
|
||||
|
||||
// If the database doens't yet exist we'll skip the rest
|
||||
if (!Utils::isNinja() && !Utils::isDatabaseSetup())
|
||||
{
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Check currency data has been cached
|
||||
if (!Cache::has('currencies'))
|
||||
{
|
||||
Cache::forever('currencies', Currency::orderBy('name')->get());
|
||||
class StartupCheck
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Ensure all request are over HTTPS in production
|
||||
if (App::environment() == ENV_PRODUCTION) {
|
||||
if (!Request::secure()) {
|
||||
return Redirect::secure(Request::getRequestUri());
|
||||
}
|
||||
}
|
||||
|
||||
// If the database doens't yet exist we'll skip the rest
|
||||
if (!Utils::isNinja() && !Utils::isDatabaseSetup()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// check the application is up to date and for any news feed messages
|
||||
if (Auth::check())
|
||||
{
|
||||
$count = Session::get(SESSION_COUNTER, 0);
|
||||
Session::put(SESSION_COUNTER, ++$count);
|
||||
// Check data has been cached
|
||||
$cachedTables = [
|
||||
'currencies' => 'App\Models\Currency',
|
||||
'sizes' => 'App\Models\Size',
|
||||
'industries' => 'App\Models\Industry',
|
||||
'timezones' => 'App\Models\Timezone',
|
||||
'dateFormats' => 'App\Models\DateFormat',
|
||||
'datetimeFormats' => 'App\Models\DatetimeFormat',
|
||||
'languages' => 'App\Models\Language',
|
||||
'paymentTerms' => 'App\Models\PaymentTerm',
|
||||
'paymentTypes' => 'App\Models\PaymentType',
|
||||
];
|
||||
foreach ($cachedTables as $name => $class) {
|
||||
if (!Cache::has($name)) {
|
||||
$orderBy = 'id';
|
||||
|
||||
if (!Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && !Session::has('news_feed_id')) {
|
||||
$data = false;
|
||||
if (Utils::isNinja()) {
|
||||
$data = Utils::getNewsFeedResponse();
|
||||
} else {
|
||||
$file = @file_get_contents(NINJA_APP_URL . '/news_feed/' . Utils::getUserType() . '/' . NINJA_VERSION);
|
||||
$data = @json_decode($file);
|
||||
}
|
||||
if ($data) {
|
||||
if ($data->version != NINJA_VERSION) {
|
||||
$params = [
|
||||
'user_version' => NINJA_VERSION,
|
||||
'latest_version'=> $data->version,
|
||||
'releases_link' => link_to(RELEASES_URL, 'Invoice Ninja', ['target' => '_blank'])
|
||||
];
|
||||
Session::put('news_feed_id', NEW_VERSION_AVAILABLE);
|
||||
Session::put('news_feed_message', trans('texts.new_version_available', $params));
|
||||
} else {
|
||||
Session::put('news_feed_id', $data->id);
|
||||
if ($data->message && $data->id > Auth::user()->news_feed_id) {
|
||||
Session::put('news_feed_message', $data->message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Session::put('news_feed_id', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($name == 'paymentTerms') {
|
||||
$orderBy = 'num_days';
|
||||
} elseif (property_exists($class, 'name') && $name != 'paymentTypes') {
|
||||
$orderBy = 'name';
|
||||
}
|
||||
|
||||
Cache::forever($name, $class::orderBy($orderBy)->get());
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we're requesting to change the account's language
|
||||
if (Input::has('lang'))
|
||||
{
|
||||
$locale = Input::get('lang');
|
||||
App::setLocale($locale);
|
||||
Session::set(SESSION_LOCALE, $locale);
|
||||
// check the application is up to date and for any news feed messages
|
||||
if (Auth::check()) {
|
||||
$count = Session::get(SESSION_COUNTER, 0);
|
||||
Session::put(SESSION_COUNTER, ++$count);
|
||||
|
||||
if (Auth::check())
|
||||
{
|
||||
if ($language = Language::whereLocale($locale)->first())
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
$account->language_id = $language->id;
|
||||
$account->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Auth::check())
|
||||
{
|
||||
$locale = Session::get(SESSION_LOCALE, DEFAULT_LOCALE);
|
||||
App::setLocale($locale);
|
||||
}
|
||||
if (!Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && !Session::has('news_feed_id')) {
|
||||
$data = false;
|
||||
if (Utils::isNinja()) {
|
||||
$data = Utils::getNewsFeedResponse();
|
||||
} else {
|
||||
$file = @file_get_contents(NINJA_APP_URL.'/news_feed/'.Utils::getUserType().'/'.NINJA_VERSION);
|
||||
$data = @json_decode($file);
|
||||
}
|
||||
if ($data) {
|
||||
if ($data->version != NINJA_VERSION) {
|
||||
$params = [
|
||||
'user_version' => NINJA_VERSION,
|
||||
'latest_version' => $data->version,
|
||||
'releases_link' => link_to(RELEASES_URL, 'Invoice Ninja', ['target' => '_blank']),
|
||||
];
|
||||
Session::put('news_feed_id', NEW_VERSION_AVAILABLE);
|
||||
Session::put('news_feed_message', trans('texts.new_version_available', $params));
|
||||
} else {
|
||||
Session::put('news_feed_id', $data->id);
|
||||
if ($data->message && $data->id > Auth::user()->news_feed_id) {
|
||||
Session::put('news_feed_message', $data->message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Session::put('news_feed_id', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the account/user localization settings are in the session
|
||||
if (Auth::check() && !Session::has(SESSION_TIMEZONE))
|
||||
{
|
||||
// Check if we're requesting to change the account's language
|
||||
if (Input::has('lang')) {
|
||||
$locale = Input::get('lang');
|
||||
App::setLocale($locale);
|
||||
Session::set(SESSION_LOCALE, $locale);
|
||||
|
||||
if (Auth::check()) {
|
||||
if ($language = Language::whereLocale($locale)->first()) {
|
||||
$account = Auth::user()->account;
|
||||
$account->language_id = $language->id;
|
||||
$account->save();
|
||||
}
|
||||
}
|
||||
} elseif (Auth::check()) {
|
||||
$locale = Session::get(SESSION_LOCALE, DEFAULT_LOCALE);
|
||||
App::setLocale($locale);
|
||||
}
|
||||
|
||||
// Make sure the account/user localization settings are in the session
|
||||
if (Auth::check() && !Session::has(SESSION_TIMEZONE)) {
|
||||
Event::fire(new UserSettingsChanged());
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the user is claiming a license (ie, additional invoices, white label, etc.)
|
||||
$claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license');
|
||||
if (!$claimingLicense && Input::has('license_key') && Input::has('product_id'))
|
||||
{
|
||||
$licenseKey = Input::get('license_key');
|
||||
$productId = Input::get('product_id');
|
||||
// Check if the user is claiming a license (ie, additional invoices, white label, etc.)
|
||||
$claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license');
|
||||
if (!$claimingLicense && Input::has('license_key') && Input::has('product_id')) {
|
||||
$licenseKey = Input::get('license_key');
|
||||
$productId = Input::get('product_id');
|
||||
|
||||
$data = trim(file_get_contents((Utils::isNinjaDev() ? 'http://ninja.dev' : NINJA_APP_URL) . "/claim_license?license_key={$licenseKey}&product_id={$productId}"));
|
||||
$data = trim(file_get_contents((Utils::isNinjaDev() ? 'http://ninja.dev' : NINJA_APP_URL)."/claim_license?license_key={$licenseKey}&product_id={$productId}"));
|
||||
|
||||
if ($productId == PRODUCT_INVOICE_DESIGNS)
|
||||
{
|
||||
if ($data = json_decode($data))
|
||||
{
|
||||
foreach ($data as $item)
|
||||
{
|
||||
$design = new InvoiceDesign();
|
||||
$design->id = $item->id;
|
||||
$design->name = $item->name;
|
||||
$design->javascript = $item->javascript;
|
||||
$design->save();
|
||||
}
|
||||
if ($productId == PRODUCT_INVOICE_DESIGNS) {
|
||||
if ($data = json_decode($data)) {
|
||||
foreach ($data as $item) {
|
||||
$design = new InvoiceDesign();
|
||||
$design->id = $item->id;
|
||||
$design->name = $item->name;
|
||||
$design->javascript = $item->javascript;
|
||||
$design->save();
|
||||
}
|
||||
|
||||
if (!Utils::isNinjaProd()) {
|
||||
Cache::forget('invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId());
|
||||
}
|
||||
if (!Utils::isNinjaProd()) {
|
||||
Cache::forget('invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId());
|
||||
}
|
||||
|
||||
Session::flash('message', trans('texts.bought_designs'));
|
||||
}
|
||||
}
|
||||
else if ($productId == PRODUCT_WHITE_LABEL)
|
||||
{
|
||||
if ($data == 'valid')
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
$account->pro_plan_paid = NINJA_DATE;
|
||||
$account->save();
|
||||
Session::flash('message', trans('texts.bought_designs'));
|
||||
}
|
||||
} elseif ($productId == PRODUCT_WHITE_LABEL) {
|
||||
if ($data == 'valid') {
|
||||
$account = Auth::user()->account;
|
||||
$account->pro_plan_paid = NINJA_DATE;
|
||||
$account->save();
|
||||
|
||||
Session::flash('message', trans('texts.bought_white_label'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
Session::flash('message', trans('texts.bought_white_label'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ class Account extends Eloquent
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
$language = Language::remember(DEFAULT_QUERY_CACHE)->where('id', '=', $this->account->language_id)->first();
|
||||
$language = Language::where('id', '=', $this->account->language_id)->first();
|
||||
|
||||
return $language->locale;
|
||||
}
|
||||
|
@ -176,37 +176,6 @@
|
||||
@yield('content')
|
||||
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="footer" style="padding-top: 32px">
|
||||
@if (false)
|
||||
<div class="pull-right">
|
||||
{!! Former::open('user/setTheme')->addClass('themeForm') !!}
|
||||
<div style="display:none">
|
||||
{!! Former::text('theme_id') !!}
|
||||
{!! Former::text('path')->value(Request::url()) !!}
|
||||
</div>
|
||||
<div class="btn-group tr-action dropup">
|
||||
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
|
||||
Site Theme <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="#" onclick="setTheme(0)">Default</a></li>
|
||||
@foreach (Theme::remember(DEFAULT_QUERY_CACHE)->get() as $theme)
|
||||
<li><a href="#" onclick="setTheme({{ $theme->id }})">{{ ucwords($theme->name) }}</a></li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
{!! Former::close() !!}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!--
|
||||
Want something changed? We're {!! link_to('https://github.com/hillelcoren/invoice-ninja', 'open source', array('target'=>'_blank')) !!}, email us at {!! link_to('mailto:contact@invoiceninja.com', 'contact@invoiceninja.com') !!}.
|
||||
-->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if (!Auth::check() || !Auth::user()->registered)
|
||||
<div class="modal fade" id="signUpModal" tabindex="-1" role="dialog" aria-labelledby="signUpModalLabel" aria-hidden="true">
|
||||
|
Loading…
x
Reference in New Issue
Block a user