From: Vincent Vanwaelscappel Date: Tue, 11 Apr 2023 15:58:14 +0000 (+0200) Subject: wip #5851 @5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=38ea930cd73c35095788847e9edcc680403cfedf;p=cubist_cms-back.git wip #5851 @5 --- diff --git a/composer.json b/composer.json index 49c72b4..2010afb 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "backpack/pro": "^1.6.4", "cubist/cms-front": "dev-backpack5", "cubist/util": "dev-master", - "cubist/locale": "dev-master", + "cubist/locale": "dev-backpack5", "cubist/laravel-backpack-dropzone-field": "dev-master", "spatie/laravel-translatable": "^6.4.0", "venturecraft/revisionable": "^1.40.0", diff --git a/src/app/Magic/MagicObserver.php b/src/app/Magic/MagicObserver.php index 318c62d..efae5b5 100644 --- a/src/app/Magic/MagicObserver.php +++ b/src/app/Magic/MagicObserver.php @@ -57,6 +57,11 @@ class MagicObserver return $this->_trigger($model, 'restored'); } + function retrieved(CubistMagicAbstractModel $model){ + return $this->_trigger($model, 'retrieved'); + } + + protected function _trigger($model, $event) { $event = Str::camel('on_' . $event); diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 347011b..27a6e88 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -160,7 +160,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia public function __construct(array $attributes = []) { $this->setup(); - parent::__construct($attributes); } @@ -170,10 +169,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia if (null !== $this->connection) { $this->setConnection($this->connection); } - start_measure('Set form fields'); + $label = 'Set '.get_class($this).' form fields'; + start_measure($label); $this->setFields(); $this->postSetFields(); - stop_measure('Set form fields'); + stop_measure($label); } /** @@ -192,19 +192,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia } - public function newFromBuilder($attributes = [], $connection = null) - { - $res = parent::newFromBuilder($attributes, $connection); - $this->onRetreived(); - return $res; - } - - - public function onRetreived() - { - - } - public function getPrimaryKey() { return $this->primaryKey; @@ -1281,6 +1268,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia return $nb; } + public function onRetrieved(): bool + { + return true; + } + public function onSaved(): bool { return true; diff --git a/src/app/Magic/Models/CubistMagicTranslatableModel.php b/src/app/Magic/Models/CubistMagicTranslatableModel.php index f0d3067..7f9b897 100644 --- a/src/app/Magic/Models/CubistMagicTranslatableModel.php +++ b/src/app/Magic/Models/CubistMagicTranslatableModel.php @@ -55,13 +55,15 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel return $field; } - public function getTranslations(string $key = null): array + public function getTranslations(string $key = null, array $allowedLocales = null): array { if ($key !== null) { if (isset($this->_translations[$key])) { return $this->_translations[$key]; } - start_measure('Get translation of ' . $key); + $measure_label = 'Get translation of ' . get_class($this) . '::' . $key; + throw new \Error(':('); + start_measure($measure_label); $this->guardAgainstNonTranslatableAttribute($key); $attrs = $this->getAttributes(); if (!isset($attrs[$key])) { @@ -86,14 +88,13 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel }); } $this->_translations[$key] = $res; - stop_measure('Get translation of ' . $key); + stop_measure($measure_label); return $res; } start_measure('Get all translations'); $res = array_reduce($this->getTranslatableAttributes(), function ($result, $item) { $result[$item] = $this->getTranslations($item); - return $result; }); stop_measure('Get all translations'); @@ -137,8 +138,8 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel $value = $this->_migrateTranslation($key); } - if(str_starts_with($key,'t_') && !$value){ - $value=''; + if (str_starts_with($key, 't_') && !$value) { + $value = ''; } if (null === $f) { diff --git a/src/app/Magic/Models/Translate.php b/src/app/Magic/Models/Translate.php index 9a771e0..7c9bed0 100644 --- a/src/app/Magic/Models/Translate.php +++ b/src/app/Magic/Models/Translate.php @@ -57,6 +57,7 @@ class Translate extends CubistMagicTranslatableModel $currentSection = '-'; $sections = [$currentSection => []]; + foreach ($translate->getStringToTranslate() as $sectionLabel => $strings) { $toTranslate = []; foreach ($strings as $string) { @@ -121,12 +122,17 @@ class Translate extends CubistMagicTranslatableModel } } + public function onRetrieved(): bool + { + $res = parent::onRetrieved(); + return $res; + } + protected static function _encodeKey($string) { return 't_' . base64_encode($string); } - public function onSaving(): bool { $this->saveLanguageFile();