Archive for category drupal

Custom sql queries in Views

I came across this when i was looking for a way to use my own sqly queries in combination with views.
Sometimes you can’t always get the things you want by using views (or you’re too lazy to fiddle around with arguments, relationships, etc.)

The idea is simple :

1) test your own custom query in phpmyadmin for example.

2) create a view and save it. You don’t have to set any filters since the SQL will be overwritten.

2) if you haven’t created your own module yet, create one now and place the following code in it.  replace MYMODULE by the name of your own module and VIEW_NAME by the name of the view you’ve just created. Then, change the sql query you see here by your own.

function MYMODULE _views_pre_execute(&$view) {

//drupal_set_message(’—->>>’.$view->name);
if($view->name==”VIEW_NAME”) {

$view->build_info['query']=”SELECT vidnode.nid as nid, vidnode.title as title
FROM node vidnode WHERE vidnode.type=’ptl_remotevideo’
AND vidnode.status <> 0
AND vidnode.nid NOT IN (
SELECT DISTINCT media.field_media_video_ref_nid as video_nid
FROM content_field_media_video_ref media
)”;

}

}

That’s it. I used a node view and it gave me what i wanted. I didn’t have time to check out other settings but i guess it shouldn’t be too hard.

, ,

1 Comment

Admin section won’t load properly

Problem

A problem that a lot of people seem to encounter when working with Drupal and especially after a new installation,  is the fact that the admin section loads very slow or sometimes not at all. This is due to the fact that Drupal by default is configured to automatically check for updates. Often this is blocked however causing Drupal to keep trying.

Solution

You could solve this by disabling the Update module in the Modules section but sometimes it’s impossible to get to that page due to the problem.
A second option is to disable it manually by going to the ’system’ table in your Drupal MySQL database, explore the table and look for the ”modules/update/update.module’ entry.
Once you have found it, edit the status field of the module to 0 (should have been 1).  Your problem is most likely fixed now.

Some pointers:

  • Drupal needs at least 16MB to run properly - if you feel your local configuration is running very slow, verify your apache settings and change the memory limit to a higher number (like 64M)
  • Importing sql.zips can sometimes fail, in this case you could try adjusting the maximum allowed packet size in your mysql settings.
    ==> the best solution however is to export all your tables except the ‘watchdog’ table and every table with ‘cache’ in it’s tablename as these are the ones to take up most of the volume.

No Comments