How to use Translatable from Symfony Console Command - symfony

I'm trying to find documentation for retrieving translated records via translatable (StofDoctrineExtensionsBundle) when executing a console command from Symfony. This command call a service that retrieves data from Doctrine using the
$query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker')
->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $lang);
If I call this service from a URL (a Controller) translatable works fine, but if I run the command from the CLI , Translatable is not fired or fails to force the locale ($lang). Any idea to solve that?

Related

How to call an API platform endpoint from a Symfony command

I have a working API platform endpoint, which supports POST, PATCH & GET. Just for an example, it's a book endpoint:
/api/books
Now, I have a new task of creating a Symfony command, which will have a part where I'll be creating a new Book object and will save it in the database.
I am into the direction of creating a new Service class to normalize the data to Book object, then using EntityManager to persist the data to DB, but since I have a working POST endpoint in API Platform that basically does the same thing, is it possible for me to call that endpoint instead from the Symfony command that I'll be creating?

How to use Doctrine Extensions in Api Platform

I'm using stofDoctrineExtensionsBundle in a Symfony 4 project with Api Platform. I've sluggable and timestampable extensions actives. It works like a charm when I persist the entities manually, ie in the fixtures, but when I persist via the POST collectionOperations, it doesn't work, and said that those fields (slug, createdAt and updatedAt) are required.
I can't find a solution for this after several days.
Thank you very much (this is my first question here).
Those fields should not be required.
The sluggable and timestampable extensions set their values onFlush, a doctrine event that calculates what has changed in your objects and runs the SQL queries to actually update the database. API Platform will make that happen at the WRITE stage, which is AFTER validation so validation will not see those values. Remove any assersions for those fields like #Assert\NotBlank, #Assert\NotNull.
If the fields are not nullable in the configuration of their mapping (for example #ORM\Column()) they will appear as required in the swagger, open api or Hydra documentation generated by API Platform. Some clients, like the admin client and those from the client generator, use this documentation and will therefore make the inputs for those properties required.
Add the following annotations to the doc blocks of those properties:
* #ApiProperty(required=false)
This annotation requires near the top of the file:
use ApiPlatform\Core\Annotation\ApiProperty;

Publish workspace from Author instance to public

I got newly created Magnolia instance. I tried to create an app via bundled groovy script and publish news to public instance. I got this error
It happened because 'ebtnews' workspace is not synchronised from author to private. So the question is how to sync workspace from author to private?
What I do is every time I added a new workspace in the module definition xml for my author instance, I make sure I also added this workspace in the module definition xml for my public instance. Then need to restart both author and public instance for it to create the new workspace.
Alternatively, you can just run following via groovy console/script:
// create workspace
Components.getSingleton(RepositoryManager.class).createWorkspace(app_repository, app_workspace)
// check we registered all right
appSession = ctx.getJCRSession(app_workspace)
// register node type
nodeTypeManager = appSession.getWorkspace().getNodeTypeManager()
type = NodeTypeTemplateUtil.createSimpleNodeType(nodeTypeManager, app_node_type, Arrays.asList(NodeType.NT_HIERARCHY_NODE, NodeType.MIX_REFERENCEABLE, NodeTypes.Created.NAME, NodeTypes.Activatable.NAME, NodeTypes.LastModified.NAME, NodeTypes.Renderable.NAME))
nodeTypeManager.registerNodeType(type, true)
appSession.save()
// double check it registered all right
nodeTypeManager.getNodeType(app_node_type)
You will also want to register basic security rights for the workspace, set it under subscriber workspace mapping to enable activation and possibly include/exclude it from list of triggers for flushing cache upon update of content on public instance.
You can find code to do all that in createAppScript sample script in groovy module. Code I've pasted above is actually from the same script.
Advantage being that you can do all that at runtime w/o restart. Disadvantage, that you need to run same code on each instance.

Usergrid: Accessing a resource in Usergrid

I am running usergrid on my local, I am trying to access an entity I just created, however I seem to having issues inspite of confirming to what is specified in the documentation:
The entity I created is: /summaries/915b986a-78cf-11e4-aa04-eb4bd0e81071
it is preceeded by my API name , which in turn is preceeded by my org name, so it gives me:
http://localhost:3000/test-org/test-api/summaries/915b986a-78cf-11e4-aa04-eb4bd0e81071
I am not able to reach the entity with the above is there anything I am missing?
-S

Create sfContext in symfony task without unnecessary things

I use symfony 1.4. And I use task for email reporting, before retrieving sfMailer i create sfContext instance, but during creation symfony output this lines to the console:
>> sfPatternRouting Connect sfRequestRoute "sf_captchagd" (/captcha)
>> sfPatternRouting Match route "homepage" (/) for / with parameters array ( 'module' => 'main', 'action' => 'index',)
As you can see, sfContext create routing stuff and probably other unnecessary things - i need just two things: partial templates and sfMailer instance thats all.
Here is the lines when i create sfContext instance:
sfContext::createInstance($this->configuration);
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
The easiest way is to create a new evironment in your factories.yml and settings.yml with only the things you need. It doesn't need to have a php script in the web directory, only a definition in the factories.yml and settings.yml same as dev and test and stage environments. And when you load the context configuration use that environment. In your own mailer environment you can disable routing, cache, and other parts of the framework.

Resources