verbb / super-table

Super-charge your Craft workflow using Super Table.
MIT License
317 stars 47 forks source link

Super Table inside Matrix Not Propagating Content (multisite) #366

Closed GrayAnchor closed 4 years ago

GrayAnchor commented 4 years ago

Description

Super Table fields inside Matrix blocks are not propagating content automatically to new sites. To be clear, all other field types in Matrix blocks, and even Super Table fields that are not in Matrix blocks are behaving as expected and propagating content automatically to new sites.

The current work around is this: after new sites are added, update the Super Table fields' content in the Matrix blocks in the default/english site (even just adding a blank space after some text works), and then save the entry. This causes the newly updated fields to propagate content to the new sites. However, this is a lot of additional work for large sites(in my case), and isn't a solution.

Resaving entries via craft CLI doesn't solve this issue, and neither does resaving Matrix blocks via CLI.

Also note (if this info helps at all), content in these fields is missing completely, even in fields that are required and have a default value set. For example, I have 'options' fields using buttonbox plugin with default text values set for alignment and image display, but the fields are empty on the new site, and do not use the default values.

I experience the same issue with plugin ver 2.4.5 and Craft ver 3.4.1

Steps to reproduce

  1. Create a single site, and load content into a Super Table field in a Matrix block. Be sure Matrix and blocks are set appropriately to propagate content across sites.
  2. Add new sites.
  3. See content is missing in Super Table in Matrix blocks on new sites.

Additional info

Please help ¯_(ツ)_/¯

I will provide more info for anyone interested. Just let me know what you want to see. Thanks!

GrayAnchor commented 4 years ago

I've updated for clarity and added more details. Please let me know if more info is needed and I will gladly update it. Thanks!

darylknight commented 4 years ago

Just had this issue on a site I made translatable too. Added Spanish to an English site, everything except Super Table inside the main Matrix field got copied over but the Super Table fields inside Matrix are empty.

image

Related: if you add multi-site (spanish) to a site that used to only have one site (english), then Super Table will clear the blocks on the new site (spanish). When you add blocks to the new site (spanish), they'll be added to the old site (english), but the old blocks will all still be there. Updates to the old blocks won't affect the blocks on the new site until you delete the entire thing and add new blocks, which then behave correctly in both sites. (English/Spanish labels added to help me explain it, actual languages aren't relevant)

GrayAnchor commented 4 years ago

Glad I'm not the only one seeing this issue. @darylknight what version of Craft and Super Table are you running?

darylknight commented 4 years ago

Craft 3.4.23 and Super Table 2.5.1.

I may post another issue about this, although I can't reliably replicated it, but it looks like something might have changed recently that's causing major issues with Super Table inside Matrix fields generally. I added a simple toggle switch to Super Table inside a Matrix field yesterday and it deleted all of the content in that field on every page it was used including all the revision history. Caused me a major headache.

GrayAnchor commented 4 years ago

I rolled back to Super Table 2.4.5 and Craft 3.4.1 and experienced these issues, so I wonder when this started happening. I guess the next step is to keep rolling back Super Table to older versions until it works as expected. I just hope it has worked at some point and hasn't always been this way.

Daryl, do you know what version of Super Table you created your fields in originally? I created the original site in Craft 3.3 with Super Table 2.3.0, before upgrading to Craft 3.4. I'm wondering if the version of Super Table the fields were created with still affects them now, even after updating. Just a theory since I'm out of ideas.

Not sure what this means or if it's relevant, but here's what I get when I run the tool in the Super Table settings. It 'fixed' these issues, but the errors show up again after running 're-save fields':

image

darylknight commented 4 years ago

Josh if you're able to reply as to whether you're aware of the issues with this and when it might be fixed that'd be great. I've just had a previous client contact us about adding Spanish to a website we built a couple of years ago with over a thousand entries, and at the moment my answer's going to have to be that we can't because the plugin that most of the site's content sits in has a bug with adding translation.

It was ok when I translated a 5-page site and had to re-add all the super table blocks by hand, but I can't do that on a site of this size.

engram-design commented 4 years ago

I'm aware of the issue @darylknight but I haven't had the time to investigate yet. Will do so as soon as I can.

darylknight commented 4 years ago

Got it, thanks Josh!

GrayAnchor commented 4 years ago

Thanks, Josh! It will be very good news for us when this is resolved. A big multi-language rollout is on hold until then.

mildlygeeky commented 4 years ago

We're in a similar boat right now (this, as well as issues @arthurdewolf mentioned on another ticket around propagation) — thanks Josh!

ghost commented 4 years ago

We have been concerned about this issue for a month. Now, We can't add data for fix the lost data, Because if added data for new site, Other site will lost them or double them, We tried change the Propagation Method of fields, But queue will stuck, Below is the logs. `2020-07-16 03:10:11 [-][-][-][error][craft\queue\QueueLogBehavior::afterError] [49608] Applying new propagation method to Matrix blocks (attempt: 1) - Error (time: 0.359s): Attempting to duplicate an element in an unsupported site. 2020-07-16 03:10:11 [-][-][-][error][yii\base\Exception] yii\base\Exception: Attempting to duplicate an element in an unsupported site. in /data/webroot/craft3/vendor/craftcms/cms/src/services/Elements.php:767 Stack trace:

0 /data/webroot/craft3/vendor/craftcms/cms/src/queue/jobs/ApplyNewPropagationMethod.php(98): craft\services\Elements->duplicateElement(Object(craft\elements\MatrixBlock))

1 [internal function]: craft\queue\jobs\ApplyNewPropagationMethod->craft\queue\jobs{closure}(Object(craft\events\BatchElementActionEvent))

2 /data/webroot/craft3/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(craft\events\BatchElementActionEvent))

3 /data/webroot/craft3/vendor/craftcms/cms/src/services/Elements.php(570): yii\base\Component->trigger('beforeResaveEle...', Object(craft\events\BatchElementActionEvent))

4 /data/webroot/craft3/vendor/craftcms/cms/src/queue/jobs/ApplyNewPropagationMethod.php(109): craft\services\Elements->resaveElements(Object(craft\elements\db\MatrixBlockQuery))

5 /data/webroot/craft3/vendor/yiisoft/yii2-queue/src/Queue.php(246): craft\queue\jobs\ApplyNewPropagationMethod->execute(Object(craft\queue\Queue))

6 /data/webroot/craft3/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('49608', 'O:42:"craft\que...', '54000', '1')

7 /data/webroot/craft3/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('49608', 'O:42:"craft\que...', '54000', '1', NULL)

8 [internal function]: yii\queue\cli\Command->actionExec('49608', '54000', '1', '0')

9 /data/webroot/craft3/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

10 /data/webroot/craft3/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)

11 /data/webroot/craft3/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('exec', Array)

12 /data/webroot/craft3/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('exec', Array)

13 /data/webroot/craft3/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)

14 /data/webroot/craft3/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('queue/exec', Array)

15 /data/webroot/craft3/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)

16 /data/webroot/craft3/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))

17 /data/webroot/craft3/craft(22): yii\base\Application->run()

18 {main}

2020-07-16 03:10:12 [-][-][-][error][craft\queue\QueueLogBehavior::afterError] [49609] Applying new propagation method to Super Table blocks (attempt: 1) - Error (time: 0.584s): Attempting to duplicate an element in an unsupported site. 2020-07-16 03:10:12 [-][-][-][error][yii\base\Exception] yii\base\Exception: Attempting to duplicate an element in an unsupported site. in /data/webroot/craft3/vendor/craftcms/cms/src/services/Elements.php:767 Stack trace:

0 /data/webroot/craft3/vendor/craftcms/cms/src/queue/jobs/ApplyNewPropagationMethod.php(98): craft\services\Elements->duplicateElement(Object(verbb\supertable\elements\SuperTableBlockElement))

1 [internal function]: craft\queue\jobs\ApplyNewPropagationMethod->craft\queue\jobs{closure}(Object(craft\events\BatchElementActionEvent))

2 /data/webroot/craft3/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(craft\events\BatchElementActionEvent))

3 /data/webroot/craft3/vendor/craftcms/cms/src/services/Elements.php(570): yii\base\Component->trigger('beforeResaveEle...', Object(craft\events\BatchElementActionEvent))

4 /data/webroot/craft3/vendor/craftcms/cms/src/queue/jobs/ApplyNewPropagationMethod.php(109): craft\services\Elements->resaveElements(Object(verbb\supertable\elements\db\SuperTableBlockQuery))

5 /data/webroot/craft3/vendor/yiisoft/yii2-queue/src/Queue.php(246): craft\queue\jobs\ApplyNewPropagationMethod->execute(Object(craft\queue\Queue))

6 /data/webroot/craft3/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('49609', 'O:42:"craft\que...', '54000', '1')

7 /data/webroot/craft3/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('49609', 'O:42:"craft\que...', '54000', '1', NULL)

8 [internal function]: yii\queue\cli\Command->actionExec('49609', '54000', '1', '0')

9 /data/webroot/craft3/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

10 /data/webroot/craft3/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)

11 /data/webroot/craft3/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('exec', Array)

12 /data/webroot/craft3/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('exec', Array)

13 /data/webroot/craft3/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)

14 /data/webroot/craft3/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('queue/exec', Array)

15 /data/webroot/craft3/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)

16 /data/webroot/craft3/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))

17 /data/webroot/craft3/craft(22): yii\base\Application->run()

18 {main}`

So I think may be Matrix of Craft CMS causing the this problem. Also, Hi @brandonkelly Could you help me?

taylordaughtry commented 4 years ago

@engram-design Hey! Have you had the chance to check out this issue just yet? (Any rough timeframe for when you might, days, weeks, or months?)

Just want to get an idea for our planning; it's currently blocking a major translation release for a client project in production.

mildlygeeky commented 4 years ago

Same here - pinging @brandonkelly (as recommended by @andris-sevcenko) as well in case this may be a regression based on a recent Craft update. Right now we have two site builds that are on pause due to this and #357, which are both around propagation rules.

engram-design commented 4 years ago

Working on it this weekend all, will update as soon as I can with my findings.

engram-design commented 4 years ago

@darylknight I'm keen to hear more about your issue. You mentioned you had a single site, but then adding another. Did you check all your Super Table/Matrix fields first after adding it? For instance, multi-site settings won't appear on a single site. I'll do my best to replicate this, but I also think its a separate issue.

For people with an issue on content inside a Super Table field nested in a Matrix field, I have a temporary workaround. Temporary because it might need to be changed to make Super Table > Matrix combinations (the other way around) work.

To get the fix early, change your verbb/super-table requirement in composer.json to:

"require": {
  "verbb/super-table": "dev-craft-3 as 2.5.1",
  "...": "..."
}

Then run composer update. If Craft isn't up to date, also make sure it is

taylordaughtry commented 4 years ago

@engram-design Hey! Would your workaround also be possible for Neo fields? We have a similar issue with Super Table fields in a Neo field not propagating. (I can make some quick replication steps if you need them!)

engram-design commented 4 years ago

@taylordaughtry It won't, but I can add a case for that, which I've just done so in the latest craft-3 branch. You can update using the above method

kylecotter commented 4 years ago

Hi @engram-design,

Commenting on your temporary workaround, I can confirm the above update solves the Neo and Matrix -> Super Table propagation issue I was getting on a project, but that Super Table -> Matrix propagation still isn't working.

Thanks!

engram-design commented 4 years ago

@kylecotter Just to confirm, your issue is an outer Super Table field, and an inner Matrix field? If that's the case, then I'm aware of this, and it can only be fixed from Craft's end.

The reason here is that https://github.com/craftcms/cms/blob/develop/src/fields/Matrix.php#L960 - Matrix and Super Table are testing isFieldDirty() on the parent element. For top-level fields, this is the Entry (or whatever element its on). For nested fields, this is the respective field blocks around it.

This issue is that inner fields are not being marked as dirty, and therefore not re-saving. I've managed to include a temporary workaround for Super Table, by checking if its contained in a Matrix or Neo field, but that's not ideal.

I'd need to chat with @brandonkelly about how to better handle the isFieldDirty() issue.

kylecotter commented 4 years ago

@engram-design yep, that's my use case. Makes sense! Thanks for the explanation!

engram-design commented 4 years ago

Thanks to @brandonkelly this should be fixed in Fixed in 2.5.2 and https://github.com/craftcms/cms/commit/1c72e36145bf913eba6dfacf3758a405d3b18513