Saturday, November 14, 2009

Drupal upload path

To get where is the default path to upload file of the site:
file_directory_path()
example return: sites/xyz.com/files

Reference:
http://api.drupal.org/api/group/file/6

Other interesting discussion here:
http://groups.drupal.org/node/13420

Monday, November 9, 2009

drupal admin mysql has gone away!

Its such a hectic day.
I tried to clear the cache and i'm getting bunch of errors from mysql has gone away!
It turn out to be some very long query to update cache_update table and caused it to started to lost connection to db.. arg! I added a static variable to count the # of queries to database,, wow! 250+ queries! the front page itself about 110+queries!....

my here is my quick fix to the problem:
edit: drupal/includes/database.mysql.inc
function: _db_query
line #111, before mysql_query line.
(updated 10th nov: if ping is placed after mysql_query, db_effected_rows will always return -1, which causes lots of other issues)

//****BEGIN ATTEMPT TO RECONNECT ON ERROR
try {
if (! mysql_ping($active_db))
{
throw new Exception("db closed!");
}
}
catch (Exception $e)
{
//attempt to reconnect
global $db_url;
$urlname = "default";
if (is_array($db_url)) {
$connect_url = array_key_exists($urlname, $db_url) ? $db_url[$urlname] : $db_url['default'];
}
else {
$connect_url = $db_url;
}

$active_db = db_connect($connect_url);
}
//****END ATTEMPT TO RECONNECT ON ERROR


And these are my modules i've installed, while some are my custom modules:
/var/www/mydrupal/sites/all/modules/advanced_help
/var/www/mydrupal/sites/all/modules/aes
/var/www/mydrupal/sites/all/modules/apisetting
/var/www/mydrupal/sites/all/modules/apisettinglist
/var/www/mydrupal/sites/all/modules/apiutils
/var/www/mydrupal/sites/all/modules/backup_migrate
/var/www/mydrupal/sites/all/modules/birthdays
/var/www/mydrupal/sites/all/modules/calendar
/var/www/mydrupal/sites/all/modules/captcha
/var/www/mydrupal/sites/all/modules/casetracker
/var/www/mydrupal/sites/all/modules/cck
/var/www/mydrupal/sites/all/modules/computed_field
/var/www/mydrupal/sites/all/modules/content_access
/var/www/mydrupal/sites/all/modules/crm_account
/var/www/mydrupal/sites/all/modules/customcasetracker
/var/www/mydrupal/sites/all/modules/customintranet
/var/www/mydrupal/sites/all/modules/date
/var/www/mydrupal/sites/all/modules/filefield
/var/www/mydrupal/sites/all/modules/flexifilter
/var/www/mydrupal/sites/all/modules/hellomodule
/var/www/mydrupal/sites/all/modules/i18n
/var/www/mydrupal/sites/all/modules/imageapi
/var/www/mydrupal/sites/all/modules/imagecache
/var/www/mydrupal/sites/all/modules/imagefield
/var/www/mydrupal/sites/all/modules/imce
/var/www/mydrupal/sites/all/modules/imce_wysiwyg
/var/www/mydrupal/sites/all/modules/jquery_dataTables
/var/www/mydrupal/sites/all/modules/languageicons
/var/www/mydrupal/sites/all/modules/mail_api
/var/www/mydrupal/sites/all/modules/messaging
/var/www/mydrupal/sites/all/modules/mimedetect
/var/www/mydrupal/sites/all/modules/mimemail
/var/www/mydrupal/sites/all/modules/node_gallery
/var/www/mydrupal/sites/all/modules/node_privacy_byrole
/var/www/mydrupal/sites/all/modules/notifications
/var/www/mydrupal/sites/all/modules/notify
/var/www/mydrupal/sites/all/modules/og
/var/www/mydrupal/sites/all/modules/pear
/var/www/mydrupal/sites/all/modules/print
/var/www/mydrupal/sites/all/modules/rdf
/var/www/mydrupal/sites/all/modules/realname
/var/www/mydrupal/sites/all/modules/schema
/var/www/mydrupal/sites/all/modules/simplemenu
/var/www/mydrupal/sites/all/modules/simplenews
/var/www/mydrupal/sites/all/modules/subscriptions
/var/www/mydrupal/sites/all/modules/swftools
/var/www/mydrupal/sites/all/modules/thickbox
/var/www/mydrupal/sites/all/modules/token
/var/www/mydrupal/sites/all/modules/translation_overview
/var/www/mydrupal/sites/all/modules/transliteration
/var/www/mydrupal/sites/all/modules/ubercart
/var/www/mydrupal/sites/all/modules/video
/var/www/mydrupal/sites/all/modules/views
/var/www/mydrupal/sites/all/modules/views_customfield
/var/www/mydrupal/sites/all/modules/wysiwyg

Tuesday, October 20, 2009

apache web based monitoring

Ever wonder what is happening on your apache web server?
There are times when we found dead processes which doesnt seems to die off.
And it keeps accumulating and somehow reach its peak memory and dies off the server.
And you were spending many days of sleepless night trying to standby to restart the apache webserver every time it reaches its peak

Here is a solution:
Enable apache mod_status:
sudo a2enmod status
edit status.conf, and replace server-status with your secret url
sudo vi /etc/apache2/mods-available/status.conf

location server-status

restart apache:

apachectl restart

access your browser:

http://www.youdomain.com/server-status or yoursecreturl

Sunday, October 18, 2009

drupal custom url / menu permission

Took me some time to figure this out.
If you ever one to have a url which is accessible by anyone,
you may either make a function to return true,
or you may set 'access callback' => '1'...

If it doesn't work, try go to administration > performance > resetting the cache.
The cache is always there, even with cache is off.

drupal access stages

Drupal is built with permission sets in mind.
User may have 1 or more roles.
Content may be limited based on content type, or up to single node level (1record).

When a user is viewing a node / page,
user will have to pass through access "access content".

Next, node may be limited based on content type in:
hook_access

The type of access names can be declared in:
hook_perm


To overwrite permission, you may edit hook_access within the same node module,
or use hook_nodeapi

stages:
  • check for "access content"
  • trigger nodeapi.op = "load"
  • check for hook_access
  • running "hook_view"
  • trigger nodeapi.op = "view"
  • ...
Please advice me if I've missed out or made any mistake here.

Saturday, October 10, 2009

Open Source Rocks!

Who say open source isn't powerful for desktop?
It is enough for us to design this card :)
Tools: Gimp & Inkscape.
Purpose: To create awareness of skin disorder alternative cure

Thursday, October 8, 2009

Drupal Logging

Since drupal 6, they have replaced watchdog logging with dblog.
We are open sourcing one of our library for you to easily log onto the database log "watchdog" table.



/*
* log to database
* @param string category
* @param string sLog
* @param string sType
* WATCHDOG_EMERG => t('emergency'),
WATCHDOG_ALERT => t('alert'),
WATCHDOG_CRITICAL => t('critical'),
WATCHDOG_ERROR => t('error'),
WATCHDOG_WARNING => t('warning'),
WATCHDOG_NOTICE => t('notice'),
WATCHDOG_INFO => t('info'),
WATCHDOG_DEBUG => t('debug'),
* @param array variables
*/
function logger_log($sCategory, $sLog, $sType="info", $aVars=array())
{
switch ($sType)
{
case "emergency":
$iType = WATCHDOG_EMERG;
break;
case "alert":
$iType = WATCHDOG_ALERT;
break;
case "critical":
$iType = WATCHDOG_CRITICAL;
break;
case "error":
case "err":
$iType = WATCHDOG_ERROR;
break;
case "warning":
case "warn":
$iType = WATCHDOG_WARNING;
break;
case "note":
case "notice":
$iType = WATCHDOG_NOTICE;
break;
case "info":
$iType = WATCHDOG_INFO;
break;
case "debug":
$iType = WATCHDOG_DEBUG;
break;
default:
$iType = 999;//unknown
}

$aLog = array(
"user" => $GLOBALS["user"],
"type" => $sCategory,
"message" => $sLog,
"variables" => $aVars,
"severity" => $iType,
"request_uri" => $_SERVER["REQUEST_URI"],
"referer" => $_SERVER["HTTP_REFERER"],
"ip" => $_SERVER["REMOTE_ADDR"],
"timestamp" => time()
);

dblog_watchdog($aLog);
}