Drupal investigation

MysqlProfilerStorage.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Profiler;
  11. @trigger_error('The '.__NAMESPACE__.'\MysqlProfilerStorage class is deprecated since Symfony 2.8 and will be removed in 3.0. Use FileProfilerStorage instead.', E_USER_DEPRECATED);
  12. /**
  13. * A ProfilerStorage for Mysql.
  14. *
  15. * @author Jan Schumann <js@schumann-it.com>
  16. *
  17. * @deprecated Deprecated since Symfony 2.8, to be removed in Symfony 3.0.
  18. * Use {@link FileProfilerStorage} instead.
  19. */
  20. class MysqlProfilerStorage extends PdoProfilerStorage
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. protected function initDb()
  26. {
  27. if (null === $this->db) {
  28. if (0 !== strpos($this->dsn, 'mysql')) {
  29. throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Mysql with an invalid dsn "%s". The expected format is "mysql:dbname=database_name;host=host_name".', $this->dsn));
  30. }
  31. if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
  32. throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
  33. }
  34. $db = new \PDO($this->dsn, $this->username, $this->password);
  35. $db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), method VARCHAR(6), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, status_code SMALLINT UNSIGNED, KEY (created_at), KEY (ip), KEY (method), KEY (url), KEY (parent))');
  36. $this->db = $db;
  37. }
  38. return $this->db;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function buildCriteria($ip, $url, $start, $end, $limit, $method)
  44. {
  45. $criteria = array();
  46. $args = array();
  47. if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
  48. $criteria[] = 'ip LIKE :ip';
  49. $args[':ip'] = '%'.$ip.'%';
  50. }
  51. if ($url) {
  52. $criteria[] = 'url LIKE :url';
  53. $args[':url'] = '%'.addcslashes($url, '%_\\').'%';
  54. }
  55. if ($method) {
  56. $criteria[] = 'method = :method';
  57. $args[':method'] = $method;
  58. }
  59. if (!empty($start)) {
  60. $criteria[] = 'time >= :start';
  61. $args[':start'] = $start;
  62. }
  63. if (!empty($end)) {
  64. $criteria[] = 'time <= :end';
  65. $args[':end'] = $end;
  66. }
  67. return array($criteria, $args);
  68. }
  69. }