Skip to content

Commit aac3c1e

Browse files
committed
Improved DB type mapping
1 parent 2a678f5 commit aac3c1e

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

classes/drivers/Mysql.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php namespace Webula\SmallBackup\Classes\Drivers;
22

33
use Illuminate\Database\Connection;
4-
use Webula\SmallBackup\Models\Settings;
54

65
class Mysql implements Contracts\BackupStream
76
{
@@ -25,13 +24,7 @@ public function __construct(Connection $connection, array $excludedTables = [])
2524
$this->connection = $connection;
2625
$this->excludedTables = $excludedTables;
2726

28-
/**
29-
* Override missing json type if needed
30-
*/
31-
if( Settings::get('doctrine_maping', null) )
32-
{
33-
\DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'text');
34-
}
27+
$this->syncPlatformMapping();
3528
}
3629

3730
/**
@@ -288,6 +281,23 @@ protected function getCharset(): string
288281
}
289282

290283

284+
/**
285+
* Sync doctrine platform mapping
286+
*
287+
* @return void
288+
*/
289+
protected function syncPlatformMapping(): void
290+
{
291+
$platform = $this->connection->getDoctrineSchemaManager()->getDatabasePlatform();
292+
if (!$platform->hasDoctrineTypeMappingFor('json')) {
293+
$platform->registerDoctrineTypeMapping('json', \Doctrine\DBAL\Types\Type::TEXT);
294+
}
295+
if (!$platform->hasDoctrineTypeMappingFor('enum')) {
296+
$platform->registerDoctrineTypeMapping('enum', \Doctrine\DBAL\Types\Type::STRING);
297+
}
298+
}
299+
300+
291301
/**
292302
* Wrap table/database name
293303
*

lang/cs/lang.php

-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
'database' => 'Databáze',
3737
'theme' => 'Šablona',
3838
'backups' => 'Zálohy',
39-
'settings' => 'Nastavení',
4039
],
4140

4241
'backup_folder' => 'Adresář pro umístění záloh',
@@ -56,8 +55,5 @@
5655
'section_db' => 'Databáze',
5756
'section_theme' => 'Téma vzhledu',
5857
'section_listing' => 'Výpis záloh',
59-
60-
'doctrine_maping' => 'Přepsat mapování typů sloupců DB',
61-
'doctrine_maping_comment' => 'Pokud při zálohování databáze dostáváte chybu s nepodporovaným typem, povolením této volby budou přemapovány. Podporovaná mapování jsou: [json => text].',
6258
],
6359
];

lang/en/lang.php

-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
'database' => 'Database',
3737
'theme' => 'Theme',
3838
'backups' => 'Backups',
39-
'settings' => 'Settings',
4039
],
4140

4241
'backup_folder' => 'Backup folder',
@@ -56,8 +55,5 @@
5655
'section_db' => 'Database',
5756
'section_theme' => 'Theme',
5857
'section_listing' => 'List of backups',
59-
60-
'doctrine_maping' => 'Override DB columns type mapping',
61-
'doctrine_maping_comment' => 'If you receive DB backup error with unsupported type message, enable this to override type mapping. Supported mappings are: [json => text].',
6258
],
6359
];

models/settings/fields.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,3 @@ tabs:
6161
type: partial
6262
path: $/webula/smallbackup/controllers/settings/_listing-theme.htm
6363
tab: webula.smallbackup::lang.settings.tabs.theme
64-
65-
doctrine_maping:
66-
label: webula.smallbackup::lang.settings.doctrine_maping
67-
comment: webula.smallbackup::lang.settings.doctrine_maping_comment
68-
type: checkbox
69-
span: left
70-
tab: webula.smallbackup::lang.settings.tabs.settings

updates/version.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
1.0.1: First version of SmallBackup
22
1.0.2: Fixed flash message content
3-
1.1.0:
4-
- Added option to override DB type mapping
3+
1.1.0:
4+
- Fixed missing DB type mapping

0 commit comments

Comments
 (0)