]> _ Git - cubist_cms-back.git/commitdiff
wip #5150 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Mar 2022 22:05:28 +0000 (23:05 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Mar 2022 22:05:28 +0000 (23:05 +0100)
src/app/Console/Commands/RefreshComposedAttributesCommand.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 4904840f662a23aea041f6d97697213691218ec1..e86e529d03c5b55a1ae3406a5b62e6135eeb9645 100644 (file)
@@ -44,10 +44,13 @@ class RefreshComposedAttributesCommand extends CubistMagicCommand
     {
         $this->line('Handling ' . get_class($model));
 
-        try {
-            call_user_func(get_class($model), 'refreshComposedAttributes');
-        } catch (\Exception $e) {
 
+        $res = call_user_func([get_class($model), 'refreshComposedAttributes']);
+        if (!$res) {
+            $this->line('No composed attributes');
+        } else {
+            $this->line($res . ' models updated');
         }
+
     }
 }
index 3ba4fc9ff0412770f6c61ca0ee7fb8282ada5ad5..e73c23cb0b75a8283436c2f46979df2678dc8e5b 100644 (file)
@@ -1172,17 +1172,24 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     {
         $all = static::all();
         $hasComposed = false;
+        $nb = 0;
         foreach ($all as $instance) {
             foreach ($instance->getFields() as $field) {
                 if ($field instanceof Composed) {
                     $hasComposed = true;
-                    $instance->getAttribute($field->getName());
+                    $n = $field->getName();
+                    $v = $instance->getAttribute($n);
+                    $instance->setAttribute($n, $v);
                 }
             }
             if (!$hasComposed) {
-                return;
+                return false;
+            }
+
+            if ($instance->save()) {
+                $nb++;
             }
-            $instance->save();
         }
+        return $nb;
     }
 }