コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $connections = [];
     foreach (Database::getAllConnectionInfo() as $key => $info) {
         $database = Database::getConnection('default', $key);
         $connections[$key] = $database->getLogger()->get('webprofiler');
     }
     $this->data['connections'] = array_keys($connections);
     $data = [];
     foreach ($connections as $key => $queries) {
         foreach ($queries as $query) {
             // Remove caller args.
             unset($query['caller']['args']);
             // Remove query args element if empty.
             if (empty($query['args'])) {
                 unset($query['args']);
             }
             // Save time in milliseconds.
             $query['time'] = $query['time'] * 1000;
             $query['database'] = $key;
             $data[] = $query;
         }
     }
     $querySort = $this->configFactory->get('webprofiler.config')->get('query_sort');
     if ('duration' === $querySort) {
         usort($data, ["Drupal\\webprofiler\\DataCollector\\DatabaseDataCollector", "orderQueryByTime"]);
     }
     $this->data['queries'] = $data;
     $options = $this->database->getConnectionOptions();
     // Remove password for security.
     unset($options['password']);
     $this->data['database'] = $options;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     foreach (Database::getAllConnectionInfo() as $key => $info) {
         Database::startLog('webprofiler', $key);
     }
     return $this->httpKernel->handle($request, $type, $catch);
 }
コード例 #3
0
ファイル: KernelTestBase.php プロジェクト: aWEBoLabs/taxi
 /**
  * @after
  *
  * Additional tear down method to close the connection at the end.
  */
 public function tearDownCloseDatabaseConnection()
 {
     // Destroy the database connection, which for example removes the memory
     // from sqlite in memory.
     foreach (Database::getAllConnectionInfo() as $key => $targets) {
         Database::removeConnection($key);
     }
 }
コード例 #4
0
ファイル: Database.php プロジェクト: jkyto/agolf
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    // Discern between creation and editing of a server, since we don't allow
    // the database to be changed later on.
    if (!$this->configuration['database']) {
      $options = array();
      $key = $target = '';
      foreach (CoreDatabase::getAllConnectionInfo() as $key => $targets) {
        foreach ($targets as $target => $info) {
          $options[$key]["$key:$target"] = "$key » $target";
        }
      }
      if (count($options) > 1 || count(reset($options)) > 1) {
        $form['database'] = array(
          '#type' => 'select',
          '#title' => $this->t('Database'),
          '#description' => $this->t('Select the database key and target to use for storing indexing information in. ' .
              'Cannot be changed after creation.'),
          '#options' => $options,
          '#default_value' => 'default:default',
          '#required' => TRUE,
        );
      }
      else {
        $form['database'] = array(
          '#type' => 'value',
          '#value' => "$key:$target",
        );
      }
    }
    else {
      $form = array(
        'database' => array(
          '#type' => 'value',
          '#title' => $this->t('Database'),
          '#value' => $this->configuration['database'],
        ),
        'database_text' => array(
          '#type' => 'item',
          '#title' => $this->t('Database'),
          '#plain_text' => str_replace(':', ' > ', $this->configuration['database']),
        ),
      );
    }

    $form['min_chars'] = array(
      '#type' => 'select',
      '#title' => $this->t('Minimum word length'),
      '#description' => $this->t('The minimum number of characters a word must consist of to be indexed'),
      '#options' => array_combine(array(1, 2, 3, 4, 5, 6), array(1, 2, 3, 4, 5, 6)),
      '#default_value' => $this->configuration['min_chars'],
    );

    if ($this->getModuleHandler()->moduleExists('search_api_autocomplete')) {
      $form['autocomplete'] = array(
        '#type' => 'details',
        '#title' => $this->t('Autocomplete settings'),
        '#description' => $this->t('These settings allow you to configure how suggestions are computed when autocompletion is used. If you are seeing many inappropriate suggestions you might want to deactivate the corresponding suggestion type. You can also deactivate one method to speed up the generation of suggestions.'),
      );
      $form['autocomplete']['suggest_suffix'] = array(
        '#type' => 'checkbox',
        '#title' => $this->t('Suggest word endings'),
        '#description' => $this->t('Suggest endings for the currently entered word.'),
        '#default_value' => $this->configuration['autocomplete']['suggest_suffix'],
      );
      $form['autocomplete']['suggest_words'] = array(
        '#type' => 'checkbox',
        '#title' => $this->t('Suggest additional words'),
        '#description' => $this->t('Suggest additional words the user might want to search for.'),
        '#default_value' => $this->configuration['autocomplete']['suggest_words'],
      );
    }

    return $form;
  }
コード例 #5
0
ファイル: KernelTestBase.php プロジェクト: scratch/gai
 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     // Destroy the testing kernel.
     if (isset($this->kernel)) {
         $this->kernel->shutdown();
     }
     // Free up memory: Own properties.
     $this->classLoader = NULL;
     $this->vfsRoot = NULL;
     $this->configImporter = NULL;
     // Free up memory: Custom test class properties.
     // Note: Private properties cannot be cleaned up.
     $rc = new \ReflectionClass(__CLASS__);
     $blacklist = array();
     foreach ($rc->getProperties() as $property) {
         $blacklist[$property->name] = $property->getDeclaringClass()->name;
     }
     $rc = new \ReflectionClass($this);
     foreach ($rc->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $property) {
         if (!$property->isStatic() && !isset($blacklist[$property->name])) {
             $this->{$property->name} = NULL;
         }
     }
     // Clean up statics, container, and settings.
     if (function_exists('drupal_static_reset')) {
         drupal_static_reset();
     }
     \Drupal::unsetContainer();
     $this->container = NULL;
     new Settings(array());
     // Destroy the database connection, which for example removes the memory
     // from sqlite in memory.
     foreach (Database::getAllConnectionInfo() as $key => $targets) {
         Database::removeConnection($key);
     }
     parent::tearDown();
 }
コード例 #6
0
ファイル: Sql8.php プロジェクト: bjargud/drush
 public function getAll()
 {
     return Database::getAllConnectionInfo();
 }
コード例 #7
0
 /**
  * Tests the serialization and unserialization of a database connection.
  */
 public function testConnectionSerialization()
 {
     $db = Database::getConnection('default', 'default');
     try {
         $serialized = serialize($db);
         $this->pass('The database connection can be serialized.');
         $unserialized = unserialize($serialized);
         $this->assertTrue(get_class($unserialized) === get_class($db));
     } catch (\Exception $e) {
         $this->fail('The database connection cannot be serialized.');
     }
     // Ensure that all properties on the unserialized object are the same.
     $db_reflection = new \ReflectionObject($db);
     $unserialized_reflection = new \ReflectionObject($unserialized);
     foreach ($db_reflection->getProperties() as $value) {
         $value->setAccessible(TRUE);
         // Skip properties that are lazily populated on access.
         if ($value->getName() === 'driverClasses' || $value->getName() === 'schema') {
             continue;
         }
         $unserialized_property = $unserialized_reflection->getProperty($value->getName());
         $unserialized_property->setAccessible(TRUE);
         // For the PDO object, just check the statement class attribute.
         if ($value->getName() == 'connection') {
             $db_statement_class = $unserialized_property->getValue($db)->getAttribute(\PDO::ATTR_STATEMENT_CLASS);
             $unserialized_statement_class = $unserialized_property->getValue($unserialized)->getAttribute(\PDO::ATTR_STATEMENT_CLASS);
             // Assert the statement class.
             $this->assertEqual($unserialized_statement_class[0], $db_statement_class[0]);
             // Assert the connection argument that is passed into the statement.
             $this->assertEqual(get_class($unserialized_statement_class[1][0]), get_class($db_statement_class[1][0]));
         } else {
             $actual = $unserialized_property->getValue($unserialized);
             $expected = $value->getValue($db);
             $this->assertEqual($actual, $expected, vsprintf('Unserialized Connection property %s value %s is equal to expected %s', array(var_export($value->getName(), TRUE), is_object($actual) ? print_r($actual, TRUE) : var_export($actual, TRUE), is_object($expected) ? print_r($expected, TRUE) : var_export($expected, TRUE))));
         }
     }
     // By using "key", we ensure that its not a key used in the serialized PHP.
     $not_serialized_properties = ['"connection"', '"connectionOptions"', '"schema"', '"prefixes"', '"prefixReplace"', '"driverClasses"'];
     foreach ($not_serialized_properties as $property) {
         $this->assertIdentical(FALSE, strpos($serialized, $property));
     }
     // Serialize the DB connection again, but this time change the connection
     // information under the hood.
     $serialized = serialize($db);
     $db_connection_info = Database::getAllConnectionInfo();
     // Use reflection to empty out $databaseInfo.
     $reflection_class = new \ReflectionClass('Drupal\\Core\\Database\\Database');
     $database_info_reflection = $reflection_class->getProperty('databaseInfo');
     $database_info_reflection->setAccessible(TRUE);
     $database_info_reflection->setValue(NULL, []);
     // Setup a different DB connection which should be picked up after the
     // unserialize.
     $db_connection_info['default']['default']['extra'] = 'value';
     Database::setMultipleConnectionInfo($db_connection_info);
     /** @var \Drupal\Core\Database\Connection $db */
     $db = unserialize($serialized);
     $this->assertEqual($db->getConnectionOptions()['extra'], 'value');
 }