Sorry for my English (gg translation).
I just passed all my entities with attributes instead of annotations.
Everything was working before and now I have this error.
I can't get it up. Do you have an idea ?
Thanks
composer.json :
Symfony 6.1.*
"php": ">=8.0.2",
"doctrine/annotations": "^1.13",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
#type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
numeric_functions:
acos: DoctrineExtensions\Query\Mysql\Acos
cos: DoctrineExtensions\Query\Mysql\Cos
radians: DoctrineExtensions\Query\Mysql\Radians
sin: DoctrineExtensions\Query\Mysql\Sin
error message : "Attribute "Doctrine\ORM\Mapping\Table" must not be repeated"
I made the modification of the annotations in attributes with rector.
In one of my entities, he transformed me this code:
/**
* #ORM\Entity(repositoryClass=CodePostalRepository::class)
* #Table(name="code_postal_villes",
* uniqueConstraints={#UniqueConstraint(name="ville_code_postal", columns={"code_postal_id", "villes_id"})}
* )
* #Table(name="code_postal",
* indexes={#Index(name="cp_idx",columns={"cp"})},
* uniqueConstraints={#UniqueConstraint(name="cp", columns={"cp"})}
* )
*/
in :
#[Table(name: 'code_postal_villes')]
#[UniqueConstraint(name: 'ville_code_postal', columns: ['code_postal_id', 'villes_id'])]
#[Table(name: 'code_postal')]
#[Index(name: 'cp_idx', columns: ['cp'])]
#[UniqueConstraint(name: 'cp', columns: ['cp'])]
#[ORM\Entity(repositoryClass: CodePostalRepository::class)]
This is what poses the problem.
There cannot be twice the table attribute
It remains to be seen how I solve the problem.
Same for me: I made the modifications with rector
It transformed this code:
* #ORM\Entity(repositoryClass="DropzoneRepository::class")
* #ORM\Table(name="dropzone")
* #ORM\Entity
into:
#[ORM\Table(name: 'dropzone')]
#[ORM\Entity(repositoryClass: DropzoneRepository::class)]
#[ORM\Entity]
The last line must be removed or you get two ORM\Entity annotations:
//#[ORM\Entity]
Related
I'm working in app upgrade from symfony 3.4 to 4.4.
But I'm having an issue with the query selects, I'm not sure why the result is always empty:
return $this
->_em
->createQuery('SELECT u FROM App\Entity\InternalUsers u')
->getResult();
Result: Array ( )
Using with getRepository:
$user = $this
->getDoctrine()
->getRepository(InternalUsers::class)
->validate($this->_getFilterParams(), $this->getParameter('ENCRYPTION_KEY'));
print_r($user);
Result: Array ( )
Validate function is inside InternalUserRepository
<?php
namespace App\Repository;
use CoreBundle\DoctrineExtensions\Paginate\Paginate;
use CoreBundle\Utils\Validate;
use App\Repository\BaseRepository;
use App\Entity\InternalUsers;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
/**
* Internal Users
* Controls DB operations of internal users.
*/
class InternalUserRepository extends ServiceEntityRepository {
/**
*
* #var type
*/
protected $InternalUsers;
public function __construct(ManagerRegistry $registry) {
parent::__construct($registry, InternalUsers::class);
}
/**
* Validate credentias.
*
* #param array $userData User creteria.
* #param string $encryptionKey Entrypt key.
*
* #return type
*/
public function validate(array $userData, string $encryptionKey) {
$criteria = [
'username' => $userData['username'],
'password' => sha1($encryptionKey . $userData['password'])
];
$user = $this->findOneBy($criteria);
var_dump($user); // NULL
if ($user) {
return $user;
}
}
It's using my cli:
$ php bin/console doctrine:query:dql "SELECT cat FROM App\Entity\InternalUsers cat"
array(0) {
}
I've a supposition with the ORM manually adjusted:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
# alias: App
# AppBundle:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/AppBundle/Entity'
# prefix: 'AppBundle\Entity'
# alias: AppBundle
App\Entity\:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/'
prefix: 'App\Entity\'
alias: App\Entity\
But I'm still not getting results, I've almost 2 days working on this issue and there is no answer after investigating and reading the documentations.
It was another try, but there were no results as well.
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
auto_mapping: true
metadata_cache_driver:
type: 'service'
id: doctrine.cache.memcached
query_cache_driver:
type: 'service'
id: doctrine.cache.memcached
result_cache_driver:
type: 'service'
id: doctrine.cache.memcached
dql:
string_functions:
STRING_AGG: GalleryCore\CoreBundle\DoctrineExtensions\DQL\StringAgg
Here an update!
It looks like related to type of Entity mapping.
After configuring the doctrine.orm.
orm:
auto_generate_proxy_classes: '%kernel.debug%'
#default_entity_manager: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
#entity_managers:
#default:
#metadata_cache_driver:
# type: 'service'
# id: doctrine.cache.memcached
#query_cache_driver:
# type: 'service'
# id: doctrine.cache.memcached
#dql:
# string_functions:
# STRING_AGG: GalleryCore\CoreBundle\DoctrineExtensions\DQL\StringAgg
#connection: default
#naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
# alias: App
# AppBundle:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/AppBundle/Entity'
# prefix: 'AppBundle\Entity'
# alias: AppBundle
#App\Entity:
#is_bundle: false
#type: annotation
#dir: '%kernel.project_dir%/src/Entity'
#prefix: 'App\Entity'
#alias: App
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/'
prefix: 'App\Entity'
alias: App
I ran this command:
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
to generate the entities correctly in my src/Entity folder
output:
$ php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
Importing mapping information from "default" entity manager
> writing src/Entity/Bonsai.trackSites.php
> writing src/Entity/Gallery.adTagTypes.php
> writing src/Entity/Gallery.albumAssets.php
> writing src/Entity/Gallery.appUrls.php
> writing src/Entity/Gallery.adTags.php
> writing src/Entity/Bonsai.trackAssettypes.php
> writing src/Entity/Bonsai.trackViews.php
> writing src/Entity/Bonsai.trackVisitors.php
> writing src/Entity/Gallery.apps.php
> writing src/Entity/Gallery.adGptTags.php
> writing src/Entity/Gallery.appConfigurations.php
> writing src/Entity/Gallery.appFeatures.php
> writing src/Entity/Gallery.appUrlTypes.php
> writing src/Entity/Gallery.assetFlags.php
> writing src/Entity/Gallery.assetTypes.php
> writing src/Entity/Gallery.assetVotes.php
> writing src/Entity/Gallery.assets.php
> writing src/Entity/Gallery.assetsKeywords.php
> writing src/Entity/Gallery.exifValues.php
> writing src/Entity/Gallery.comments.php
> writing src/Entity/Gallery.exifFields.php
> writing src/Entity/Gallery.domains.php
> writing src/Entity/Gallery.countries.php
> writing src/Entity/Gallery.featuredAssetsData.php
> writing src/Entity/Gallery.fieldValues.php
> writing src/Entity/Gallery.jobsQueue.php
> writing src/Entity/Gallery.regions.php
> writing src/Entity/Gallery.indexJobs.php
> writing src/Entity/Gallery.keywords.php
> writing src/Entity/Gallery.externalValues.php
> writing src/Entity/Gallery.releaseDates.php
> writing src/Entity/Gallery.requestTypes.php
> writing src/Entity/Gallery.responseLogs.php
> writing src/Entity/Gallery.userRoles.php
> writing src/Entity/Gallery.trendingConfiguration.php
> writing src/Entity/Gallery.votesConfiguration.php
> writing src/Entity/Bonsai.trackAssets.php
> writing src/Entity/Gallery.internalUsers.php
> writing src/Entity/Gallery.commentFlags.php
> writing src/Entity/Gallery.verticals.php
> writing src/Entity/Gallery.fields.php
> writing src/Entity/Gallery.fieldTypes.php
> writing src/Entity/Gallery.imageTags.php
> writing src/Entity/Gallery.internalCategories.php
> writing src/Entity/Gallery.sitesConnections.php
> writing src/Entity/Gallery.threadAssets.php
> writing src/Entity/Gallery.trendingCriterias.php
> writing src/Entity/Gallery.trendingFormulaDetails.php
> writing src/Entity/Gallery.trendingFormulas.php
> writing src/Entity/Gallery.userSettings.php
> writing src/Entity/Gallery.userVariables.php
> writing src/Entity/AdGptTags.php
after made a couple of adjustments:
$user = $this
->getDoctrine()
->getRepository(InternalUsers::class)
->findOneBy(
$criteria = [
'username' => $this->_getFilterParams()['username'],
'password' => sha1($this->getParameter('ENCRYPTION_KEY') . $this->_getFilterParams()['password'])
]
);
// validate($this->_getFilterParams(), $this->getParameter('ENCRYPTION_KEY'));
var_dump($user->getUsername());
exit;
it's my output:
string(10) "superadmin"
I have a query with hardcoded dates used in the parameters section.Instead I want to pass them as environment variables.Any suggestions on how to parameterize the QueryString parameter?
service: service-name
frameworkVersion: '2'
provider:
name: aws
runtime: go1.x
lambdaHashingVersion: 20201221
stage: ${opt:stage, self:custom.defaultStage}
region: us-east-1
tags: ${self:custom.tagsObject}
logRetentionInDays: 1
timeout: 10
deploymentBucket: lambda-repository
memorySize: 128
tracing:
lambda: true
plugins:
- serverless-step-functions
configValidationMode: error
stepFunctions:
stateMachines:
callAthena:
name: datasorting-dev
type: STANDARD
role: ${self:custom.datasorting.${self:provider.stage}.iam}
definition:
Comment: "Data Refersh"
StartAt: Refresh Data
States:
Refresh Data:
Type: Task
Resource: arn:aws:states:::athena:startQueryExecution.sync
Parameters:
QueryString: >-
ALTER TABLE table.raw_data ADD IF NOT EXISTS
PARTITION (YEAR=2021, MONTH=02, DAY=15, hour=00)
WorkGroup: primary
ResultConfiguration:
OutputLocation: s3://output/location
End: true
you can replace any value in your serverless.yml enclosed in ${} brackets,
Serverless Framework Guide to Variables:
https://www.serverless.com/framework/docs/providers/aws/guide/variables/
for example, you can create a custom: section looking for environment variables, and if they are not present, you can have default values:
service: service-name
frameworkVersion: '2'
custom:
year: ${env:YEAR, 'default-year'}
month: ${env:MONTH, 'default-month'}
day: ${env:DAY, 'default-day'}
hour: ${env:HOUR, 'default-hour'}
stepFunctions:
stateMachines:
callAthena:
...
Parameters:
QueryString: >-
ALTER TABLE table.raw_data ADD IF NOT EXISTS
PARTITION (YEAR=${self:custom.year}, MONTH=${self:custom.month}, DAY=${self:custom.day}, hour=${self:custom.hour})
...
I'm working in a symfony project and I have a problem with browsing server in ckeditor for inserting images.
I'm using "Trsteel/ckeditor-bundle": "~1.8" and "helios-ag/fm-elfinder-bundle": "~4.0". When I try to browse the server to add image I have this error (Unable to connect to backend):
Warning: Missing argument 1 for
FM\ElFinderPHP\Connector\ElFinderConnector::run(), called in
C:\wamp\www\awb\vendor\helios-ag\fm-elfinder-bundle\Loader\ElFinderLoader.php
on line 63 and defined
Here is my config.yml:
trsteel_ckeditor: class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
transformers: [] toolbar: ['document', 'clipboard', 'editing', '/',
'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
toolbar_groups: document: ['Source','-','Save','-','Templates']
clipboard:
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']
editing: ['Find','Replace','-','SelectAll'] basicstyles:
['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']
paragraph:
['NumberedList','BulletedList','-','Outdent','Indent','-','JustifyLeft',
'JustifyCenter','JustifyRight','JustifyBlock'] links:
['Link','Unlink','Anchor'] insert:
['Image','Flash','Table','HorizontalRule'] styles: ['Styles','Format']
tools: ['Maximize', 'ShowBlocks'] ui_color: '#ffffff'
startup_outline_blocks: false width: 100% #Integer or % height: 300
Integer or % language: 'fr'
filebrowser_upload_url:
url: relative-url.php?type=file filebrowser_image_browse_url: route: elfinder route_parameters: instance: default
fm_elfinder: instances: default: locale: %locale% editor: ckeditor
fullscreen: true include_assets: true connector: debug: false roots:
uploads: show_hidden: false driver: LocalFileSystem path: uploads
upload_allow: ['image/png', 'image/jpg', 'image/jpeg'] upload_deny:
['all'] upload_max_size: 6M
Can someone help me please?
You should as suggested in the issues of fe-elfindeer to use the 5.0.5 version of ElFinderBundle who provides the 1st parameter to the ElFinderConnector::run() function.
Maybe you could try to edit your composer.json file as following :
"helios-ag/fm-elfinder-bundle": "~5.0",
"helios-ag/fm-elfinder-php-connector": "~2.3"
and run composer update helios-ag/fm-elfinder-bundle helios-ag/fm-elfinder-php-connector
Receiving the following error message when trying to run my project.
Fatal error: Uncaught exception 'Doctrine\ODM\PHPCR\Translation\MissingTranslationException' with message 'The locale 'en' is not present in the list of available locales' in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Doctrine\ODM\PHPCR\Translation\MissingTranslationException: The locale 'en' is not present in the list of available locales in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
And the following stack trace:
# Time Memory Function Location
1 0.0040 240752 {main}( ) ../app.php:0
2 0.0299 643576 Symfony\Component\HttpKernel\HttpCache\HttpCache->handle( ) ../app.php:20
3 0.0309 657488 Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup( ) ../HttpCache.php:193
4 0.0316 659008 Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch( ) ../HttpCache.php:329
5 0.0317 665184 Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache->forward( ) ../HttpCache.php:429
6 0.4876 9740256 Symfony\Component\HttpKernel\HttpCache\HttpCache->forward( ) ../HttpCache.php:60
7 0.4877 9742120 Symfony\Component\HttpKernel\Kernel->handle( ) ../HttpCache.php:466
8 0.4957 9838264 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( ) ../Kernel.php:187
That is all what I am getting as error report.
What could be going wrong?
edit:
Here is a part my config.yml;
framework:
#esi: ~
translator: { fallback: en }
secret: %secret%
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
default_locale: %locale%
session: ~
edit 2:
After configuring config.yml;
Warning: filemtime(): stat failed for /var/www/sources/piccolo-standard/app/config/config.yml in /var/www/sources/piccolo-standard/vendor/symfony/symfony/src/Symfony/Component/Config/Resource/FileResource.php on line 68
Fatal error: Uncaught exception 'Doctrine\ODM\PHPCR\Translation\MissingTranslationException' with message 'The locale 'en' is not present in the list of available locales' in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Doctrine\ODM\PHPCR\Translation\MissingTranslationException: The locale 'en' is not present in the list of available locales in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Edit 3: Solution
The problem was a combining of two issues. The first one was the config.yml. Make sure that the 'doctrine_phpcr.odm.locales' section is set as followed (or something a like, considering what languages you support):
locales:
en: [de, fr]
de: [en, fr]
fr: [en, de]
And the second problem was the absence of database connection configured in 'parameters.yml'. Without connection to my database, the server most likely tried to load an English object (perhaps a DateTime) and failed to load.
This is may be stupid, but have you tried to quote your language value ?
like this :
Translator : { fallback : 'en' }
in all of our symfony project we use the locale variable instead of an hard value
Translator : { fallback : "%locale%" }
according to this source code :
https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php
the language definition should be quoted ( line 37 )
/**
* locale fallback list indexed by source locale
*
* example:
* array(
* 'en' => array('en', 'de', 'fr'),
* 'fr' => array('fr', 'de', 'en'),
* 'de' => array('de', 'fr', 'en'),
* )
*/
protected $localePreference;
hope that will help you
EDIT : Did you correctly setup you php-cr parameters ?
here is an example from symfony.com
doctrine_phpcr:
odm:
# ...
locales:
en: [de, fr]
de: [en, fr]
fr: [en, de]
locale_fallback: hardcoded
http://symfony.com/doc/current/cmf/bundles/phpcr_odm/multilang.html
I need to do a search like this:
//Project\MyBundle\Repository
$query = $this->getEntityManager()->getRepository('ProjectMyBundle:Product')->createQueryBuilder('p')
->where('MD5(p.id) = :id')
->setParameter('id', $id )
->getQuery()
->getSingleResult();
I get the id on MD5 and have to search for an id on MD5 in the database.
When I do a search, I showed up, gives me the following error:
[Syntax Error] line 0, col 51: Error: Expected known function, got 'MD5'
Indicated that lib:
https://github.com/beberlei/DoctrineExtensions/blob/master/lib/DoctrineExtensions/Query/Mysql/Md5.php
But I've put it inside the folder and now I need to know where it should matter.
I am using MySQL, Doctrine 2.2 in Symfony 2.1.6.
You'll need to register MD5 as a custom DQL function:
# app/config/config.yml
doctrine:
orm:
# ...
entity_managers:
default:
# ...
dql:
string_functions:
MD5: Acme\HelloBundle\DQL\MD5Function
For more info, see: http://symfony.com/doc/2.0/cookbook/doctrine/custom_dql_functions.html