CodeIgniter Check for Database Connection and if Session Library is Loaded - database

Two questions:
Is there a way in CodeIgniter to check if a library had been loaded? If the session library is loaded, I want to show a user-specific page.
If my database is offline and CodeIgniter is unable to connect, how can I display a custom message to users rather than the default error page?

Don't know if this is best (or even good) practice but I found using something like
if(isset($CI->session)):
//show user specific page
endif;
works for me so far, eg. the last 5 mins since I tried it =). In my case I didn't want the debug message:
Session class already loaded. Second attempt ignored.
polluting my logs, so I used:
if(!isset($CI->session)):
$CI->load->library('session');
endif;
hth..

Found this on Codeigniter
forum:
"If you look in the Loader
library, in the function
_ci_load_class, you’ll see that it checks if that class has already
been loaded, and will only load it
again if its being assigned to a new
variable.
Interestingly enough, if you load
the same class multiple times, the
memory usage does go up though"
So if you call $this->load->library(LIB_NAME) more than once, it will only actually load it once. This is from 2009 and CI has been
updated many times since then so not
sure if it's still true.
I hope your db never goes down. But
if it does $CI->db->conn_id
returns true if it can connect.

Related

SPA DTM analytics pagename issue

I am using Angular SPA with DTM.Using custom event based rules, I am able to get all my data including pageName, v41,v42 as correct. Now inside adobe editor, i am storing pagename to s.pageName and some hard-coded value to s.server. I have verified that all my data is correctly populating using OMNIBUG tool as server,pageName, v41 and v42.
Problem is coming in Omniture reporting, as server and page data are not coming through. Page-name data only showing SPA homepage in all page visits and server also coming as default from s.code and not the one i am passing from s.server. eVar/prop are all coming fine.Even if I do prop40=s.pageName/prop41=s.server, then in omniutre reporting i am seeing correct data populating in prop40/prop41 but not under Page and server. And again I cant use prop40/prop41 for pagename/server as its not a correct way to follow and PAGE-VISITS are ZERO in that case.
Any help how to get data in page/server in omniture for SPA or anything wrong in my implementation? Thanks in advance!!
If you really do see the correct values in Omnibug (or more specifically, network request to Adobe collection server), then the issue is not in the code.
Check against another AA hit debugger. Possible Omnibug is somehow bugging out. There are a ton of alternatives out there. Adobe Experience Cloud Debugger. Observepoint. Charles Proxy. Fiddler. Or just use the browser dev tool network tab (what I usually do as a backup).
Make sure you are looking in the correct report suite. Perhaps your data is being sent to a dev report suite, and you are looking at prod report suite, or visa versa?
Check to see if you have any Processing Rules that are overriding your values.
Contact your Adobe Rep to check if there are any VISTA Rules present for the report suite, that are overriding your values.
If you have verified none of the above is the case, then sorry, but it sounds like the issue must really be in your code, but there is a problem with your QA method (e.g. maybe you are looking at the wrong AA request, or something).
Update:
Based on your comment:
Earlier, i was making s.tl() call, but replacing it with s.t() call
resolved my problem for data was not populating
pageName/server/page-views in Omniture and now it is. But the current
problem is we need PageName on all SPA clicks (can be achieved by
s.t() call ) , but the page-Views are not needed on all clicks. So,
its like link-tracking needed only but with PageName data. I am
struggling not to populate page-views on a s.t() call or vice-versa
how to get PageName populated on s.tl() call. Again, omnibug shows all
requests just fine but the issue comes in reports in omniture
When Adobe processes a hit, it wipes pageName for s.tl calls, as that's how it determines whether to count the request as a page view or not. If you want to see page name even for s.tl calls, the common practice is to dupe the pageName value to a prop or eVar and send in with the s.tl call, and look at that report. In fact, most clients I work with don't even use the native pages report, and instead use the (usually eVar) report.

Load Testing Drupal by JMeter

I want to load test DRUPAL by JMeter, but when I run my test plan (it is about updating cart in drupal commerce) it gives me this error:"The form has become outdated. Copy any unsaved work in the form below and then reload this page."
I think the value of form-token is invalid. I use regular expressin for form-token with this regular expression: name="form_token" value="(.+?)".it still does not update cart
How can I solve this problem?
There could be a lot of different reasons for this, most probably:
Missing HTTP Cookie Manager
Missing or improperly working correlation
The solution is comparing the request, which is being generated by JMeter with the request, coming from the real browser - they need to be identical (apart from dynamic bits like cookies or this form_param).
In JMeter you can use View Results Tree listener to check request and response details, variables and cookie values, etc.
In browser you should have developer tools option which allows inspecting the same

Piwik, Export count of page visits for a specific url

I Make artificial page views with javascript on my website using javascript, because I need to track them later
piwikTracker.trackPageView('/lid/902095/website');
I need to be able to export how many times the above code was executed, i.e. how many times /lid/902095/website was visited, so that I can show some stats on my website, however I'm not sure what my query to the API should be, here is my attempt:
?module=API&method=Actions.getExitPageUrls&idSite=2&period=day&date=today&format=JSON&token_auth=anonymous&segment=pageUrl=#%2Flid%2F902095%2Fwebsite
It returns an error at this time "Error: The report 'VisitsSummary_CoreMetrics' was requested but it is not available at this stage. You may also disable the related plugin to avoid this error."
I don't see a plugin with that name in plugins section, my active plugins are "Actions, Dashbord, DoNotTrack, ExampleAPI, ExamplePlugin, Live, Login, Widgetize"
Not sure if this is the right query to send to the API or not, any help is appreciated.
If you want to track the visits use this api call
?module=API&method=VisitsSummary.getVisits&idSite=2&period=day&date=today&format=json&token_auth=anonymous
by default VisitsSummary plugin is provided
Piwik Web Essentials is a good book for reference.

Redirect (?) issue in CakePHP 1.3: "Failed to load source"

From the /posts/edit-view I'm submitting a form to the action addCategory in my Post controller.
The action does all the work it has to do, and subsequently calls $this->redirect($this->referer());.
At first sight my app works fine, but I encountered some hickups when moving to a production server. Monitoring the calls in Firebug I see that the action acually returns a 302 Found but the 'Response' is Failed to load source for: http://localhost/xps/posts/addCategory.
This happens on both dev en production servers, only on the production server it makes the redirect flow fail. On both servers the controller actions are executed well: category is added.
Removing all the code in the action results in the same failure. Removing the redirect removes the failure, but that's not getting me anywhere.
A second (though maybe irrelevant) irregularity is that the submit method of the form is identified as PUT in Firebug although I explicitly set it to POST in Cake.
I recently switched from CakePHP 1.3.4 to 1.3.6, but reversing does not change the behavior
I use the RequestHandler, Session and Auth components and call parent::beforeFilter() in beforeFilter().
I also found the following thread http://cakephp.1045679.n5.nabble.com/puzzle-over-activity-td1260972.html It suggests to remove $this->Auth->authorize = 'controller'; but I don't have that stated anywhere anyway.
Does anyone have an idea where to look next?
Just a guess, but if you are using Security component, it might cause problems. Also, sometimes when using the ajax and sessions it can cause problems. Maybe if the page requires sessions, you could try it without sessions and see if it works.
Ok, I found it.
The Failed to load source is still there but is not the cause of failure.
In one of my Behaviors I had a space after ?> which messed up the headers, which made me look into the wrong detail.

Making a drupal database call using ajax

I want a link that when you click on it, it will call a simple ajax query which updates a database entry. Normally this would be easy, but because authentication needs to happen before the query is executed, I need to be able to execute the Ajax Query AS THE CURRENTLY LOGGED IN USER. I.e. I need access to the $user variable and I don't want to create a new connection.
Does Drupal have native functions that can do this? Is there something I can use to do this?
You're going to want to create a module to handle this. Then, whatever function you call through the callback will have complete awareness of the logged in user.
Keep in mind that if someone makes a link that goes to your AJAX destination on their website, and can trick people into clicking it (or, for that matter, makes that link the src on an img tag), then weird things can happen to people's data without them meaning to.
I suggest the use of a token and checking that the token submitted as part of the link matches something to do with the user. Check drupal_get_token() for a good way to generate one.
Either create a menu item in a module implementing hook_menu() and specify a callback to a function handling this request - or use the Services module and create a new service module.

Resources