Closed mteichtahl closed 9 years ago
the following also fails
$map[\raoul2000\workflow\base\StatusIdConverter::VALUE_NULL] = 1;
Hi,
The problem is that when the Article model instance is created, it's status attribute is NULL and as a status Id Converter is declared, the SimpleWorkflow behavior is going to ask to the converter for a valid status ID to replace this NULL value. I dont know what default map you have used but I assume it doesn't contain any match for NULL.
Assuming you have an Artcile model like this one :
class Article extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'workflow' =>[
'class' => \raoul2000\workflow\base\SimpleWorkflowBehavior::className(),
// declare a status converter with ID 'converter'
'statusConverter' => 'converter'
]
];
}
}
What you should do is :
Yii::$app->set('converter',[
'class' => 'raoul2000\workflow\base\StatusIdConverter',
'map' => [StatusIdConverter::VALUE_NULL => StatusIdConverter::VALUE_NULL ]
]);
// the status ID conversion is invoked here, and status being NULL
// the conversion will look for a NULL matching line in the conversion map
$article = new Article();
$article->getStatusConverter()->setMap([
'article/DRAFT' => 'DRAFT',
'article/PUBLISHED' => 'PUBLISHED',
'article/EXPIRED' => 'EXPIRED',
'article/SCHEDULED' => 'SCHEDULED',
'article/MODERATED' => 'MODERATED',
StatusIdConverter::VALUE_NULL => StatusIdConverter::VALUE_NULL
]);
This is ok if you want to consider that the NULL status is invariant regarding the Status Id Convertion. If that's not the case and if for instance you want to convert NULL status into 'article/new', then, you will have to force the conversion for all models that were created before the map is updated.
To force status ID conversion on a model, you must call the initStatus()
method on this model:
$article->initStatus();
I hope this explanation is clear. If not, don't hesitate to ask ...
One last point : I think you should update yii2-workflow to dev-master until I release 0.0.12 because from the stack trace I see you are not using the lastest version. As for releasing 0.0.12 I will do that soon but I wanted to wait for your feedback first and make more tests on my side ....
Thanks raoul
I can confirm all is working as expected.
Thank you very much for your support.
you're welcome :)
I am calling setMap() as below
which is providing me the following map
However, Im seeing the following
I have tried all combination of null, ' null', NULL, 'NULL' etc, with the same results
The check on line 100
Leads me to think that if I pass in NULL, or null, then $id gets replaced. then line 103
tried to find a matching entry in $map.
As I already have null in $map, I would assume this would return a value of 1, but rather it throws on line 121.
any ideas ?