craft-wheelform icon indicating copy to clipboard operation
craft-wheelform copied to clipboard

Install issue (on MySQL Galera cluster setup)

Open holiday-jan opened this issue 2 years ago • 5 comments

Hi!

During the ./craft plugin/install process, we receive the following issue:

insert into {{%wheelform_forms}} ... done (time: 0.012s)

insert into {{%wheelform_form_fields}} ...Exception: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (cr_demo.wheelform_form_fields, CONSTRAINT fk_rqhzcqwspclgbchelqochlustfsetbvaadxc FOREIGN KEY (form_id) REFERENCES wheelform_forms (id) ON DELETE CASCADE) The SQL being executed was: INSERT INTO wheelform_form_fields (form_id, type, name, order, required, dateCreated, dateUpdated, uid) VALUES (1, 'email', 'email', 1, 1, '2023-12-07 12:37:44', '2023-12-07 12:37:44', '5389955c-91c0-4d12-b1e1-ccf4cdc831d3') (/data/www/host/vendor/yiisoft/yii2/db/Schema.php:676)`

Extra information: our DB-setup is on a galera-cluster and, the first "auto ID" for the initial insert was 3, instead of the expacted 1. image So the second insert, where the form_id value is set to 1, fails the constraint.

Hope this imformation helps you to make the install process smoother.

Best regards, Jan

holiday-jan avatar Dec 07 '23 12:12 holiday-jan

Thank you for the bug report. That's a very specific bug. I'll look into it.

xpertbot avatar Dec 07 '23 15:12 xpertbot

Hi,

Maybe this is a suitable solution, if you change the function insertDefaultData() in the Install.php script to:

    protected function insertDefaultData()
    {
        $firstForm = new \wheelform\db\Form();
        $firstForm->site_id = Craft::$app->sites->currentSite->id;
        $firstForm->name = 'Contact Form';
        $firstForm->to_email = "[email protected]";
        $firstForm->active = 1;
        $firstForm->send_email = 1;
        $firstForm->recaptcha = 0;

        if ($firstForm->save()) {
            $this->insert(
                '{{%wheelform_form_fields}}',
                [
                    "form_id" => $firstForm->id,
                    "type" => 'email',
                    "name" => "email",
                    "order" => 1,
                    "required" => 1,
                ]
            );
            $this->insert(
                '{{%wheelform_form_fields}}',
                [
                    "form_id" => $firstForm->id,
                    "type" => 'text',
                    "name" => "name",
                    "order" => 2,
                    "required" => 0,
                ]
            );
            $this->insert(
                '{{%wheelform_form_fields}}',
                [
                    "form_id" => $firstForm->id,
                    "type" => 'text',
                    "name" => "message",
                    "order" => 3,
                    "required" => 1,
                ]
            );
        }
    }

!! Untested, only as example !!

Hope this will help you in a good and solid solution. We love your plugin, thank you for your time again!

Beste regards, Jan

holiday-jan avatar Jan 12 '24 14:01 holiday-jan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 15 '24 21:03 stale[bot]

I tested my suggested solution: https://github.com/xpertbot/craft-wheelform/issues/301#issuecomment-1889414754, and it works prefectly both ways (normal DB-setup and our cluster setup). Can you please take another look into this. It would realy help us forward. Best regards, Jan

holiday-jan avatar Mar 28 '24 14:03 holiday-jan

I'll take another look and deploy a fix if appropriate.

xpertbot avatar Mar 28 '24 14:03 xpertbot

Any progress on this?

I tested the code above both ways, and it works as expected. So if you please could consider a fix, it would helps us in the future with new projects.

holiday-jan avatar Apr 18 '24 12:04 holiday-jan