From: Vincent Vanwaelscappel Date: Wed, 28 Jul 2021 15:10:55 +0000 (+0200) Subject: wip #4623 0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4f26752549a4143edcff4863a733113e0b9315ee;p=fluidbook-toolbox.git wip #4623 0.5 --- diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index c998ebf2f..9a78f5447 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Models\FluidbookTheme; use App\Models\FluidbookQuote; +use App\Models\FluidbookTranslate; use Cubist\Backpack\Console\Commands\CubistCommand; use Cubist\Backpack\Magic\Fields\Files; use Cubist\Backpack\Magic\Fields\Color; @@ -24,7 +25,7 @@ class WorkshopMigration extends CubistCommand //'Backup current database' => 'backup', //'Import Quotes' => 'importQuotes', 'Migrate magic models' => 'migrate', - 'Import Themes' => 'importThemes', + 'Import Translations' => 'importTranslations', 'Clean caches' => 'cleanCache' ]; @@ -61,68 +62,6 @@ class WorkshopMigration extends CubistCommand $this->executeProcessQuiet('php artisan optimize:clear'); } - protected function themeCompatTable() - { - $theme = new FluidbookTheme(); - $theme->updateWS2Table(); - } - - protected function importThemes() - { - - $map = ['theme_id' => 'id', - 'nom' => 'name', - 'proprietaire' => 'owner', - 'date' => 'created_at',]; - - $ignore = ['extraXSpace', 'extraYSpace']; - - FluidbookTheme::$updateWS2ViewOnChange = false; - foreach (FluidbookTheme::all() as $theme) { - $theme->delete(); - } - - foreach (DB::table($this->_oldDB . '.themes')->get() as $e) { - $oldRoot = $this->_oldRoot . 'themes/' . $e->theme_id . '/'; - $c = new FluidbookTheme(); - foreach ($map as $old => $new) { - $v = $e->$old; - if ($old === 'date') { - $date = new \DateTime(); - $date->setTimestamp($v); - $v = $date; - } - $c->setAttribute($new, $v); - } - $c->save(); - - - $s = $this->_unserialize($e->parametres); - - foreach ($s->datas as $k => $data) { - if (in_array($k, $ignore)) { - continue; - } - - $f = $c->getField($k); - if (null === $f) { - continue; - } - if ($f instanceof Files) { - $c->_handleWS2File($f, $data, $oldRoot); - } else { - if ($f instanceof Color) { - $data = FluidbookTheme::_colorToWS3($data); - } - $c->setAttribute($k, $data); - } - } - $c->save(); - } - FluidbookTheme::$updateWS2ViewOnChange = true; - $this->themeCompatTable(); - - } protected function _unserialize($str) { @@ -158,4 +97,29 @@ class WorkshopMigration extends CubistCommand } } + protected function importTranslations() + { + $slug = []; + $nsis = []; + $contents = []; + + foreach (DB::table($this->_oldDB . '.langues')->get() as $e) { + $code = $e->lang_id; + if (stristr($code, '-')) { + $ex = explode('-', $code); + $code = $ex[0] . '_' . mb_strtoupper($ex[1]); + } + $slug[$code] = '1'; + $nsis[$code] = $e->nsis; + $contents[$code] = ['k' => '-']; + $translations = json_decode($e->traductions, true); + foreach ($translations as $str => $translation) { + $contents[$code]['t_' . base64_encode($str)] = $translation; + } + touch(FluidbookTranslate::getLanguageFile($code)); + } + + DB::table('fluidbook_translate')->where('id',1)->update(['slug' => json_encode($slug), 'nsis' => json_encode($nsis), 'content_translatable' => json_encode($contents)]); + } + } diff --git a/app/Models/FluidbookTranslate.php b/app/Models/FluidbookTranslate.php index 3e423fc99..ab12b89de 100644 --- a/app/Models/FluidbookTranslate.php +++ b/app/Models/FluidbookTranslate.php @@ -25,7 +25,7 @@ class FluidbookTranslate extends Translate public function setFields() { - $this->addField(['name' => 'nsis', 'type' => NSISLocale::class, 'label' => __('Langue de l\'installeur'), 'translatable' => true]); + $this->addField(['name' => 'nsis', 'type' => NSISLocale::class, 'label' => __('Langue de l\'installeur'), 'translatable' => true, 'default' => 'English']); parent::setFields(); } @@ -38,4 +38,13 @@ class FluidbookTranslate extends Translate { return array_merge(parent::getExtensions(), ['js']); } + + protected function _getLanguageFile($locale) + { + return self::getLanguageFile($locale); + } + + public static function getLanguageFile($locale){ + return resource_path('lang/fluidbook.' . $locale . '.json'); + } }