Reworked query caching for L5

This commit is contained in:
Hillel Coren 2015-04-08 16:19:17 +03:00
parent bb27ca7178
commit 4750bacd71
9 changed files with 163 additions and 269 deletions

View File

@ -11,6 +11,7 @@ use Utils;
use Validator; use Validator;
use View; use View;
use stdClass; use stdClass;
use Cache;
use App\Models\User; use App\Models\User;
use App\Models\Activity; use App\Models\Activity;
@ -129,30 +130,16 @@ class AccountController extends BaseController
public function showSection($section = ACCOUNT_DETAILS, $subSection = false) public function showSection($section = ACCOUNT_DETAILS, $subSection = false)
{ {
if ($section == ACCOUNT_DETAILS) { if ($section == ACCOUNT_DETAILS) {
/* Update Remember Function
$data = [ $data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Cache::get('countries'),
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'sizes' => Cache::get('sizes'),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'industries' => Cache::get('industries'),
'timezones' => Timezone::remember(DEFAULT_QUERY_CACHE)->orderBy('location')->get(), 'timezones' => Cache::get('timezones'),
'dateFormats' => DateFormat::remember(DEFAULT_QUERY_CACHE)->get(), 'dateFormats' => Cache::get('dateFormats'),
'datetimeFormats' => DatetimeFormat::remember(DEFAULT_QUERY_CACHE)->get(), 'datetimeFormats' => Cache::get('datetimeFormats'),
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'currencies' => Cache::get('currencies'),
'languages' => Language::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'languages' => Cache::get('languages'),
'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(),
'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id, 'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id,
]; ];
@ -210,8 +197,6 @@ class AccountController extends BaseController
$invoice->invoice_items = [$invoiceItem]; $invoice->invoice_items = [$invoiceItem];
$data['invoice'] = $invoice; $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(); $data['invoiceDesigns'] = InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get();
} else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) { } else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) {
$data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE); $data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE);
@ -391,7 +376,7 @@ class AccountController extends BaseController
$count = 0; $count = 0;
$hasHeaders = Input::get('header_checkbox'); $hasHeaders = Input::get('header_checkbox');
$countries = Country::remember(DEFAULT_QUERY_CACHE)->get(); $countries = Cache::get('countries');
$countryMap = []; $countryMap = [];
foreach ($countries as $country) { foreach ($countries as $country) {

View File

@ -9,6 +9,7 @@ use Validator;
use Input; use Input;
use Session; use Session;
use Redirect; use Redirect;
use Cache;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Client; use App\Models\Client;
@ -178,23 +179,12 @@ class ClientController extends BaseController
private static function getViewModel() private static function getViewModel()
{ {
/* Remember function no longer works
return [ return [
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'sizes' => Cache::get('sizes'),
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'paymentTerms' => Cache::get('paymentTerms'),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'industries' => Cache::get('industries'),
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'currencies' => Cache::get('currencies'),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Cache::get('countries'),
'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(),
'customLabel1' => Auth::user()->account->custom_client_label1, 'customLabel1' => Auth::user()->account->custom_client_label1,
'customLabel2' => Auth::user()->account->custom_client_label2, 'customLabel2' => Auth::user()->account->custom_client_label2,
]; ];

View File

@ -7,7 +7,7 @@ use Session;
use Utils; use Utils;
use View; use View;
use Validator; use Validator;
zz
use App\Models\Client; use App\Models\Client;
use App\Ninja\Repositories\CreditRepository; use App\Ninja\Repositories\CreditRepository;
@ -84,7 +84,6 @@ class CreditController extends BaseController
'method' => 'POST', 'method' => 'POST',
'url' => 'credits', 'url' => 'credits',
'title' => trans('texts.new_credit'), '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(), //'invoices' => Invoice::scope()->with('client', 'invoice_status')->orderBy('invoice_number')->get(),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
@ -102,7 +101,6 @@ class CreditController extends BaseController
'method' => 'PUT', 'method' => 'PUT',
'url' => 'credits/'.$publicId, 'url' => 'credits/'.$publicId,
'title' => 'Edit Credit', 'title' => 'Edit Credit',
//'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
return View::make('credit.edit', $data); return View::make('credit.edit', $data);

View File

@ -321,43 +321,17 @@ class InvoiceController extends BaseController
} }
} }
/*
return [ return [
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Cache::get('countries'),
'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(),
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(),
'currencies' => Cache::get('currencies'), 'currencies' => Cache::get('currencies'),
'sizes' => Size::orderBy('id')->get(), 'sizes' => Cache::get('sizes'),
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']), 'paymentTerms' => Cache::get('paymentTerms'),
'industries' => Industry::orderBy('name')->get(), 'industries' => Cache::get('industries'),
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(), 'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
'frequencies' => array( 'frequencies' => array(
1 => 'Weekly', 1 => 'Weekly',
2 => 'Two weeks', 2 => 'Two weeks',
@ -593,7 +567,7 @@ class InvoiceController extends BaseController
'invoice' => $invoice, 'invoice' => $invoice,
'versionsJson' => json_encode($versionsJson), 'versionsJson' => json_encode($versionsJson),
'versionsSelect' => $versionsSelect, '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); return View::make('invoices.history', $data);

View File

@ -10,6 +10,7 @@ use Validator;
use Omnipay; use Omnipay;
use CreditCard; use CreditCard;
use URL; use URL;
use Cache;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Invitation; use App\Models\Invitation;
@ -151,8 +152,7 @@ class PaymentController extends BaseController
'method' => 'POST', 'method' => 'POST',
'url' => "payments", 'url' => "payments",
'title' => trans('texts.new_payment'), 'title' => trans('texts.new_payment'),
//'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTypes' => Cache::get('paymentTypes'),
'paymentTypes' => PaymentType::orderBy('id')->get(),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
return View::make('payments.edit', $data); return View::make('payments.edit', $data);
@ -172,8 +172,7 @@ class PaymentController extends BaseController
'method' => 'PUT', 'method' => 'PUT',
'url' => 'payments/'.$publicId, 'url' => 'payments/'.$publicId,
'title' => trans('texts.edit_payment'), 'title' => trans('texts.edit_payment'),
//'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTypes' => Cache::get('paymentTypes'),
'paymentTypes' => PaymentType::orderBy('id')->get(),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
return View::make('payments.edit', $data); return View::make('payments.edit', $data);
@ -368,8 +367,7 @@ class PaymentController extends BaseController
'paymentLibrary' => $paymentLibrary, 'paymentLibrary' => $paymentLibrary,
'gateway' => $gateway, 'gateway' => $gateway,
'acceptedCreditCardTypes' => $acceptedCreditCardTypes, 'acceptedCreditCardTypes' => $acceptedCreditCardTypes,
//'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Cache::get('countries'),
'countries' => Country::orderBy('name')->get(),
'currencyId' => $client->currency_id, 'currencyId' => $client->currency_id,
'account' => $client->account 'account' => $client->account
]; ];
@ -418,8 +416,7 @@ class PaymentController extends BaseController
'paymentLibrary' => $paymentLibrary, 'paymentLibrary' => $paymentLibrary,
'gateway' => $gateway, 'gateway' => $gateway,
'acceptedCreditCardTypes' => $acceptedCreditCardTypes, 'acceptedCreditCardTypes' => $acceptedCreditCardTypes,
//'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Cache::get('countries'),
'countries' => Country::orderBy('name')->get(),
'currencyId' => 1, 'currencyId' => 1,
'paymentTitle' => $affiliate->payment_title, 'paymentTitle' => $affiliate->payment_title,
'paymentSubtitle' => $affiliate->payment_subtitle, 'paymentSubtitle' => $affiliate->payment_subtitle,

View File

@ -5,6 +5,7 @@ use Input;
use Redirect; use Redirect;
use Utils; use Utils;
use View; use View;
use Cache;
use App\Models\Account; use App\Models\Account;
use App\Models\Client; use App\Models\Client;
@ -139,35 +140,17 @@ class QuoteController extends BaseController
private static function getViewModel() 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 [ return [
'entityType' => ENTITY_QUOTE, 'entityType' => ENTITY_QUOTE,
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), '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(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(),
'currencies' => Currency::orderBy('name')->get(), 'currencies' => Cache::get('currencies'),
'sizes' => Size::orderBy('id')->get(), 'sizes' => Cache::get('sizes'),
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']), 'paymentTerms' => Cache::get('paymentTerms'),
'industries' => Industry::orderBy('name')->get(), 'industries' => Cache::get('industries'),
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(), 'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
'invoiceLabels' => Auth::user()->account->getInvoiceLabels() 'invoiceLabels' => Auth::user()->account->getInvoiceLabels()
]; ];

View File

@ -1,4 +1,4 @@
<?php namespace App\Http\Middleware; <?php namespace app\Http\Middleware;
use Closure; use Closure;
use Utils; use Utils;
@ -9,151 +9,149 @@ use Redirect;
use Cache; use Cache;
use Session; use Session;
use Event; use Event;
use App\Models\Currency;
use App\Events\UserSettingsChanged; use App\Events\UserSettingsChanged;
class StartupCheck { class StartupCheck
{
/** /**
* Handle an incoming request. * Handle an incoming request.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Closure $next * @param \Closure $next
* @return mixed * @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
// Ensure all request are over HTTPS in production // Ensure all request are over HTTPS in production
if (App::environment() == ENV_PRODUCTION) if (App::environment() == ENV_PRODUCTION) {
{ if (!Request::secure()) {
if (!Request::secure()) return Redirect::secure(Request::getRequestUri());
{ }
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());
} }
// 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 // Check data has been cached
if (Auth::check()) $cachedTables = [
{ 'currencies' => 'App\Models\Currency',
$count = Session::get(SESSION_COUNTER, 0); 'sizes' => 'App\Models\Size',
Session::put(SESSION_COUNTER, ++$count); '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')) { if ($name == 'paymentTerms') {
$data = false; $orderBy = 'num_days';
if (Utils::isNinja()) { } elseif (property_exists($class, 'name') && $name != 'paymentTypes') {
$data = Utils::getNewsFeedResponse(); $orderBy = 'name';
} 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);
}
}
}
Cache::forever($name, $class::orderBy($orderBy)->get());
}
}
// Check if we're requesting to change the account's language // check the application is up to date and for any news feed messages
if (Input::has('lang')) if (Auth::check()) {
{ $count = Session::get(SESSION_COUNTER, 0);
$locale = Input::get('lang'); Session::put(SESSION_COUNTER, ++$count);
App::setLocale($locale);
Session::set(SESSION_LOCALE, $locale);
if (Auth::check()) if (!Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && !Session::has('news_feed_id')) {
{ $data = false;
if ($language = Language::whereLocale($locale)->first()) if (Utils::isNinja()) {
{ $data = Utils::getNewsFeedResponse();
$account = Auth::user()->account; } else {
$account->language_id = $language->id; $file = @file_get_contents(NINJA_APP_URL.'/news_feed/'.Utils::getUserType().'/'.NINJA_VERSION);
$account->save(); $data = @json_decode($file);
} }
} if ($data) {
} if ($data->version != NINJA_VERSION) {
else if (Auth::check()) $params = [
{ 'user_version' => NINJA_VERSION,
$locale = Session::get(SESSION_LOCALE, DEFAULT_LOCALE); 'latest_version' => $data->version,
App::setLocale($locale); '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 // Check if we're requesting to change the account's language
if (Auth::check() && !Session::has(SESSION_TIMEZONE)) 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()); Event::fire(new UserSettingsChanged());
} }
// Check if the user is claiming a license (ie, additional invoices, white label, etc.) // Check if the user is claiming a license (ie, additional invoices, white label, etc.)
$claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license'); $claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license');
if (!$claimingLicense && Input::has('license_key') && Input::has('product_id')) if (!$claimingLicense && Input::has('license_key') && Input::has('product_id')) {
{ $licenseKey = Input::get('license_key');
$licenseKey = Input::get('license_key'); $productId = Input::get('product_id');
$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 ($productId == PRODUCT_INVOICE_DESIGNS) {
{ if ($data = json_decode($data)) {
if ($data = json_decode($data)) foreach ($data as $item) {
{ $design = new InvoiceDesign();
foreach ($data as $item) $design->id = $item->id;
{ $design->name = $item->name;
$design = new InvoiceDesign(); $design->javascript = $item->javascript;
$design->id = $item->id; $design->save();
$design->name = $item->name; }
$design->javascript = $item->javascript;
$design->save();
}
if (!Utils::isNinjaProd()) { if (!Utils::isNinjaProd()) {
Cache::forget('invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId()); Cache::forget('invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId());
} }
Session::flash('message', trans('texts.bought_designs')); Session::flash('message', trans('texts.bought_designs'));
} }
} } elseif ($productId == PRODUCT_WHITE_LABEL) {
else if ($productId == PRODUCT_WHITE_LABEL) if ($data == 'valid') {
{ $account = Auth::user()->account;
if ($data == 'valid') $account->pro_plan_paid = NINJA_DATE;
{ $account->save();
$account = Auth::user()->account;
$account->pro_plan_paid = NINJA_DATE;
$account->save();
Session::flash('message', trans('texts.bought_white_label')); Session::flash('message', trans('texts.bought_white_label'));
} }
} }
} }
return $next($request);
}
return $next($request);
}
} }

View File

@ -193,7 +193,7 @@ class Account extends Eloquent
public function getLocale() 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; return $language->locale;
} }

View File

@ -176,37 +176,6 @@
@yield('content') @yield('content')
</div> </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) @if (!Auth::check() || !Auth::user()->registered)
<div class="modal fade" id="signUpModal" tabindex="-1" role="dialog" aria-labelledby="signUpModalLabel" aria-hidden="true"> <div class="modal fade" id="signUpModal" tabindex="-1" role="dialog" aria-labelledby="signUpModalLabel" aria-hidden="true">