Skip to content

Commit

Permalink
added - convert database
Browse files Browse the repository at this point in the history
  • Loading branch information
Tint Naing Win committed Sep 28, 2019
1 parent c82d87a commit 9cf4ab9
Show file tree
Hide file tree
Showing 20 changed files with 725 additions and 143 deletions.
88 changes: 84 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Convert files from zawgyi to unicode for Laravel apps

:warning: **This package is under development and is not suitable for production use.** :warning:
# Convert files and database from zawgyi to unicode for Laravel apps

## Requirements

Expand Down Expand Up @@ -52,17 +50,99 @@ You can publish the config-file with:
``` bash
php artisan vendor:publish --provider="Tintnaingwin\KuuPyaung\KuuPyaungServiceProvider"
```
## Artisan commands

You can convert your app by running:

``` bash
php artisan kuupyaung:run
```

If you would like to convert only the files, run:
``` bash
php artisan kuupyaung:run --only-files
```

If you would like to convert only the database, run:
``` bash
php artisan kuupyaung:run --only-database
```

## Configuration

Kuu Pyaung can be configured directly in /config/kuu-pyaung.php.

This is the contents of the published config file:
``` php
return [

/*
* These resource directories only will be convert.
*/
'include_files' => [
'views',
'lang', // lang/my
],

/*
* These database tables will be excluded from the convert.
*/
'exclude_tables' => [
'password_resets',
'migrations',
'failed_jobs',
'telescope_entries',
'telescope_entries_tags',
'telescope_monitoring',
],
];
```

**Files Convert**

This package convert only folder under the `resource directories`. You can determine which resource files will be convert.

``` php
/*
* These resource directories only will be convert.
*/
'include_files' => [
'views',
'lang', // lang/my
],
```

**Database Convert**

This package convert only `string` data types from database. You can determine which tables will be excluded from the convert.

``` php
/*
* These database tables will be excluded from the convert.
*/
'exclude_tables' => [
'password_resets',
'migrations',
'failed_jobs',
'telescope_entries',
'telescope_entries_tags',
'telescope_monitoring',
],
```

**We highly recommend that you should use maintenance mode when you convert the database tables in production server.**

### Supported databases

- MySQL
- PostgreSQL
- SQLite

## Todo

- Convert database (high priority on mysql)
- Backup database
- Restore database
- Convert database with UI

## Testing

Expand Down
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@
],
"require": {
"php": ">=5.6",
"illuminate/console": "^5.2",
"illuminate/contracts": "^5.2",
"illuminate/events": "^5.2",
"illuminate/filesystem": "^5.2",
"illuminate/support": "^5.2",
"tintnaingwin/myanfont": "^0.2"
"illuminate/console": "~5.2|~5.3|~5.4",
"illuminate/contracts": "~5.2|~5.3|~5.4",
"illuminate/events": "~5.2|~5.3|~5.4",
"illuminate/filesystem": "~5.2|~5.3|~5.4",
"illuminate/support": "~5.2|~5.3|~5.4",
"tintnaingwin/myanfont": "^0.2",
"doctrine/dbal": "^2.5"
},
"require-dev": {
"mockery/mockery": "^1.0",
"orchestra/testbench": "3.*",
"orchestra/testbench": "~3.2|~3.3|~3.4",
"phpunit/phpunit": "^4.8|^5.7"
},
"autoload": {
"psr-4": {
"Tintnaingwin\\KuuPyaung\\": "src"
}
},
"files": [
"src/Helpers/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
38 changes: 12 additions & 26 deletions config/kuu-pyaung.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,22 @@
return [

/*
* These directories only will be convert.
* These resource directories only will be convert.
*/
'include_files' => [
'views',
'lang', // lang/my
],

'database' => [
/*
* These tables will be excluded from the convert.
*/
'exclude_tables' => [
'migrations',
'telescope_entries',
'telescope_entries_tags',
'telescope_monitoring',
],

/*
* These data types will be include from the convert.
*
* Recommend data type is string.
*/
'include_data_types' => [
'char',
'varchar',
'tinytext',
'text',
'mediumtext',
'longtext',
]
]
/*
* These database tables will be excluded from the convert.
*/
'exclude_tables' => [
'password_resets',
'migrations',
'failed_jobs',
'telescope_entries',
'telescope_entries_tags',
'telescope_monitoring',
],
];
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
</filter>
<php>
<env name="APP_NAME" value="mysite"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
11 changes: 5 additions & 6 deletions src/Console/ConvertCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Console\Command;
use Tintnaingwin\KuuPyaung\Convert\ConvertJobFactory;
use Tintnaingwin\KuuPyaung\Exceptions\InvalidCommand;
use Tintnaingwin\KuuPyaung\Helpers\CommandOutput;

class ConvertCommand extends Command
{
Expand All @@ -18,14 +19,12 @@ class ConvertCommand extends Command
*/
public function handle()
{
try {
app(CommandOutput::class)->bind($this);

try {
$this->guardAgainstInvalidOptions();

$this->info('Starting convert from zawgyi to unicode...');
$this->output->newLine();

$convertJob = ConvertJobFactory::create($this);
$convertJob = ConvertJobFactory::create();

if ($this->option('only-database')) {
$convertJob->dontConvertFiles();
Expand Down Expand Up @@ -53,7 +52,7 @@ public function handle()
protected function guardAgainstInvalidOptions()
{
if ($this->option('only-database') && $this->option('only-files')) {
throw InvalidCommand::create('Cannot use only-database and only-files together');
throw InvalidCommand::create('Cannot use `only-database` and `only-files` together');
}
}
}
110 changes: 25 additions & 85 deletions src/Convert/ConvertJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

namespace Tintnaingwin\KuuPyaung\Convert;

use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Tintnaingwin\MyanFont\Facades\MyanFont;

class ConvertJob implements ConvertJobInterface
{
protected $includeFolder = ['views', 'lang'];

protected $isConvertFiles = true;

protected $isConvertDatabases = true;

/**
* The console command instance.
* The FileJob implementation.
*
* @var FileJob
*/
protected $fileJob;

/**
* The DatabaseJob implementation.
*
* @var \Illuminate\Console\Command
* @var DatabaseJob
*/
protected $command;
protected $dbJob;

/**
* @throws \Exception
Expand All @@ -37,84 +37,37 @@ public function run()
}

/**
* The list of directories and files that will be included in the convert.
* Convert the $includeFolder
*
* @return void
*/
public function convertFolders() {
try {

if (!count($this->includeFolder)) {
$this->command->warn("There are no folder to be converted.");
}

foreach ($this->includeFolder as $value) {

$this->command->info("Converting $value files...");

if (!File::exists(resource_path($value))) {
$this->command->error(resource_path($value) . " directory does not exist");
$this->command->getOutput()->newLine();
continue;
}

$files = File::allFiles(resource_path($value));

if (!count($files)) {
$this->command->warn("There are no $value files to be converted.");
continue;
}

$this->convertFolder($value, $files);

}

} catch (Exception $exception) {

$this->command->error("Convert failed because {$exception->getMessage()}.".PHP_EOL.$exception->getTraceAsString());

}
public function convertFolders()
{
$this->fileJob->convert();
}

/**
* @param string $name
* @param \Symfony\Component\Finder\SplFileInfo[] $files
*
* @return void
*/
public function convertFolder($name, $files)
public function convertDatabase()
{
$this->command->getOutput()->progressStart(count($files));

foreach ($files as $path => $value) {

$content = $value->getContents();

$data = MyanFont::zg2uni($content);

File::put(resource_path($name . '/' . $value->getRelativePathname()), $data);

$this->command->getOutput()->progressAdvance();
}

$this->command->getOutput()->progressFinish();
$this->dbJob->convert();
}

public function convertDatabase()
/**
* @return self
*/
public function setDbJob(DatabaseJob $dbJob)
{
// TODO: Implement convertDatabase() method.
$this->dbJob = $dbJob;

return $this;
}

/**
* Set the console command instance.
*
* @param \Illuminate\Console\Command $command
* @return $this
* @return self
*/
public function setCommand(Command $command)
public function setFileJob(FileJob $fileJob)
{
$this->command = $command;
$this->fileJob = $fileJob;

return $this;
}
Expand Down Expand Up @@ -142,17 +95,4 @@ public function dontConvertDatabases()

return $this;
}


/**
* @param array $includeFolder
*
* @return ConvertJob
*/
public function setIncludeFiles($includeFolder)
{
$this->includeFolder = $includeFolder;

return $this;
}
}
Loading

0 comments on commit 9cf4ab9

Please sign in to comment.