Have you ever experienced that the Bootstrap doesn't save (with flush or without flush - same result) anything in the db?
I'm using the Spring security core plugin, and I'm creating roles and user in the init-method.
My app starts up fine, without errors, but I have nothing in my db...
I have made some changes, I'm running a MySQL-database and might have made some wierd changes that enable this behaviour.
Has anyone experienced this?
Are you certain that your objects pass validation?
I always use
object.save(failOnError: true)
for objects I create in BootStrap.groovy. save will throw an exception if validation fails.
An alternative would be to check that your call to save returns true.
I spent few aggravated hours with same problem after which I realized that I had set
dbCreate = "create-drop"
Make sure you have
dbCreate = "update"
Related
Even if I configure CookieStore with:
MyApp::Application.config.session_store :cookie_store, {
key: '_myapp_session',
cookie_only: false,
httponly: false
}
and I make a POST request with
_myapp_session = #SOME_SESSION_ID
and authenticity_token = #AUTH_TOKEN
and http-header[X-CSRF-Token] set to #AUTH_TOKEN
finally the user is not authenticated, and new session is created with new AUTH_TOKEN and session id.
Can anybody give me some suggestions ?
Unfortunately there is NO SUPPORT for this option in current 4.0 branch. Although this option is forced to TRUE and I didn't find any code in rails sources using this option.
The way to make isolated POST's requests working is to create dedicated middleware, which will add appropriate session cookie. It must be inserted in the apropriate place, because middleware's order is significant.
Because it is very dangerous in CSRF security aspect, we must add to our middleware same verification, which will limit potential risk to minimum.
I've got a CakePHP application and I'm interested in reacting to a user's attempt to upload a file that's too large for the MySQL packet size. I'd like to get the MySQL error and then provide an error message to the user based on that.
It looks like CakePHP uses PDO under the hood, but I'm not sure how to access it. I'd rather borrow CakePHP's PDO connection so that I don't have to create a new PDO connection w/ the username, password, etc, etc (also so I don't have to worry about problems from multiple connections to the same DB, etc).
It looks like there's a PDO class in CakePHP (http://api.cakephp.org/2.2/class-PDO.html), but I'm not sure how to actually get to it in order to invoke the errorCode() method.
This is the method you probably need. In your controller after a save operation you can use $this->SomeModel->getDataSource()->lastError() to get the error.
Or.... check this out:
if( is_a( $this->SomeModel->getDataSource(), "DboSource") ) {
$myPDO = $this->SomeModel->getDataSource()->getConnection();
debug($myPDO.errorCode()); // or whatever...
}
Anyways, thanks a ton for your help with this - there was just a couple too many hops in the documentation for me to find this on my own.
(I'm posting this here instead of as a comment to your answer so that it'll stand out better)
I am developing an AIR application that is supposed to run on desktop and mobile platforms.
For most Facebook functionality, I use the official GraphAPI for Flash, version 1.8.1.
To use the app, the user must login to Facebook, this works easily by first calling FacebookMobile.init(), and if it reports that the user is not logged in, logging in like this:
var webView :StageWebView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
FacebookMobile.login(handleLoginResult, stage, new Array(), webView);
All of this works very well, but logging out does not work as expected. Calling
FacebookMobile.logout(handleLogout);
does log out the user from Facebook, it seems, and handleLogout is always passed a true as first parameter. After this logout, when FacebookMobile.init() is called, it also correctly reports the user as not logged in. So I call the login() method from above again.
Then, the WebView opens, but closes itself immediatly, automatically logging in the user that just logged out, without showing any kind of Facebook login screen. But I want to be able to log in another user, by having to type in email and passwort.
Probably I should mention that the logging out happens when the application starts. The user can't log out himself, the application does so when starting, so that the user should be forced to login each time. Yes, this has a reason ;)
I'm sure this is some kind of caching problem, but how can I solve it with Flash/AIR?
Bit late but better than nothing right? I have seen this issue before when I was experimenting with the OAUTH api...
Found the potential solution while looking for a separate issue but with regards to caching/cookies...
This post explains what you need to do:
http://cookbooks.adobe.com/post_Cannot_logout_from_Facebook_on_Android_devices-19254.html
Basically its not a very pretty solution, but what it does is you manually delete the folders where the caching is happening.
Hope this helps.
Implementing "reallyLogout" from this answer for a similar issue worked for me:
https://stackoverflow.com/a/8199505/952779
Clear internet explorer cache & cookies, .. and it will log you out from StageWebView facebook login
UPDATE: Change also the app id from the descriptor xml file
I have installed the sfErrorNotifierPlugin. When both options reportErrors/reportPHPErrors reportPHPWarnings/reportWarnings are set to false, everything is ok. But I want to catch PHP exceptions and warnings to receive E-mails, but then all my tasks fail, including clear-cache. After few hours of tests I'm 100% sure that the problem is with set_exception_handler/set_error_handler.
There's a similar question:
sfErrorNotifierPlugin on symfony task but the author there is having problems with a custom task. In my case, even built-in tasks fail.
I haven't used sfErrorNotifierPlugin, but I have run into 'The “default” context does not exist.' messages before. It happens when a call is made to sfContext::getInstance() and the context simply doesn't exist. I've had this happen a lot from within custom tasks. One solution is to add sfContext::createInstance() before the call to sfContext::getInstance(). This will ensure that a context exists.
There's an interesting blog post on 'Why sfContext::getInstance() is bad' that goes into more detail - http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/
Well, the problem could not be solved this way, unfortunately. Using sfErrorNotifierPlugin, I have enabled reporting PHP warning/errors (apart from symfony exceptions) and this resulted in huge problems, e.g. built-in tasks such as clear-cache failed.
The solution I chose was to load the plugin only in non-task mode (project configuration class):
public function setup()
{
$this->enableAllPluginsExcept('sfPropelPlugin');
if ('cli' == php_sapi_name()) $this->disablePlugins('sfErrorNotifierPlugin');
}
WHen a task is executed, everything works normally. When an app is fired from the browser, emails are sent when exception/warning occurs (maybe someone will find it useful).
Arms has explained the problem correctly. But usually context does not exist when executing backend/maintenance tasks on the console. And it is easier if you handle the condition yourself.
Check, if you really need the context?
If you do, what exactly do you need it for?
Sometimes you only want a user to populate a created_by field. You can work around by hard-coding a user ID.
If you want to do something more integrated, create a page (which will have a context) and trigger the task from there.
you can test the existance of the instance before doing something inside a class. Like:
if(sfContext::hasInstance())
$this->microsite_id = sfContext::getInstance()->getUser()->getAttribute('active_microsite');
I've been experiencing the same problem using the plugin sfErrorNotifier.
In my specific case, I noticed a warning was raised:
Warning: ob_start(): function '' not found or invalid function name in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
Notice: ob_start(): failed to create buffer in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
So, checking the file: sfApplicationConfiguration.class.php class, line 155,
I've replaced the ' ' for a null, then the warnings disappears, and also the error!
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : ''); bad
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null); good
It only happens in production, when we update some of the records through browser, the change was not saved. it does not seem to be a cache problem as we verified that the data in mysql was still the old data. However, the controller did get hit and flash message returned as if the change was made successfully.
However, we can make the change manually in rails console or mysql withhout any problem.
Any ideas why this is happening?
btw, we recently reconfigure the site to use SSL, it might have something to do with that.
Is there anything that could've prevented the model from being saved?
One way to ensure that the attributes are set and the model is saved is to use the exception raising version which can help fix problems like this:
def update
#model = Model.find(params[:id])
#model.update_attributes(params[:model])
redirect_to(model_path(#model))
end
This could be improved to a more reliable method:
def update
#model = Model.find(params[:id])
# Use exception-throwing update_attributes!
#model.update_attributes!(params[:model])
redirect_to(model_path(#model))
rescue ActiveRecord::RecordNotFound
render(:partial => 'not_found')
rescue ActiveRecord::RecordInvalid
# Delegate back to edit action, something's invalid
edit
render(:action => 'edit')
end
There are occasions where update_attributes may not successfully save.
If you can perform the same update on the same data with the same methods then that is peculiar.