Sylius, SearchBundle - symfony

Search in latest Sylius-standard does not work:
[Syntax Error] line 0, col 92: Error: Expected known function, got 'MATCH'
[1/2] QueryException: select u.itemId, u.tags, u.entity from Sylius\Bundle\SearchBundle\Model\SearchIndex u WHERE MATCH(u.value) AGAINST (:searchTerm) > 0
How to fix?

You need to add the custom function to you doctrine config as in the Sylius app/config/config.yml
doctrine:
...
orm:
dql:
string_functions:
MATCH: Sylius\Bundle\SearchBundle\Extension\Doctrine\MatchAgainstFunction

Here are the steps to get it working :
In app/config/config.yml put in the following lines
doctrine:
dbal:
driver: %sylius.database.driver%
host: %sylius.database.host%
port: %sylius.database.port%
dbname: %sylius.database.name%
user: %sylius.database.user%
password: %sylius.database.password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
mappings:
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
is_bundle: false
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
dql:
string_functions:
MATCH: Sylius\Bundle\SearchBundle\Extension\Doctrine\MatchAgainstFunction
In your mysql database look for the table sylius_search_index and check if it has a full index on the value column, if not just run the below command :
ALTER TABLE sylius_search_index ADD FULLTEXT index_name(
value
)
On the console run the following command for your products:
php app/console sylius:search:index
The above command builds a list of search terms for the search in the sylius_search_index table value column.
That should be all !

Related

Symfony4 doctrine utf8mb4 not detected

i have an issue with doctrine and symfony4.1, he don't take my charset parameter.
I have always my tables with charset utf8 and collate utf8_unicode_ci.
I have tried with mariadb / mysql and nothing work he never detect my charset configuration.
I have drop my database, recreate and migrate mutiple times and clear cache everytime. But he doesn't work.
commands :
php bin/console doctrine:database:drop --force
php bin/console doctrine:database:create
php bin/console make:migration
php bin/console doctrine:migration:migrate
here my configuration file :
doctrine:
dbal:
driver: pdo_mysql
host: "%env(DATABASE_MASTER_HOST)%"
dbname: "%env(DATABASE_DBNAME)%"
user: "%env(DATABASE_USER)%"
password: "%env(DATABASE_PASSWORD)%"
slaves:
slave1:
host: "%env(DATABASE_SLAVE_HOST)%"
dbname: "%env(DATABASE_DBNAME)%"
user: "%env(DATABASE_USER)%"
password: "%env(DATABASE_PASSWORD)%"
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
string_functions:
GROUP_CONCAT: DoctrineExtensions\Query\Mysql\GroupConcat
IF: DoctrineExtensions\Query\Mysql\IfElse
FIND_IN_SET: App\DQL\FindInSet
When i add to my sql configuration file :
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
My database is created with utf8mb4_unicode_ci
but my tables is always generate with utf8 / utf8_unicode_ci
It work if i create my entity with the options parameter:
#ORM\Table(options={"charset":"utf8mb4"}...)
But i don't want to change all my table like that and my jointable are always with utf8.
why he don't take my configuration of charset.
It look likes something doens't work when i use MasterSlaveConnection.
Thanks a lot for your help.

Match Against Doctrine Extension configuration

I'm trying to make match against doctrine extension work but i get error with doctrine configuration file. I got Unrecognized option "dql" under "doctrine.orm" . How to propely use symfony 4 + doctrine + match against extension?
Match against file + conf https://gist.github.com/ZeBigDuck/1234419#file-addfulltextindexescommand-php
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
dql:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# string_functions:
# MATCH_AGAINST: App\Extension\Doctrine\MatchAgainst
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
entity_managers:
default:
dql:
string_functions:
MATCH_AGAINST: App\Extension\Doctrine\MatchAgainst
Try it like this:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
string_functions:
MATCH_AGAINST: App\Extension\Doctrine\MatchAgainst
EDIT.. It should be something like this (not tested):
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
string_functions:
MATCH_AGAINST: App\Extension\Doctrine\MatchAgainst
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App

YEAR() and beberlei/DoctrineExtensions

I have to make requests with YEAR and I installed beberlei/DoctrineExtensions with doctrine command. I added the requested annotations
doctrine:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
datetime_functions:
year: DoctrineExtensions\Query\Mysql\Year
, but it does not work, I have this error:
Attempted to load class "Year" from namespace
"DoctrineExtensions\Query\Mysql". Did you forget a "use" statement for
another namespace?
The request:
public function groupTypeInterArray(){
$qb = $this->createQueryBuilder('i')
->select('YEAR(i.interventionDate)');
return $qb->getQuery()->execute();
}
Config Doctrine
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
datetime_functions:
Year: DoctrineExtensions\Query\Mysql\Year
I searched all the afternoon, but I didn't find the solution.
Thank you in advance.
enter image description here
1.dql:
datetime_functions:
year: DoctrineExtensions\Query\Mysql\Year ???
2.dql:
datetime_functions:
Year: DoctrineExtensions\Query\Mysql\Year ???
Maybe
dql:
datetime_functions:
YEAR: DoctrineExtensions\Query\Mysql\Year
MONTH: DoctrineExtensions\Query\Mysql\Month
DAY: DoctrineExtensions\Query\Mysql\Day
For me removing the vendor dir and do a fresh composer install solved the problem.
in the query replace "Year" with "year"
so use the following code instead:
public function groupTypeInterArray(){
$qb = $this->createQueryBuilder('i')
->select('year(i.interventionDate)');
return $qb->getQuery()->execute();
}
and you also need to change the corresponding line in the doctrine config :
replaces this code
Year: DoctrineExtensions\Query\Mysql\Year
By this code
year: DoctrineExtensions\Query\Mysql\Year
PS : to know which link you have to use to add a function correctly in doctrine config you have to go on this link

sonatabundle installation ApplicationSonataMediaBundle not found

I tried to follow the tutorial installation for SonataBundle tutorial
I change only mapping in this way
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
ApplicationSonataMediaBundle: ~
SonataMediaBundle: ~
the command
php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle
generate in src/Application/Sonata/MediaBundle/ApplicationSonataMediaBundle
but always I get this error :
Class 'Application\Sonata\MediaBundle\ApplicationSonataMediaBundle' not found

FOSUserBundle generate:entities does not work, Access level of fields too high

I have a problem with FOSUserBundle after I configured DoctrineExtensions, with StofDoctrineExtensionsBundle.
First of all, to install DoctrineExtensions I had to remove "auto_mapping: true" segment from app/config/config.yml file.
I found that if auto_mapping is not active I have to include FOSUserBundle: ~ in default:mappings segment.
But, when I try
php app/console doctrine:schema:update --force
or
php app/console doctrine:generate:entities FOS
I get:
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
Generating entities for namespace "FOS"
PHP Fatal error: Access level to FOS\UserBundle\Entity\User::$username must be protected (as in class FOS\UserBundle\Model\User) or weaker in /var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php on line 17
PHP Stack trace:
PHP 1. {main}() /var/www/rBay/app/console:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/rBay/app/console:22
PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:105
PHP 4. Symfony\Component\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
PHP 5. Symfony\Component\Console\Command\Command->run() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:192
PHP 6. Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:238
PHP 7. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getNamespaceMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:109
PHP 8. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForNamespace() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:97
PHP 9. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:160
PHP 10. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
PHP 11. Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:111
PHP 12. Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:132
PHP 13. require_once() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:194
PHP 14. Symfony\Component\ClassLoader\DebugClassLoader->loadClass() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:0
PHP 15. require() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:82
Fatal error: Access level to FOS\UserBundle\Entity\User::$username must be protected (as in class FOS\UserBundle\Model\User) or weaker in /var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php on line 17
Call Stack:
0.0002 644752 1. {main}() /var/www/rBay/app/console:0
0.0132 3467080 2. Symfony\Component\Console\Application->run() /var/www/rBay/app/console:22
0.0155 3851816 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:105
2.3154 50066792 4. Symfony\Component\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
2.3187 50066792 5. Symfony\Component\Console\Command\Command->run() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:192
2.3192 50068328 6. Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:238
2.3208 50178008 7. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getNamespaceMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:109
2.3208 50178008 8. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForNamespace() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:97
2.3208 50178320 9. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:160
2.3307 50203984 10. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
2.3308 50204456 11. Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:111
2.3308 50205408 12. Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:132
2.3428 52000872 13. require_once('/var/www/rBay/src/MSoft/UserBundle/Entity/User.php') /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:194
2.3428 52001400 14. Symfony\Component\ClassLoader\DebugClassLoader->loadClass() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:0
2.3431 52081336 15. require('/var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php') /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:82
I'll attach related regions of my config file, as well, just in case...
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
connection: default
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable # this one is optional and will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator # this one is optional and will default to the name set for the mapping
is_bundle: false
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
alias: GedmoLoggable # this one is optional and will default to the name set for the mapping
is_bundle: false
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree # this one is optional and will default to the name set for the mapping
is_bundle: false
MSoftAdminBundle: ~
MSoftUserBundle: ~
FOSUserBundle: ~
# Fosuser Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: MSoft\UserBundle\Entity\User
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: true
sluggable: true
What am I doing wrong?
Solved. Problem appeared when I ran
php app/console doctrine:generate:entities FOS
Than doctrine entity generator added properties that wasn't supposed to be there, and that made a problem.
The point is that class FOS\UserBundle\Entity\User should have empty body, and generator created all the fields from FOS\UserBundle\Model\User in it, just with higher protection level ("private" instead of "protected").
All properties of the User class should be protected, not public.

Resources