Symfony2.5 softDeleted with mongodb - mongodb

How to make the symfony doctrine extension 'SoftDeleted' works with mongoDb? (doctrine-mongo-odm). The plugin says 'only works for ORM'...And is there any other solutions ?

DoctrineExtensions for ODM currently doesn't support Softdeletable.
List of extensions which support ODM
Translatable
Sluggable
Timestampable
Blameable
Loggable
Translator
Tree (Materialized Path strategy for now)
References
Sortable
See the documentation on Github for more informations.
Edit: scratch that. Just found this https://github.com/Atlantic18/DoctrineExtensions/pull/877
Edit 2: https://github.com/Atlantic18/DoctrineExtensions/blob/master/lib/Gedmo/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php
It seems to work like the normal ORM annotation. To set it up with symfony just follow the usual documentation (not the one on that Repo).
Config:
doctrine_mongodb:
...
document_managers:
default:
[.....]
filters:
soft-deleteable:
class: Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter
enabled: true
Edit 3 Updated the code above again, because I'm stupid

Related

The annotation "#ODM\Document" in class ... was never imported

Annotation doesn't work any more after upgrading php7.4 to 8.1.
I upgrade a php7.4 project to php8.1.9, then annotations don't work:
The annotation "#ODM\Document" in class ... was never imported.
Some examples of annotations are:
use Zend\Form\Annotation;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* #ODM\Document
* #Annotation\Name("client")
* #Annotation\Attributes({"novalidate": "true"})
*/
I have checked the above two classes exist under vendor/.
I have also run composer dumpautoload.
There also exist AnnotationDriver of Doctrine:
vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php;
vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php
In addition, the version of their packages are not changed.
My questions:
Firstly what's the most effective way to make the system work or identify problems ?
I'm considering, do I have to replace all the annotations to PHP8 attributes ? But this doesn't look necessary or practical. There're huge amount of annotations. Even if I can replace those annotations of my project, the vendor packages still use annotations and definitely I can't change them.
Just wondering, which version of Doctrine Mongodb ODM support PHP8 attributes ?
Just guessing, is it because PHP8 makes the current Zend framework 2 and Doctrine ODM broken and thus causing annotation not work any more? If so, how to fix?
The related packages are as the following:
"zendframework/zendframework" : "2.3.10"
"doctrine/annotations" : "1.2.8",
"doctrine/mongodb": "1.2.2" (There's no version for PHP8, so I have to install it as github VCS package )
"mongodb/mongodb" : "^1.0.1",
"doctrine/mongodb-odm" : "1.0.0-BETA14",
"doctrine/doctrine-mongo-odm-module" : "0.8.0",
"doctrine/annotations" : "1.2.8",
"doctrine/common": "2.4.4",
"doctrine/doctrine-module": "0.8.2",
If you need further resources, please let me know. Thanks!

Can't use filter with dynamic linq

I tried to use ef plus for filtering data with following code
_context.Filter<TEntity>(x => x.Where(q => "q.Property == 1"));
And got an error.
Am i doing something wrong?
Disclaimer: I'm the owner of the project Entity Framework Plus
Disclaimer: I'm the owner of the project Eval-Expression.NET
As specified in the introduction: http://entityframework-plus.net/linq-dynamic, LINQ Dynamic require the library Eval-Expression.NET (paid library) to work.
It should now work once you add this library in reference: https://www.nuget.org/packages/Z.Expressions.Eval/

Moped::Errors::OperationFailure when creating an embedded object

I'm using mongoid 3.1.4 altogether with moped 1.5.1, mongodb 2.4.1, and ruby 1.9.3.
I have next models:
class Practice
include Mongoid::Document
embeds_many :distresses
end
class Distress
include Mongoid::Document
embedded_in :practice
end
When I do something like this it seems to be working:
practice = Practice.create
practice.distresses.create
But when I place safe: true in my config file and I do the same, then I get:
Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
#length=82
#request_id=22
#response_to=0
#op_code=2004
#flags=[]
#full_collection_name="collection.$cmd"
#skip=0
#limit=-1
#selector={:getlasterror=>1, :safe=>true}
#fields=nil>
And actually, I got the error when creating the distress in any way. This also throws the exception:
practice = Practice.create
distress = practice.distresses.build
distress.save
When I check with practice.distresses.count I can see that distresses where created successfully in the database, however I get the exception mentioned above.
Ok, after some days I was able to fix this problem.
In my Distress model I had a before_create callback that was trying to update a field on the Practice parent object. Somehow this makes Moped to create a wrong request that makes MongoDB to fail.
I changed before_create callback for after_create and everything is working now.
Hope this helps somebody else.

How to Log in SailsJS

What is the actual syntax to log in SailsJS?
Docs don't have anything, but found the following line in the site's roadmap
"Pull out Sails.log (winston wrapper) as a separate module so it can
be used by waterline"
I image it's something like:
Sails.log(...)
Sails.error(...)
Sails.warn(...)
In your controllers, models, services, and anywhere else that the sails global is available, you can log with one of:
sails.log();
sails.log.warn();
sails.log.info();
sails.log.debug();
sails.log.error();
sails.log.verbose();
sails.log.silly();
The logging level (that is, the level at which logs will be output to the console) is set in /config/log.js.
To extend on the Scott Answer, dont forget to add the filePath: property to log.js file... otherwise it will not work :)
So it should be something like:
log: {
level: 'info',
maxSize: 1000,
filePath: 'c://serverlogs/mylogfilename.log'
Answer is changed based on Joseph question.

Symfony2: problems rendering the translation-form with A2lixTranslationFormBundle and Gedmo\DoctrineExtensions Translatable

I'm using gedmo/doctrine-translations and a2lix/translation-form-bundle: 2.*#dev to translate my entities.
The translation form always renders a Field and Content but my entity itself doesn't contain a Field or Content field.
The form type
$builder->add('translations', 'a2lix_translations');
The 2.0 version of the TranslationFormBundle
isn't compatible with the current gedmo/doctrine-extensions version.
See the bundle's upgrade notes.
You'll need to use the currently unstable branches wip-v2.4.0 and .
solution:
Either update gedmo/doctrine-extensions ...
composer require gedmo/doctrine-extensions:wip-v2.4.0#dev
composer update gedmo/doctrine-extensions
... or downgrade your a2lix/translation-form-bundle version:
composer require a2lix/translation-form-bundle:~1.2
composer update a2lix/translation-form-bundle
important notice for the 1.x version of a2lix/TranslationFormBundle:
You need to use the a2lix_translations_gedmo field-type as described in the documentation.
Further you need to specify the translatable class in the options-array like this:
$builder->add('translations', 'a2lix_translations_gedmo', array(
'translatable_class' => "Your\Entity"
);