Symfony Cache TagAwareAdapter problem with saving and then getting cacheItem - symfony

Symfony's FilesystemTagAwareAdapter() lets me get, assign a value to, and save a cacheItem, and then retrieve the saved item with another get. But if I also tag the new item before saving, I cannot retrieve the saved item with another get.
when I run the following:
$this->cache = new \Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter();
$thingItem = $this->cache->getItem('thing');
$thingItem->set('thingValue');
// $thingItem->tag('msc');
$this->cache->save($thingItem);
$retrieved = $this->cache->getItem('thing')->get();
The value of $retrieved is "thingValue".
If I uncomment the "$thingItem->tag('msc');" line and run the code again, the value of $retrieved is null.
I would expect the value of "$retrieved" to be "thingValue" in both cases.
Can anyone explain the inconsistent behavior?
Edit:
This is on php 8.1 and windows 10.
The inconsistent behavior occurs in a phpunit TestCase test in a Symfony project I am working on.
I find that the inconsistent behavior does not occur in a function test using Symfony's KernetTestCase with $this->cache = static::getContainer()->get('cache.app.taggable');

Solved!
It appears that the cache.app.taggable that symfony creates in a Windows environment is not a FilesystemTagAwareAdapter. It is a TagAwareAdapter wrapped around a TraceableAdapter wrapped around a FilesystemAdapter().
So if I create my cache this way:
$this->cache = new TagAwareAdapter(new TraceableAdapter(new FilesystemAdapter());
The code works as expected in a phpunit test!

Related

Why creating model in any other location than client, meteor runtime throws exception?

I am a meteor newbie. I am trying out by building a simple app and it does nothing but shows list of items. I first tried out with hard coded model values in my client javascript code and it worked just fine. I then created a folder called 'model' under root of the application and created the model there like the following
Favorites = new Meteor.collection("favorites")
with this change, meteor throws exception pointing to this line of the file on load. If I move this code to client the code works ofcourse that is wrong. The full code is # https://github.com/ksunair/13favs It is a very simple solution has few files and less than 20 or 30 lines altogether. My client code is,
Template.favorites_main.helper({
favorites:Favorites
});
I did the following in order to clear your app of errors:
Favorites = new Meteor.Collection("favorites"); (Collection starts with a capital C)
I moved model/mainmodel.js to lib/mainmodel.js so Favorites would be available as soon as the template rendered. I always put my models under lib (or in a subdirectory) so they will be loaded first. This contradicts what I see in other places including discover meteor, so I'm unclear what the best practice is. In any case, it fixed the problem.
$ meteor add accounts-ui was needed because you referenced Accounts.ui.config.
You need to actually do a find in your favorites_main template. So it should look something like:
Template.favorites_main.helpers({
favorites: Favorites.find();
});

Websphere & Tivoli: NPE while trying to create PDAuthorizationContext

I am getting the following error when I try to start my Application...
[java.lang.IllegalStateException: java.lang.NullPointerException^M
at com.tivoli.pd.jutil.kb$1.run(kb$1.java:41)^M
at java.security.AccessController.doPrivileged(AccessController.java:229
)^M
at com.tivoli.pd.jutil.kb.c(kb.java:141)^M
at com.tivoli.pd.jutil.kb.(kb.java:56)^M
at com.tivoli.pd.jutil.PDContext.(PDContext.java:76)^M
at com.tivoli.pd.jazn.PDAuthorizationContext.(PDAuthorizationConte
xt.java:66)^M
I double checked the config file was accessible and I could read it. The code I am using looks as follows...
aC = new PDAuthorizationContext(cFile);
Is there a way to get more information on what is causing the NPE?
More information!!!
After debuging a bit, it appears the issue comes from this code (they use progaurd so it is a little hard to be 100% confident)...
Certificate[] arrayOfCertificate1 = ((KeyStore)???).getCertificateChain("DefaultID");
//Throws Null pointer (presumably because array is null)
Certificate localCertificate1 = arrayOfCertificate1[0];
EVEN MORE INFO
This appears to be some kind of dependency conflict (guess), because if I just create a sample App using PDAuthorizationContext it works fine.
Problem was related to the PD.jar version that I was using. Although I thought I was using one version I was using another. This was because on version was registered in my WebSphere library (under build path in eclipse). Once the proper library was introduced everything worked.

Symfony2 passed argument is null

I'm building a CRM system and I faced a weird problem I'm unable to solve. When I try to create a new CustomerCase entity, I want to assign a CaseState entity for it, so this is what I do in the createAction of CustomerCaseController.php:
$caseStateId = $request->request->get('caseState_id');
$caseState = $this->getDoctrine()->getManager()->getRepository('HSWAshaBundle:CaseState')->findOneById($caseStateId);
$entity = new CustomerCase();
$entity->setCaseState($caseState);
...... etc.....
Everything works just fine until the setCaseState method. After running setCaseState, I get the following error:
Catchable Fatal Error: Argument 1 passed to HSW\AshaBundle\Entity\CustomerCase::setCaseState() must be an instance of HSW\AshaBundle\Entity\CaseState, null given, called in /home/webuser/Symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 538 and defined in /home/webuser/Symfony/src/HSW/AshaBundle/Entity/CustomerCase.php line 843
The weird part is that $caseState really is a CaseState object (because for example $caseState->getName() works and gives me the correct name for the selected CaseState). For some mind blowing reason it just turns null when I use the setCaseState method. If I do $entity->setCaseState($customerStateObject->getId()), I get the same error message, but this time null changes to integer.
The CustomerCase has a manyToOne relationship with CaseState.
This works just fine if I use the formBuilder's add() method and skip all this manual work, but since I'm using a very specific auto-populating jQuery dropdown for selecting the CaseState from a nested tree structure, I had to manually add the dropdown and read it with $request->request->get().
I've been fighting with this part for almost three days now and would greatly appreciate every help I can get with this!
Finally I got it to work! The reason was $request was missing some parameters because the twig template was missing form_rest(form). After adding that, everything started to work. Thank you!

How to use GET and POST Arguments in Symfony2

We are transforming PHP Application to Symfony2 Application.
Most of the pages we are completely writing new but some pages we decided to keep it as it is. i.e I want to use the same php without any major change.
In the php page we used GET['prospect_id'], GET['executive_id'] and many other arguments. Both GET and Post methods. When I view the page in Symfony1.4 there is no error or warning.
But when I view in Symfony 2 I am getting undefined index error.
How can I solve the issue?
EDIT: if GET['prospect_id'] is null there is no error in Symfony 1.4 but i'm getting undefined index notice in Symfony2. There are many variables like that. Is it necessary to define variable before use it. How to avoid this notice message.
What i want is if i am using $_GET['xxx']. symfony2 should not show any notice or error. i want to escape from that.
Use (in Symfony2) the controllers request-object, to get those params:
$this->request->get('prospect_id');
$this->request->get('executive_id');
You can also set default values, if there is no value given. Take a look at this documentation.

browseForOpenMultiple - crashing

I am trying to work with browseForOpenMultiple function inside Flex, sdk 3.5, I am trying to figure out a bug. The browseForOpenMultiple does not crash everytime, but it seems as though I can upload a file once, but when I go to upload a second file, it crashes when the browseForOpenMultiple function is called. Anyone have any ideas about possible causes?
Update:
private function browseForFiles():void
{
fileBrowser = new File();
fileBrowser.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
fileBrowser.addEventListener(Event.CANCEL, fileSelectionCancelled);
fileBrowser.browseForOpenMultiple("Select Desired Media File(s)", [(mode == "Media")? MediaTypes.getFileFilter() : MediaTypes.getVideoFilter()]);
}
So the code in our array of file extensions was crashing when there were over 60 items listed in an array that gets converted into a string for the FileFilter. This may not be an Adobe limit, but I wanted to make mention that the crash is fixed, so that others who may be encountering issues with browseForOpenMultiple will know what the issue was for this problem. This is not code that I originally wrote, so I will check into it for more clues, but for the time being, too many array items being joined together into a string for FileFilter object caused the crash.
It could be how it's construct the File, without a real file reference.
Try something like this :
var fileBrowser = File.desktopDirectory

Resources