class Tasks

Same name in this branch
  1. 8.9.x core/modules/system/tests/modules/database_statement_monitoring_test/src/sqlite/Install/Tasks.php \Drupal\database_statement_monitoring_test\sqlite\Install\Tasks
  2. 8.9.x core/modules/system/tests/modules/database_statement_monitoring_test/src/mysql/Install/Tasks.php \Drupal\database_statement_monitoring_test\mysql\Install\Tasks
  3. 8.9.x core/modules/system/tests/modules/database_statement_monitoring_test/src/pgsql/Install/Tasks.php \Drupal\database_statement_monitoring_test\pgsql\Install\Tasks
  4. 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestMysql\Install\Tasks
  5. 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion\Install\Tasks
  6. 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestPgsql\Install\Tasks
  7. 8.9.x core/tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefake/Install/Tasks.php \Drupal\corefake\Driver\Database\corefake\Install\Tasks
  8. 8.9.x core/tests/fixtures/database_drivers/core/corefake/Install/Tasks.php \Drupal\Core\Database\Driver\corefake\Install\Tasks
  9. 8.9.x core/tests/fixtures/database_drivers/custom/corefake/Install/Tasks.php \Drupal\Driver\Database\corefake\Install\Tasks
  10. 8.9.x core/tests/fixtures/database_drivers/custom/fake/Install/Tasks.php \Drupal\Driver\Database\fake\Install\Tasks
  11. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php \Drupal\Core\Database\Driver\sqlite\Install\Tasks
  12. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php \Drupal\Core\Database\Driver\mysql\Install\Tasks
  13. 8.9.x core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks
Same name in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php \Drupal\sqlite\Driver\Database\sqlite\Install\Tasks
  2. 9 core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php \Drupal\mysql\Driver\Database\mysql\Install\Tasks
  3. 9 core/modules/system/tests/modules/database_statement_monitoring_test/src/sqlite/Install/Tasks.php \Drupal\database_statement_monitoring_test\sqlite\Install\Tasks
  4. 9 core/modules/system/tests/modules/database_statement_monitoring_test/src/mysql/Install/Tasks.php \Drupal\database_statement_monitoring_test\mysql\Install\Tasks
  5. 9 core/modules/system/tests/modules/database_statement_monitoring_test/src/pgsql/Install/Tasks.php \Drupal\database_statement_monitoring_test\pgsql\Install\Tasks
  6. 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestMysql\Install\Tasks
  7. 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion\Install\Tasks
  8. 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestPgsql\Install\Tasks
  9. 9 core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks
  10. 9 core/tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefake/Install/Tasks.php \Drupal\corefake\Driver\Database\corefake\Install\Tasks
  11. 9 core/tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses/Install/Tasks.php \Drupal\corefake\Driver\Database\corefakeWithAllCustomClasses\Install\Tasks
  12. 9 core/tests/fixtures/database_drivers/core/corefake/Install/Tasks.php \Drupal\Core\Database\Driver\corefake\Install\Tasks
  13. 9 core/tests/fixtures/database_drivers/custom/corefake/Install/Tasks.php \Drupal\Driver\Database\corefake\Install\Tasks
  14. 9 core/tests/fixtures/database_drivers/custom/fake/Install/Tasks.php \Drupal\Driver\Database\fake\Install\Tasks
  15. 9 core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php \Drupal\Core\Database\Driver\sqlite\Install\Tasks
  16. 9 core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php \Drupal\Core\Database\Driver\mysql\Install\Tasks
  17. 9 core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php \Drupal\Core\Database\Driver\pgsql\Install\Tasks
  18. 9 core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks
  19. 10 core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php \Drupal\sqlite\Driver\Database\sqlite\Install\Tasks
  20. 10 core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php \Drupal\mysql\Driver\Database\mysql\Install\Tasks
  21. 10 core/modules/system/tests/modules/database_statement_monitoring_test/src/sqlite/Install/Tasks.php \Drupal\database_statement_monitoring_test\sqlite\Install\Tasks
  22. 10 core/modules/system/tests/modules/database_statement_monitoring_test/src/mysql/Install/Tasks.php \Drupal\database_statement_monitoring_test\mysql\Install\Tasks
  23. 10 core/modules/system/tests/modules/database_statement_monitoring_test/src/pgsql/Install/Tasks.php \Drupal\database_statement_monitoring_test\pgsql\Install\Tasks
  24. 10 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestMysql\Install\Tasks
  25. 10 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion\Install\Tasks
  26. 10 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DrivertestPgsql\Install\Tasks
  27. 10 core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks
  28. 10 core/tests/Drupal/Tests/Core/Database/fixtures/core/modules/driver_missing_dependency_test/src/Driver/Database/MissingDependency/Install/Tasks.php \Drupal\driver_missing_dependency_test\Driver\Database\MissingDependency\Install\Tasks
  29. 10 core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFake/Install/Tasks.php \Drupal\core_fake\Driver\Database\CoreFake\Install\Tasks
  30. 10 core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Install/Tasks.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\Install\Tasks
  31. 10 core/tests/fixtures/database_drivers/core/CoreFake/Install/Tasks.php \Drupal\Core\Database\Driver\CoreFake\Install\Tasks
  32. 10 core/tests/fixtures/database_drivers/custom/CoreFake/Install/Tasks.php \Drupal\Driver\Database\CoreFake\Install\Tasks
  33. 10 core/tests/fixtures/database_drivers/custom/fake/Install/Tasks.php \Drupal\Driver\Database\fake\Install\Tasks
  34. 10 core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php \Drupal\Core\Database\Driver\sqlite\Install\Tasks
  35. 10 core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php \Drupal\Core\Database\Driver\mysql\Install\Tasks
  36. 10 core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php \Drupal\Core\Database\Driver\pgsql\Install\Tasks
  37. 10 core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks
  38. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php \Drupal\sqlite\Driver\Database\sqlite\Install\Tasks
  39. 11.x core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php \Drupal\mysql\Driver\Database\mysql\Install\Tasks
  40. 11.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DriverTestMysql\Install\Tasks
  41. 11.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysqlDeprecatedVersion/Install/Tasks.php \Drupal\driver_test\Driver\Database\DriverTestMysqlDeprecatedVersion\Install\Tasks
  42. 11.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestPgsql/Install/Tasks.php \Drupal\driver_test\Driver\Database\DriverTestPgsql\Install\Tasks
  43. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks
  44. 11.x core/tests/Drupal/Tests/Core/Database/fixtures/core/modules/driver_missing_dependency_test/src/Driver/Database/MissingDependency/Install/Tasks.php \Drupal\driver_missing_dependency_test\Driver\Database\MissingDependency\Install\Tasks
  45. 11.x core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFake/Install/Tasks.php \Drupal\core_fake\Driver\Database\CoreFake\Install\Tasks
  46. 11.x core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Install/Tasks.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\Install\Tasks
  47. 11.x core/tests/fixtures/database_drivers/core/CoreFake/Install/Tasks.php \Drupal\Core\Database\Driver\CoreFake\Install\Tasks
  48. 11.x core/tests/fixtures/database_drivers/custom/CoreFake/Install/Tasks.php \Drupal\Driver\Database\CoreFake\Install\Tasks
  49. 11.x core/tests/fixtures/database_drivers/custom/fake/Install/Tasks.php \Drupal\Driver\Database\fake\Install\Tasks
  50. 11.x core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks

Specifies installation tasks for PostgreSQL databases.

Hierarchy

  • class \Drupal\Core\Database\Install\Tasks
    • class \Drupal\Core\Database\Driver\pgsql\Install\Tasks extends \Drupal\Core\Database\Install\Tasks

Expanded class hierarchy of Tasks

2 files declare their use of Tasks
Tasks.php in core/modules/system/tests/modules/database_statement_monitoring_test/src/pgsql/Install/Tasks.php
Tasks.php in core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Install/Tasks.php
1 string reference to 'Tasks'
system.links.task.yml in core/modules/system/system.links.task.yml
core/modules/system/system.links.task.yml

File

core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php, line 12

Namespace

Drupal\Core\Database\Driver\pgsql\Install
View source
class Tasks extends InstallTasks {
    
    /**
     * {@inheritdoc}
     */
    protected $pdoDriver = 'pgsql';
    
    /**
     * Constructs a \Drupal\Core\Database\Driver\pgsql\Install\Tasks object.
     */
    public function __construct() {
        $this->tasks[] = [
            'function' => 'checkEncoding',
            'arguments' => [],
        ];
        $this->tasks[] = [
            'function' => 'checkBinaryOutput',
            'arguments' => [],
        ];
        $this->tasks[] = [
            'function' => 'checkStandardConformingStrings',
            'arguments' => [],
        ];
        $this->tasks[] = [
            'function' => 'initializeDatabase',
            'arguments' => [],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function name() {
        return t('PostgreSQL');
    }
    
    /**
     * {@inheritdoc}
     */
    public function minimumVersion() {
        return '9.1.2';
    }
    
    /**
     * {@inheritdoc}
     */
    protected function connect() {
        try {
            // This doesn't actually test the connection.
            Database::setActiveConnection();
            // Now actually do a check.
            Database::getConnection();
            $this->pass('Drupal can CONNECT to the database ok.');
        } catch (\Exception $e) {
            // Attempt to create the database if it is not found.
            if ($e instanceof DatabaseNotFoundException) {
                // Remove the database string from connection info.
                $connection_info = Database::getConnectionInfo();
                $database = $connection_info['default']['database'];
                unset($connection_info['default']['database']);
                // In order to change the Database::$databaseInfo array, need to remove
                // the active connection, then re-add it with the new info.
                Database::removeConnection('default');
                Database::addConnectionInfo('default', 'default', $connection_info['default']);
                try {
                    // Now, attempt the connection again; if it's successful, attempt to
                    // create the database.
                    Database::getConnection()->createDatabase($database);
                    Database::closeConnection();
                    // Now, restore the database config.
                    Database::removeConnection('default');
                    $connection_info['default']['database'] = $database;
                    Database::addConnectionInfo('default', 'default', $connection_info['default']);
                    // Check the database connection.
                    Database::getConnection();
                    $this->pass('Drupal can CONNECT to the database ok.');
                } catch (DatabaseNotFoundException $e) {
                    // Still no dice; probably a permission issue. Raise the error to the
                    // installer.
                    $this->fail(t('Database %database not found. The server reports the following message when attempting to create the database: %error.', [
                        '%database' => $database,
                        '%error' => $e->getMessage(),
                    ]));
                }
            }
            else {
                // Database connection failed for some other reason than the database
                // not existing.
                $this->fail(t('Failed to connect to your database server. The server reports the following message: %error.<ul><li>Is the database server running?</li><li>Does the database exist, and have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname and port number?</li></ul>', [
                    '%error' => $e->getMessage(),
                ]));
                return FALSE;
            }
        }
        return TRUE;
    }
    
    /**
     * Check encoding is UTF8.
     */
    protected function checkEncoding() {
        try {
            if (Database::getConnection()->query('SHOW server_encoding')
                ->fetchField() == 'UTF8') {
                $this->pass(t('Database is encoded in UTF-8'));
            }
            else {
                $this->fail(t('The %driver database must use %encoding encoding to work with Drupal. Recreate the database with %encoding encoding. See <a href="INSTALL.pgsql.txt">INSTALL.pgsql.txt</a> for more details.', [
                    '%encoding' => 'UTF8',
                    '%driver' => $this->name(),
                ]));
            }
        } catch (\Exception $e) {
            $this->fail(t('Drupal could not determine the encoding of the database was set to UTF-8'));
        }
    }
    
    /**
     * Check Binary Output.
     *
     * Unserializing does not work on Postgresql 9 when bytea_output is 'hex'.
     */
    public function checkBinaryOutput() {
        // PostgreSQL < 9 doesn't support bytea_output, so verify we are running
        // at least PostgreSQL 9.
        $database_connection = Database::getConnection();
        if (version_compare($database_connection->version(), '9') >= 0) {
            if (!$this->checkBinaryOutputSuccess()) {
                // First try to alter the database. If it fails, raise an error telling
                // the user to do it themselves.
                $connection_options = $database_connection->getConnectionOptions();
                // It is safe to include the database name directly here, because this
                // code is only called when a connection to the database is already
                // established, thus the database name is guaranteed to be a correct
                // value.
                $query = "ALTER DATABASE \"" . $connection_options['database'] . "\" SET bytea_output = 'escape';";
                try {
                    $database_connection->query($query);
                } catch (\Exception $e) {
                    // Ignore possible errors when the user doesn't have the necessary
                    // privileges to ALTER the database.
                }
                // Close the database connection so that the configuration parameter
                // is applied to the current connection.
                Database::closeConnection();
                // Recheck, if it fails, finally just rely on the end user to do the
                // right thing.
                if (!$this->checkBinaryOutputSuccess()) {
                    $replacements = [
                        '%setting' => 'bytea_output',
                        '%current_value' => 'hex',
                        '%needed_value' => 'escape',
                        '@query' => $query,
                    ];
                    $this->fail(t("The %setting setting is currently set to '%current_value', but needs to be '%needed_value'. Change this by running the following query: <code>@query</code>", $replacements));
                }
            }
        }
    }
    
    /**
     * Verify that a binary data roundtrip returns the original string.
     */
    protected function checkBinaryOutputSuccess() {
        $bytea_output = Database::getConnection()->query("SHOW bytea_output")
            ->fetchField();
        return $bytea_output == 'escape';
    }
    
    /**
     * Ensures standard_conforming_strings setting is 'on'.
     *
     * When standard_conforming_strings setting is 'on' string literals ('...')
     * treat backslashes literally, as specified in the SQL standard. This allows
     * Drupal to convert between bytea, text and varchar columns.
     */
    public function checkStandardConformingStrings() {
        $database_connection = Database::getConnection();
        if (!$this->checkStandardConformingStringsSuccess()) {
            // First try to alter the database. If it fails, raise an error telling
            // the user to do it themselves.
            $connection_options = $database_connection->getConnectionOptions();
            // It is safe to include the database name directly here, because this
            // code is only called when a connection to the database is already
            // established, thus the database name is guaranteed to be a correct
            // value.
            $query = "ALTER DATABASE \"" . $connection_options['database'] . "\" SET standard_conforming_strings = 'on';";
            try {
                $database_connection->query($query);
            } catch (\Exception $e) {
                // Ignore possible errors when the user doesn't have the necessary
                // privileges to ALTER the database.
            }
            // Close the database connection so that the configuration parameter
            // is applied to the current connection.
            Database::closeConnection();
            // Recheck, if it fails, finally just rely on the end user to do the
            // right thing.
            if (!$this->checkStandardConformingStringsSuccess()) {
                $replacements = [
                    '%setting' => 'standard_conforming_strings',
                    '%current_value' => 'off',
                    '%needed_value' => 'on',
                    '@query' => $query,
                ];
                $this->fail(t("The %setting setting is currently set to '%current_value', but needs to be '%needed_value'. Change this by running the following query: <code>@query</code>", $replacements));
            }
        }
    }
    
    /**
     * Verifies the standard_conforming_strings setting.
     */
    protected function checkStandardConformingStringsSuccess() {
        $standard_conforming_strings = Database::getConnection()->query("SHOW standard_conforming_strings")
            ->fetchField();
        return $standard_conforming_strings == 'on';
    }
    
    /**
     * Make PostgreSQL Drupal friendly.
     */
    public function initializeDatabase() {
        // We create some functions using global names instead of prefixing them
        // like we do with table names. This is so that we don't double up if more
        // than one instance of Drupal is running on a single database. We therefore
        // avoid trying to create them again in that case.
        // At the same time checking for the existence of the function fixes
        // concurrency issues, when both try to update at the same time.
        try {
            $connection = Database::getConnection();
            // When testing, two installs might try to run the CREATE FUNCTION queries
            // at the same time. Do not let that happen.
            $connection->query('SELECT pg_advisory_lock(1)');
            // Don't use {} around pg_proc table.
            if (!$connection->query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")
                ->fetchField()) {
                $connection->query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
          \'SELECT random();\'
          LANGUAGE \'sql\'', [], [
                    'allow_delimiter_in_query' => TRUE,
                ]);
            }
            if (!$connection->query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'substring_index'")
                ->fetchField()) {
                $connection->query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
          \'SELECT array_to_string((string_to_array($1, $2)) [1:$3], $2);\'
          LANGUAGE \'sql\'', [], [
                    'allow_delimiter_in_query' => TRUE,
                ]);
            }
            $connection->query('SELECT pg_advisory_unlock(1)');
            $this->pass(t('PostgreSQL has initialized itself.'));
        } catch (\Exception $e) {
            $this->fail(t('Drupal could not be correctly setup with the existing database due to the following error: @error.', [
                '@error' => $e->getMessage(),
            ]));
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function getFormOptions(array $database) {
        $form = parent::getFormOptions($database);
        if (empty($form['advanced_options']['port']['#default_value'])) {
            $form['advanced_options']['port']['#default_value'] = '5432';
        }
        return $form;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Tasks::$pdoDriver protected property The name of the PDO driver this database type requires. Overrides Tasks::$pdoDriver
Tasks::$results protected property Results from tasks.
Tasks::$tasks protected property Structure that describes each task to run.
Tasks::checkBinaryOutput public function Check Binary Output.
Tasks::checkBinaryOutputSuccess protected function Verify that a binary data roundtrip returns the original string.
Tasks::checkEncoding protected function Check encoding is UTF8.
Tasks::checkEngineVersion protected function Check the engine version. 1
Tasks::checkStandardConformingStrings public function Ensures standard_conforming_strings setting is &#039;on&#039;.
Tasks::checkStandardConformingStringsSuccess protected function Verifies the standard_conforming_strings setting.
Tasks::connect protected function Check if we can connect to the database. Overrides Tasks::connect
Tasks::engineVersionRequirementsCheck final public function Checks engine version requirements for the status report.
Tasks::fail protected function Assert test as failed.
Tasks::getFormOptions public function Return driver specific configuration options. Overrides Tasks::getFormOptions
Tasks::hasPdoDriver protected function Ensure the PDO driver is supported by the version of PHP in use.
Tasks::initializeDatabase public function Make PostgreSQL Drupal friendly.
Tasks::installable public function Check whether Drupal is installable on the database.
Tasks::minimumVersion public function Return the minimum required version of the engine. Overrides Tasks::minimumVersion
Tasks::name public function Return the human-readable name of the driver. Overrides Tasks::name 1
Tasks::pass protected function Assert test as a pass.
Tasks::runTasks public function Run database tasks and tests to see if Drupal can run on the database.
Tasks::runTestQuery protected function Run SQL tests to ensure the database can execute commands with the current user.
Tasks::validateDatabaseSettings public function Validates driver specific configuration settings.
Tasks::__construct public function Constructs a \Drupal\Core\Database\Driver\pgsql\Install\Tasks object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.