1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #3902 from turbo124/v2

Update refresh route to filter all subqueries by updated_at
This commit is contained in:
David Bomba 2020-07-10 21:43:26 +10:00 committed by GitHub
commit baf5f8f479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 5 deletions

View File

@ -1 +1 @@
5.0.10
5.0.12

View File

@ -243,7 +243,7 @@ class LoginController extends BaseController
public function refresh(Request $request)
{
$ct = CompanyUser::whereUserId(auth()->user()->id);
return $this->listResponse($ct);
return $this->refreshResponse($ct);
}
/**

View File

@ -130,6 +130,51 @@ class BaseController extends Controller
return response()->make($error, $httpErrorCode, $headers);
}
protected function refreshResponse($query)
{
$this->buildManager();
$transformer = new $this->entity_transformer(Input::get('serializer'));
$includes = $transformer->getDefaultIncludes();
$includes = $this->getRequestIncludes($includes);
$updated_at = request()->has('updated_at') ? request()->input('updated_at') : 0;
$updated_at = date('Y-m-d H:i:s', $updated_at);
$query->with(
[
'company' => function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.activities' => function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.clients' =>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.tax_rates'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.groups'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.company_gateways'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.clients.contacts'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.products'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.invoices.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.invoices.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.invoices.documents'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.payments.paymentables'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.quotes.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.quotes.documents'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.credits.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.credits'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.payment_terms'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.vendors'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.expenses'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.tasks'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.projects'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
'company.designs'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);},
]
);
$data = $this->createCollection($query, $transformer, $this->entity_type);
return $this->response($data);
}
protected function listResponse($query)
{
$this->buildManager();

View File

@ -51,7 +51,7 @@ class QueryLogging
// Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
//if($count > 10)
// Log::info($queries);
Log::info($queries);
}
}

View File

@ -30,7 +30,7 @@ class StoreWebhookRequest extends Request
public function rules()
{
return [
'target_url' => 'required',
'target_url' => 'required|url',
'event_id' => 'required',
];
}

View File

@ -34,6 +34,7 @@ class UpdateWebhookRequest extends Request
public function rules()
{
return [
'target_url' => 'url',
];
}

View File

@ -64,7 +64,7 @@ class WebhookHandler implements ShouldQueue
// generate JSON data
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$manager->parseIncludes($include);
// $manager->parseIncludes($include);
$transformer = new $this->getTransformerClassName();