ContainerAware and Session - serialization

I'm using a custom class that extends ContainerAware, and I need to serialize it to store it in the session.
I'm using __sleep and __wakeup to select what properties of my object needs to persist in session, and of course I'm not storing the $this->container in the session.
So my problem is : when I use __wakeup , I don't have access to my container anymore! Is there a way I can handle this?

Well, yeah that would be the expected outcome. If You have your class registered as service im not sure it that would be possible, because on __wakeup you woudl have to execute setContainer with correct container argument.

Related

CKAN: Get user object or id when a context object is not available in extension

When writing a CKAN extension, I can create a custom GET-able method, which automatically receives the context.
e.g.
#side_effect_free
def custom_method(context, data_dict):
# Do something with the context and/or data_dict
The context argument above, which is basically injected by CKAN, contains, among other things, the user object which can be used to identify the user.
In other cases, like for example in a template helper, how can I get access to the user information? Ideally, I would like to have a context object just as above, so that I can call for example package_search and the rest of the actions provided in the toolkit.
Turns out that when calling actions, skipping the context variable will cause ckan to add it later inside the call, so there's no need to provide the context yourself. Also, if you want information on the user, the g variable from Flask has everything you need.

Update Running workflow with dynamicUpdateMap

I have a workflow running and i'm trying to update it dynamically. It is a Flowchart and i'm trying to change the Next property of a FlowStep.
The problem is that when loading WorkflowApplication.Load(workflowApplicationInstance, map); the instance with the map, i got the error:
In order for an implementation map to be directly applied to a workflow instance, the root of the definition must not have any public/imported children or public/imported delegates.
i tried saving the map to file and to database, because i saw in other examples, the map is saved with extension file.map not file.xaml of file.xml. Anyway it was useless, it's still not loading.
Solved that. The problem was when calling PrepareForUpdate and CreateUpdateMap methods, from their API, i was calling them with ActivityBuilder parameter and it should have been Activity. So having the ActivityBuilder of a workflow you can obtain the activity of it like this:
ActivityBuilder workflowDefinition;
Activity flowcharWorkflow = workflowDefinition.Implementation as Flowchart();
if your workflow definition has a root of flowchart.

Changing Mule Flow Threading Profile at runtime

I have a requirement in hand where I need to change the Mule Flow Threading Behavior at runtime without the need of bouncing the whole Mule Container. I figured out few different ways to achieve this, but none of them are working.
I tried accessing the Mule Context Registry and from there I was trying to do a lookup of "FlowConstructLifecycleManager" Object so that I can tap in there and access the threading profile of the object and reset those values, then stop and start the flow programmatically in order to get the change applied in the flow. I am stuck in this approach as I was unable to get hold of the FlowConstructLifecycleManager Object neither from the Mule Spring Registry nor from the Transient Registry. I was able to get hold of the Flow object though which has a direct reference to that FlowConstructLifecycleManager Object. But, unfortunately, they made this object as protected and didn't expose any method for us to access this object.
Since I was unable to access this FlowConstructLifecycleManager directly from Mule implemented Flow class, I decided to extend this Flow class and just add another public method to it so that I can access FlowConstructLifecycleManager object from Flow object programmatically. But, I am stuck in this approach as well as even if I am putting my version of the same Flow class packaged and dropped in lib/user folder of the container, it is still not picking up my version of the class, and loading the original version instead.
It would be of great help if I can get any pointer on the approach of solving either my first or second problem.
Thanks in advance,
Ananya
In our company, we are building a dashboard from where we should be able to start/stop any flow or change the processing power of any flow by increasing/ decreasing the active threads for a flow or changing the pollen polling frequency. All of these should be done at runtime without any server downtime.
Anyway, I made it working finally. I had to patch up the mule-core jar and expose few objects so that I can get to the thread profile object and tweak the values at runtime and stop/ start the flow to reflect the changes to take effect. I know this is little bit messy and but it works.
Thanks,
Ananya

Permanently disable saving of a model in Yii

Is it possible to create an AR model in yii in such a way as to disable the save() function? I am using the models to display data that is entered into the DB from another source and will never need to update it.
UPDATE:
So which methods do I override, which methods in the base class actually write something to DB?
Simply override save and have it throw an appropriate exception. For example:
public function save(bool $runValidation=true, array $attributes=NULL)
{
throw new \LogicException("This kind of model does not support saving.");
}
This way it's also clear to anyone that mistakenly calls the method what is going on.
Don't forget to also override saveAttributes since the two methods are unfortunately completely independent.

Symfony 2 extending DefaultAuthenticationSuccessHandler

I'm trying to count failed and successful logins for my users. For that, I simply want to increase the respective counter in the datebase whenever an authentication attempt succeeds or fails. But I want to keep the default behavior without reinventing it.
So I followed this post: Symfony2 hold behavior when extending DefaultAuthenticationSuccessHandler
But apparently I cannot add any parameters to the constructor of my subclass of DefaultAuthenticationSuccessHandler or Symfony complains that the argument types are wrong.
How can I inject my user management service as a constructor parameter??
EDIT: Actually, the problem seems to be a little bit different! I have the following line in my services.yml:
services:
security.authentication.success_handler:
class: %security.authentication.success_handler.class%
arguments: [#my_stuff.my_user_management_service, #security.http_utils, {}]
But the second argument passed to the constructor is an array containing the options like "login_path". But it's supposed to be an instance of HttpUtils. I'm confused...
I figured it out by myself: the order of the parameters is important. I had to move my_stuff.my_user_management_service to the end of the parameter array like so:
arguments: [#security.http_utils, {}, #my_stuff.my_user_management_service]
I don't really understand why, though. There is something wrong with the parameter injection. Maybe someone has some insight??