Git Product home page Git Product logo

Comments (4)

mteichtahl avatar mteichtahl commented on September 13, 2024

the following also fails

$map[\raoul2000\workflow\base\StatusIdConverter::VALUE_NULL] = 1;

from yii2-workflow.

raoul2000 avatar raoul2000 commented on September 13, 2024

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 :

  • initialize the Status Id Converter with a minimal map definig a mapping for NULL.
Yii::$app->set('converter',[
    'class' => 'raoul2000\workflow\base\StatusIdConverter',
    'map' => [StatusIdConverter::VALUE_NULL => StatusIdConverter::VALUE_NULL ]
]);
  • Once you have your final conversion map ready, update the Status Id Converter component, and don't forget the NULL match.
// 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 ....

from yii2-workflow.

mteichtahl avatar mteichtahl commented on September 13, 2024

Thanks raoul

I can confirm all is working as expected.

Thank you very much for your support.

from yii2-workflow.

raoul2000 avatar raoul2000 commented on September 13, 2024

you're welcome :)

from yii2-workflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.