{
$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');
}
+
}
}
{
$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;
}
}