Log message #4197637

# At Username Text
# Aug 13th 2019, 03:05 challgren Digging into the code it looks cookie based
# Aug 13th 2019, 02:56 claudio Yeah it's worth the shot, just going to drop a line on the forum to, maybe someone else has some ideas I can try before changing the live server to use database sessions. Thanks for the feedback @challgren
# Aug 13th 2019, 02:54 challgren Id root around in the CsrfComponent and see what its doing there to set it and verify it
# Aug 13th 2019, 02:54 challgren Im not 100% honestly
# Aug 13th 2019, 02:53 claudio component
# Aug 13th 2019, 02:53 challgren Are you using the component or middleware?
# Aug 13th 2019, 02:53 claudio @challgren I actually thought the issue could be there, but testing locally, I did delete the tmp/sessions folder and I didn't get any token mismatch exceptions, I did notice some pages were acting up because the session had gone away, but not the csrf in particular. It's worth the try but I wanted to be sure before trying it out. Anything else worth checking?
# Aug 13th 2019, 02:51 challgren might want a central cache location for your session since it auto scales
# Aug 13th 2019, 02:51 claudio 'Session' => [ 'defaults' => 'cake', 'timeout' => 480 ...
# Aug 13th 2019, 02:49 challgren How are you storing your cookies?
# Aug 13th 2019, 02:49 claudio Hi everyone. My current Cake website is hosted in AWS and it allows for auto scaling, works perfectly but recently having migrated to a newer version of cake, we started using the Csrf component ( Not the middleware ) but when the when the server auto scales I sometimes get a token mismatch exception, any way to fix this issue? Thanks
# Aug 13th 2019, 02:34 latenal @challgren, thanks. It worked. But while I was doing it, I realized that it works as well if I interchange the func and value as `$entityId => 'json_extract(`data`, “$.user_id”)’`
# Aug 13th 2019, 02:13 challgren Youd have to use a query function https://book.cakephp.org/3.0/en/orm/query-builder.html#custom-functions
# Aug 13th 2019, 01:55 slackebot1 ignored). How do I fix it?
# Aug 13th 2019, 01:55 latenal I have a simple query ``` $query = $this->Logs ->find() ->select(['Logs.id', 'Logs.action', 'Logs.ip', 'Logs.created']); $conditions = [ 'OR' => [ 'user_id' => $entityId, "JSON_EXTRACT(`data`, '$.user_id') =" => $entityId ] ]; $query = $query->where($conditions); ``` When I run it I get only 1 value (`JSON_EXTRACT` seems to be
# Aug 12th 2019, 22:12 slackebot1 and it's in the middle of the night, so that's all I have for now, you get the idea :slightly_smiling_face:
# Aug 12th 2019, 22:12 ndm @scuadra And here's a quick and dirty example for `belongsToMany` for DBMS' that do support window functions: https://gist.github.com/ndm2/b417e3fa683a972e295dc0e24ef515e3. That might not be the best way to do it, like, there's a redundant `IN` condition, I'm not sure how well this will work with additional conditions on the association, using `FROM` instead of a `JOIN` for the ranked data might be better, etc, but after all it's just an example,
# Aug 12th 2019, 21:58 ricksaccous @latenal thanks, the rule idea helped, my code is less convoluted now
# Aug 12th 2019, 21:03 slackebot1 $retailTable->find() ->where(['product_id' => $entity->id]) ->count(); return $retail + $wholesale > 0 || !$entity->visible; }, 'visible', [ 'message' => 'Fill in the inventory first', 'errorField' => 'visible' ]); ```
# Aug 12th 2019, 21:03 latenal Here it is: ``` <?php // Check minimum qty $rules->add(function ($entity, $options) { $wholesaleTable = TableRegistry::getTableLocator()->get('ProductWholesalePrices'); $wholesale = $wholesaleTable->find() ->where(['product_id' => $entity->id]) ->count(); $retailTable = TableRegistry::getTableLocator()->get('ProductRetailPrices'); $retail =
# Aug 12th 2019, 21:01 latenal I am looking for a code sample..
# Aug 12th 2019, 21:00 ricksaccous rather than whatever i'm doing
# Aug 12th 2019, 21:00 ricksaccous hmm that might be a decent idea actually
# Aug 12th 2019, 20:59 latenal I’ve done it in `buildRules`
# Aug 12th 2019, 20:31 ricksaccous hmmmm
# Aug 12th 2019, 20:31 ricksaccous i mean evaluate conditionally
# Aug 12th 2019, 20:30 ricksaccous the entity doesn't seem to be passed into "context"
# Aug 12th 2019, 20:30 ricksaccous rather than the request data
# Aug 12th 2019, 20:30 ricksaccous also what's the best way to deal with a situation where the data i want to evaluate is in the entity
# Aug 12th 2019, 20:18 ricksaccous is this evil and if so what's a good way to avoid this, lol
# Aug 12th 2019, 20:17 slackebot1 <ricksaccous>
# Aug 12th 2019, 20:01 latenal ok, thanks
# Aug 12th 2019, 20:00 ricksaccous however you see fit i suppose
# Aug 12th 2019, 19:57 latenal preg_replace?
# Aug 12th 2019, 19:56 latenal how do I do that?
# Aug 12th 2019, 19:56 ricksaccous that's prob one of the only things you'll have to escape i believe, like conditions and places where the param can have special keywords that have unintended consequences
# Aug 12th 2019, 19:55 latenal I am afraid, the sql will look like `title LIKE '%some%'`
# Aug 12th 2019, 19:54 latenal and even if `$title = ‘some%’;
# Aug 12th 2019, 19:53 latenal so will it work if I use this: `$query->where(['title LIKE' => '%' . $title]);`?
# Aug 12th 2019, 19:52 ricksaccous what's the best way to achieve this validation wise
# Aug 12th 2019, 19:52 ricksaccous suppose i want to pop an error in a related model based on the parent model's context