MySQL INSERT INTO ON DUPLICATE KEY UPDATE , regarding update triggers

This is to share some insight on the subject of mysql triggers in connection with INSERT INTO ON DUPLICATE KEY UPDATE statement.

When you execute an SQL UPDATE query, the update triggers are fired regardless of whether you changed a value or not in a specific row.
e.g.

UPDATE myTable SET myColumn='test' WHERE id=100;

The above query will fire the update trigger (before or after) even if ‘myColumn’ already has the value ‘test’ for row with id=100

This is not the case with INSERT INTO ON DUPLICATE KEY UPDATE query.

e.g.

INSERT INTO myTable (`id`, `myColumn`) VALUES (100, 'test') ON DUPLICATE KEY UPDATE myColumn='test';

The above query will not fire any UPDATE trigger if there is already a row with id=100 and ‘myColumn’ already has value ‘test’ !!!

Cheers.

IE11 and expression evaluation regarding Boolean

It seems that a lot of stuff changes with IE11. Some legacy code stopped working out the blue.
After some debugging it seems that some expressions that have been evaluating to true, now are being evaluated to false.

e.g.

if(document.ActiveXObject) //document.ActiveXObject is a valid function in IE 11
    alert("YES!!!");  //this never gets called in IE 11

Boolean(document.ActiveXObject) gets evaluated to true in IE 10 but in IE 11 is evaluated to false, while it is still a valid function.

Whatever, just thought this might help someone.

Cheers.

Google Analytics for WordPress – multisite not sufficient permissions solution

It is one of those times that you relive all that has passed.

I came across my own solution i had shared with the community back then, more than 2 years ago.
http://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-problem-and-solution-with-multisite-network-enabled-site

Time flies and time mosquitoes.

The solution is you need to edit the file wp-content/plugins/google-analytics-for-wordpress/admin/yst_plugin_tools.php at line 16

and replace the line

var $accesslvl = 'edit_users';

with

var $accesslvl = 'activate_plugins';

Cheers

jQuery UI selectable, how to programmatically select option

If you need to programmatically select an option, using events, so that your callbacks are called then you can do the following:
Suppose we have a ul element with id mySelectUlID, and i want to add an extra element to the end of it and also select it.

This is done like this:

    $('#mySelectUlID.ui-selected').addClass('ui-unselecting').removeClass('ui-selected');
    $('#mySelectUlID').append('<li class="ui-widget-content ui-selectee ui-selecting">another</li>');

    $('#mySelectUlID').selectable("refresh");

    $('#mySelectUlID').data("ui-selectable")._mouseStop(null);

The code is valid for the latest jQuery 1.10 and is self explaining i believe.

Cheers.

Jquery Tools library problem with modal overlay not appearing … a solution

So i was using the library of jquery tools recently and wanted to use the modal box with the nice overlay in the background.

I did all that was suggested yet the overlay didn’t appear. The solution was simple. I had downloaded a custom version of the jquery tools library and in an effort to save some bytes didn’t include a crucial part of the library named Expose.

The overlay is based on the ‘Expose’ part of the library. If you take a carefull look a the modal box documentation it is mentioned: ‘This feature can be achieved with the Expose tool which is tightly integrated with this overlay tool.

If you want a custom version of jquery tools, don’t forget to click on Expose.

That’s all for now.

Cheers.

Problem with Varnish(2.1). Drupal’s pages aren’t cached by varnish.

I had a problem with varnish, trying to boost a drupal site by caching it. I noticed that while js, css and image files were getting cached, no other page could be cached by varnish and on each request the apache was asked to fetch the page.

That was not acceptable since the site isn’t updated really often. I found out that the reason why varnish didn’t cache is drupal’s (v7) file:
/var/www/drupal/includes/bootstrap.inc , line 1283

  'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT',

I didn’t want to just comment it out in the file, since a lot more problems could be faced regarding drupal and varnish and caching and updating drupal core later on etc.

A solution was to add the following lines in the varnish config file vcl_fetch :

if(beresp.http.Content-Type ~ "text/html") {
        set beresp.ttl = 1d;
    }

So now all pages are cached for 1 day and then the cache gets updated again when someone requests a page.

Cheers.

PS 1: I followed the instructions at https://drupal.org/node/1054886 and the documentation of varnish.
PS 2: A nice command to check if any page is requested from apache and is not in varnish cache is this:

varnishtop -b -i txurl

IE9 DOMParser is missing method selectSingleNode, selectNodes (and possibly others too …), a solution … (XMLSerializer missing methods also)

When you have browsers which have the DOMParser (like chrome, firefox etc.)
you can do the following in javascript:

var dom = (new DOMParser).parseFromString(str, "text/xml");
dom.selectSingleNode(...);
//etc.

In IE9 although DOMParser is available it seems that it lacks some methods, so you get errors like:
Object doesn’t support property or method ‘selectSingleNode’

The solution you can use in javascript level is something like that:

var dom = new ActiveXObject("Microsoft.XMLDOM");
dom.loadXML(str);
dom.selectSingleNode(...);
//etc.

To all of you who are using sarissa.js and you face the same problems then you need a little code tweaking for it to work. I will share what i did and worked for me. I don’t know if some other parts of the library require also fixing…

in sarissa.js at line 474 (file version 0.9.9.5) replace the line:

if(!window.DOMParser){

with:

if(!window.DOMParser || navigator.userAgent.indexOf("MSIE 9")>-1){

PS. In addition the case with XMLSerializer is the same like DOMParser. So in sarissa.js change the line 596 from:

if(!window.XMLSerializer && Sarissa.getDomDocument && Sarissa.getDomDocument("","foo", null).xml){

to:

if((!window.XMLSerializer && Sarissa.getDomDocument && Sarissa.getDomDocument("","foo", null).xml) || navigator.userAgent.indexOf("MSIE 9")>-1){

That’s all for now.
Cheers.