i_database.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Install database. Provides access to the Database class and allows to add
  4. * hooks for logging, testing, etc during installation.
  5. *
  6. * @license see /license.txt
  7. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  8. */
  9. class iDatabase extends Database
  10. {
  11. private static $is_logging = true;
  12. static function is_logging()
  13. {
  14. return self::$is_logging;
  15. }
  16. static function set_is_logging($value)
  17. {
  18. self::$is_logging = $value;
  19. }
  20. static function select_db($database_name, $connection = null)
  21. {
  22. global $app;
  23. if (self::is_logging()) {
  24. $app['monolog']->addInfo(__FUNCTION__ . ' ' . $database_name);
  25. }
  26. return parent::select_db($database_name, $connection);
  27. }
  28. static function query($query, $connection = null, $file = null, $line = null)
  29. {
  30. global $app;
  31. if (self::is_logging()) {
  32. //$query = str_replace("\n", '', $query);
  33. //$app['monolog']->addInfo(__FUNCTION__ . ' ' . $query);
  34. }
  35. $result = parent::query($query, $connection, $file, $line);
  36. if (empty($result)) {
  37. $backtrace = debug_backtrace(); // Retrieving information about the caller statement.
  38. $caller = isset($backtrace[0]) ? $backtrace[0] : array();
  39. $file = $caller['file'];
  40. $line = $caller['line'];
  41. $message = " sql: $query \n file: $file \n line:$line";
  42. $app['monolog']->addError($message);
  43. }
  44. return $result;
  45. }
  46. }