0 follower

Final Class Yiisoft\Translator\Message\Db\DbSchemaManager

InheritanceYiisoft\Translator\Message\Db\DbSchemaManager

Manages the translator tables schema in the database.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Translator\Message\Db\DbSchemaManager
ensureNoTables() Ensures that the translator tables does not exist in the database. Yiisoft\Translator\Message\Db\DbSchemaManager
ensureTables() Ensures that the translator tables exists in the database. Yiisoft\Translator\Message\Db\DbSchemaManager

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Db\Connection\ConnectionInterface $db )
$db \Yiisoft\Db\Connection\ConnectionInterface

                public function __construct(private ConnectionInterface $db)
{
}

            
ensureNoTables() public method

Ensures that the translator tables does not exist in the database.

public void ensureNoTables ( string $tableSourceMessage '{{%yii_source_message}}', string $tableMessage '{{%yii_message}}' )
$tableSourceMessage string
$tableMessage string
throws \Yiisoft\Db\Exception\Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws Throwable

                public function ensureNoTables(
    string $tableSourceMessage = '{{%yii_source_message}}',
    string $tableMessage = '{{%yii_message}}',
): void {
    $driverName = $this->db->getDriverName();
    $schema = $this->db->getSchema();
    $tableRawNameSourceMessage = $schema->getRawTableName($tableSourceMessage);
    $tableRawNameMessage = $schema->getRawTableName($tableMessage);
    if ($this->hasTable($tableMessage)) {
        if ($driverName !== 'sqlite' && $schema->getTableForeignKeys($tableMessage, true) !== []) {
            // drop foreign key for table `yii_message`.
            $this->db
                ->createCommand()
                ->dropForeignKey(
                    $tableRawNameMessage,
                    "{{FK_{$tableRawNameSourceMessage}_{$tableRawNameMessage}}}",
                )
                ->execute();
        }
        // drop table `yii_message`.
        $this->db->createCommand()->dropTable($tableRawNameMessage)->execute();
        if ($driverName === 'oci') {
            // drop sequence for table `yii_message`.
            $this->db
                ->createCommand()
                ->setSql(
                    <<<SQL
                    DROP SEQUENCE {{{$tableRawNameMessage}_SEQ}}
                    SQL,
                )
                ->execute();
        }
    }
    if ($this->hasTable($tableSourceMessage)) {
        // drop table `yii_source_message`.
        $this->db->createCommand()->dropTable($tableRawNameSourceMessage)->execute();
        if ($driverName === 'oci') {
            // drop sequence for table `yii_source_message`.
            $this->db
                ->createCommand()
                ->setSql(
                    <<<SQL
                    DROP SEQUENCE {{{$tableRawNameSourceMessage}_SEQ}}
                    SQL,
                )
                ->execute();
        }
    }
}

            
ensureTables() public method

Ensures that the translator tables exists in the database.

public void ensureTables ( string $tableSourceMessage '{{%yii_source_message}}', string $tableMessage '{{%yii_message}}' )
$tableSourceMessage string
$tableMessage string
throws \Yiisoft\Db\Exception\Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws Throwable

                public function ensureTables(
    string $tableSourceMessage = '{{%yii_source_message}}',
    string $tableMessage = '{{%yii_message}}',
): void {
    $driverName = $this->db->getDriverName();
    $schema = $this->db->getSchema();
    $tableRawNameSourceMessage = $schema->getRawTableName($tableSourceMessage);
    $tableRawNameMessage = $schema->getRawTableName($tableMessage);
    if ($this->hasTable($tableSourceMessage) && $this->hasTable($tableMessage)) {
        return;
    }
    if ($driverName === 'sqlite') {
        $this->createSchemaSqlite(
            $schema,
            $tableSourceMessage,
            $tableRawNameSourceMessage,
            $tableMessage,
            $tableRawNameMessage,
        );
        return;
    }
    $this->createSchema(
        $schema,
        $driverName,
        $tableSourceMessage,
        $tableRawNameSourceMessage,
        $tableMessage,
        $tableRawNameMessage,
    );
}