Hello,

2 issues respectively feature requests:

(1) catch exceptions

I'm using your module with phpids-0.6.4. Accidentally, I've removed the phpids sub-directory in my tmp dir.
A reload of my site as anonymous shows a uncatched exceptions error thrown by phpids-0.6.4 because
of the missing temp dir.

I know, that drupal does not take care of php5 exceptions, but it would be nice to avoid this php error output.
One solution could be a wrapper for the phpids_init() function which catches the exception in a try block
and e.g. forwards the message to the drupal watchdog function:

Index: phpids.module
  2 ===================================================================
  3 --- phpids.module (revision 96)
  4 +++ phpids.module (working copy)
  5 @@ -31,6 +31,25 @@
  6    return $items;
  7  }
  8 
  9 +function phpids_init() {
 10 +   try {
 11 +     _phpids_init();
 12 +   }
 13 +   catch (Exception $e) {
 14 +      if (preg_match('/Temp directory/',$e->getMessage())) {
 15 +        // Workaround to create valid temp dir JG 01/07/2010
 16 +        $tmpdir = file_directory_temp()  . DIRECTORY_SEPARATOR . 'phpids';
 17 +        if (file_check_directory($tmpdir, FILE_CREATE_DIRECTORY)) {
 18 +           variable_set('phpids_tmppath',$tmpdir);
 19 +        }
 20 +      }
 21 +      watchdog('phpids', '[%error]: !message in %file on line %line.',
 22 +         array('%error' => $e->getCode(), '!message' => $e->getMessage(), '%file' => $e->getFile(),
 23 +               '%line' => $e->getLine()), WATCHDOG_ERROR);
 24 +   }
 25 +}
 26 +
 27 +
 28  /**
 29   * Implementation of hook_init().
 30   * $ignore : value depends which action will happen
 31 @@ -38,7 +57,7 @@
 32   *   1 = only log
 33   *   2 = log & actions
 34   */
 35 -function phpids_init() {
 36 +function _phpids_init() {
 37 
 38    if (file_exists(variable_get('phpids_path',realpath(dirname(__FILE__))). '/IDS/Config/Config.ini.php') || file_exists(variable_get('phpids_path',re
 39 

(2) create temp dir

In my opinion, it would be more convenient to create the phpids tmp dir automatically in the drupal default temp path.
This path has to be set and has to be writable by default. The php_ini 'upload_tmp_dir' is sometimes not set for security reasons and
some provider disallow changes at the php_ini file.
The following code creates the phpids sub dir within the drupal temp dir

         $tmpdir = file_directory_temp()  . DIRECTORY_SEPARATOR . 'phpids';
         if (file_check_directory($tmpdir, FILE_CREATE_DIRECTORY)) {
            /* ....variable_set('phpids_tmppath',$tmpdir); */
         }

Thanx Jens

Comments

patrickd’s picture

Status: Active » Fixed

thanks, fixed in 7.x-2.x branch

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.