Logger does not log Exceptions thrown in application - zend-framework3

I use the configuration below to create a logger:
'log' => [
'logger' => [
'writers' => [
'stream' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::INFO,
'options' => [
'stream' => __DIR__ . '/../../data/log/name_' . date("Ym") . '.log',
'formatter' => [
'name' => \Zend\Log\Formatter\Simple::class,
'options' => [
'format' => '%timestamp% %priorityName% : %message% %extra%',
'dateTimeFormat' => 'c',
],
],
],
],
],
'processors' => [
'requestid' => [
'name' => \Zend\Log\Processor\RequestId::class,
],
'backtrace' => [
'name' => \Zend\Log\Processor\Backtrace::class,
],
],
],
],
Log works fine but php error not logged nowhere.
Why?
I use this code to generate a simple error
$d1 = new DateTime();
$d2 = new DateTime();
$a = array($d1,$d2);
$a->format("Y-m-d");
in my controller class.
This error is not logged

In PHP 7 ther's Error class to catch Fatal error
}catch(\Error $err){
$this->log->err($err->getMessage());
Error class

zend-log is not exception or error handler by default. You have to set it to do that. You can use exceptionhandler, errorhandler and fatal_error_shutdownfunction options to set it. All config keys accepts boolean value. Here's an example. I didn't test it but should be like that.
'log' => [
'logger' => [
'writers' => [
'stream' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::INFO,
'options' => [
'exceptionhandler' => true,
'errorhandler' => true,
'stream' => __DIR__ . '/../../data/log/name_' . date("Ym") . '.log',
'formatter' => [
'name' => \Zend\Log\Formatter\Simple::class,
'options' => [
'format' => '%timestamp% %priorityName% : %message% %extra%',
'dateTimeFormat' => 'c',
],
],
],
],
],
'processors' => [
'requestid' => [
'name' => \Zend\Log\Processor\RequestId::class,
],
'backtrace' => [
'name' => \Zend\Log\Processor\Backtrace::class,
],
],
],
],

Related

GA4 Api - How to filter metrics with php library

I am trying to filter dimensions with the GA4 api php library. Unfortunately, it is still in beta and I can't find any php examples on how to filter dimensions.
My code returns "Expect Google\Analytics\Data\V1beta\NumericValue."
Any help would be appreciated.
$response = $client->runReport([
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => 'yesterday',
'end_date' => 'yesterday',
]),
],
'dimensions' => [
new Dimension([
'name' => 'eventName',
]),
],
'metrics' => [new Metric(
[
'name' => 'eventCount',
])
],
'metricFilter' => new FilterExpression([
'filter' => new Filter([
'field_name' => 'eventCount',
'numeric_filter' => new Filter\NumericFilter([
'operation' => Filter\NumericFilter\Operation::GREATER_THAN,
'value' => '10000',
])
]),
]),
]);
Here is the JSON version of the request from the api explorer:
{
"dimensions": [
{
"name": "eventName"
}
],
"metrics": [
{
"name": "eventCount"
}
],
"dateRanges": [
{
"startDate": "yesterday",
"endDate": "yesterday"
}
],
"metricFilter": {
"filter": {
"fieldName": "eventCount",
"numericFilter": {
"operation": "GREATER_THAN",
"value": {
"int64Value": "10000"
}
}
}
}
}
I found the solution, I decided to leave this post since there is very little out there about filtering the ga4 api.
'metricFilter' => new FilterExpression([
'filter' => new Filter([
'field_name' => 'eventCount',
'numeric_filter' => new Filter\NumericFilter([
'operation' => Filter\NumericFilter\Operation::GREATER_THAN,
'value' => new NumericValue([
'int64_value' => '10000'
]),
])
]),
]),
```

FacetWP, query from today's date

i'm looking for a way to query posts with a date from today (current day).
My query looks like that :
<?php
return [
"post_type" => [
"event"
],
"post_status" => [
"publish"
],
"meta_query" => [
"0" => [
"key" => "date",
"compare" => ">",
"type" => "DECIMAL(16,4)",
"value" => "XXXXX"
],
"sort_0" => [
"key" => "date",
"type" => "CHAR"
]
],
"orderby" => [
"sort_0" => "ASC"
],
"posts_per_page" => "4"
];
I don't know what to set on TYPE and VALUE.
Is this possible to help me please?
Thanks a lot.
Actually I found out how to do it :)
Here is the snippet I should have used :
<?php
return [
"post_type" => [
"event"
],
"post_status" => [
"publish"
],
"meta_query" => [
"sort_0" => [
"key" => "date",
"compare" => ">",
"type" => "DATE",
"value" => date("Y-m-d"),
]
],
"orderby" => [
"sort_0" => "ASC"
],
"posts_per_page" => "4"
];

zf3 skeleton application not working when change module.config.php of Application module

zf3 not work well when change route of Appliation module
download a zf3 skeleton application ,change route of zf3
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
I change it to :
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/test',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/testapplication[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
when i visit /test and /testapplication/index , i got 404 page not found error, it seems zf3 can't route to this path
If you installed the skeleton app and run it without touching anything, then the problem is the cache.
If you look in the application config file (config/application.config.php), you will find these lines:
return [
'module_listener_options' => [
// Line 33
'config_cache_enabled' => true
]
];
This will create a cache file under the cache directory (by default, data/cache, as defined in application.config.php at line 47).
For development purposes, I suggest you to disable the cache. The best way to do that is to remove the .dist from the config/development.config.php.dist configuration file.

How to use match_phrase with constant_score, terms

This is my query in symfony2. I want to add here "match_phrase", but anywhere i add that, I get errors.
$params = [
'index' => 'articles_v2',
'type' => 'article',
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"constant_score" => [
"filter" => [
"bool" => [
"must" => [
["terms" => [ "article.topics" => $topics ] ],
["match_phrase" => ["article.bodytext" => [$search_phrase] ]]
]
]
]
]
]
]
];
$response = $client->search($params);
When I try to run this, I get error:
nested: QueryParsingException[[articles_v2] No filter registered for [match_phrase]]; }]","status":400
So where to place this match_phrase?
(I want to get results like SQL LIKE '%xxxx%')
I have changed the query. this time no errors, but anyway, no filtration.
$params = [
'index' => 'articles_v2',
'type' => 'article',
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"constant_score" => [
"filter" => [
"bool" => [
"must" => [
["terms" => [ "article.topics" => $topics ] ]
]
]
],
"query" => [
"multi_match" => [
"query" => $search_phrase,
"fields" => [ "title", "bodytext" ]
]
]
]
]
]
];
$response = $client->search($params);
The solution is not to use match with constant score.
You have to use query/bool/must and all this match and other conditions inside must.
Here is the code.
$params = [
'index' => 'articles_v2',
'type' => 'article',
'size' => 50,
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"bool" => [
"must" => [
[
"match_phrase_prefix" => [
"_all" => [
"query" => $search_phrase,
"operator" => "and",
"analyzer" => "analyzer_cs"
]
]
],
["terms" => [ "article.topics" => $topics ] ],
["range" => [ "article.date" => [ "from" => $date_from,"to" => $date_till]]]
]
]
]
]
];

DynamoDB - Update item by GSI (PHP)

I'm trying to update an item using a Global Secondary Index. My table definition is listed below. I am new to DynamoDb.
$response = $this->client->createTable([
'TableName' => 'rawproducts_products',
'AttributeDefinitions' => [
[
'AttributeName' => 'product_code',
'AttributeType' => 'N'
],
[
'AttributeName' => 'token',
'AttributeType' => 'S'
],
[
'AttributeName' => 'processed_at',
'AttributeType' => 'N'
],
[
'AttributeName' => 'created_at',
'AttributeType' => 'N'
]
],
'KeySchema' => [
[
'AttributeName' => 'product_code',
'KeyType' => 'HASH'
],
[
'AttributeName' => 'token',
'KeyType' => 'RANGE'
]
],
'LocalSecondaryIndexes' => [
[
'IndexName' => 'ProductCodeProcessedIndex',
'KeySchema' => [
['AttributeName' => 'product_code', 'KeyType' => 'HASH'],
['AttributeName' => 'processed_at', 'KeyType' => 'RANGE']
],
'Projection' => [
'ProjectionType' => 'KEYS_ONLY',
],
],
[
'IndexName' => 'ProductCodeCreatedIndex',
'KeySchema' => [
['AttributeName' => 'product_code', 'KeyType' => 'HASH'],
['AttributeName' => 'created_at', 'KeyType' => 'RANGE']
],
'Projection' => [
'ProjectionType' => 'KEYS_ONLY',
],
]
],
'GlobalSecondaryIndexes' => [
[
'IndexName' => 'TokenIndex',
'KeySchema' => [
[ 'AttributeName' => 'token', 'KeyType' => 'HASH' ]
],
'Projection' => [
'ProjectionType' => 'ALL'
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1
]
]
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 6
]
]);
When I try to update the attribute "complete" using the query below:
$this->dynamoDb->updateItem([
'TableName' => $this->table,
'TableIndex' => 'TokenIndex',
'Key' => [
'token' => ['S' => (string)$this->token['S']]
],
'UpdateExpression' => 'set complete = :complete',
'ExpressionAttributeValues' => [
':complete' => ['N' => (string)1]
]
]);
But I keep getting the following error:
"The provided key element does not match the schema"
Can anybody please advise a newbie. Many thanks.
It shows this because you are not passing key properly
You need to pass product_code and token both to update the value
Secondly
You cannot update value directly from GSI it's just a projection of the Table and not actual table
If you want to update the value you have to update in the table not in the index
refer this link.

Resources