Comments (4)
As well as updating the elements_sites
table, you will also need to change the site ID for the relevant Neo block structure(s). Since you're running Craft 3, this will involve updating the ownerSiteId
value for the relevant rows in the neoblockstructures
table (on Craft 4 and later, the column is just called siteId
).
Both of these could be achieved using code based on the following as part of your event handling code:
$blockIds = \benf\neo\elements\Block::find()
->ownerId($element->id)
->siteId(11)
->ids();
$this->update(
'{{%elements_sites}}',
[
'siteId' => 53,
],
[
'siteId' => 11,
'elementId' => $blockIds,
]
);
$this->update(
'{{%neoblockstructures}}',
[
'ownerSiteId' => 53,
],
[
'ownerSiteId' => 11,
'ownerId' => $element->id,
]
);
Please let me know if you have any issues while making these changes.
from craft-neo.
Thanks for your answer @ttempleton !
1.) I tried it, both table rows in elements_sites
and neoblockstructures
are updated in the way I would expected it, but still the Neo blocks do not appear when I edit the owner entry in the CMS. The Neo field does not contain any blocks in edit mode.
2.) And because I would like to understand it: Why does moving the blocks work with Neo if I resave via Craft's console command? Isn't this the same as the resave service I use in the migration?
Below is the adapted content migration with your code, slightly modified with $this
/ $thisClone
:
public function safeUp()
{
$elementsService = Craft::$app->getElements();
$entryQuery = Entry::find()->siteId(11)->id(118464); //
$thisClone = $this;
$elementsService->on(
\craft\services\Elements::EVENT_BEFORE_RESAVE_ELEMENT,
static function(\craft\events\BatchElementActionEvent $e) use ($entryQuery, $thisClone) {
if ($e->query === $entryQuery) {
$element = $e->element;
$element->siteId = 53;
$element->sectionId = 36;
$blockIds = \benf\neo\elements\Block::find()
->ownerId($element->id)
->siteId(11)
->ids();
$thisClone->update(
'{{%elements_sites}}',
[
'siteId' => 53,
],
[
'siteId' => 11,
'elementId' => $blockIds,
]
);
$thisClone->update(
'{{%neoblockstructures}}',
[
'ownerSiteId' => 53,
],
[
'ownerSiteId' => 11,
'ownerId' => $element->id,
]
);
}
}
);
$elementsService->resaveElements(
$entryQuery,
true,
true
);
}
There must be something else which needs to be updated. How does the resave console command make it work?
Our Neo blocks are nested, does this cause any additional problems?
Thanks!
from craft-neo.
Whoops, I forgot about needing to update the content
table as well:
$thisClone->update(
'{{%content}}',
[
'siteId' => 53,
],
[
'siteId' => 11,
'elementId' => $blockIds,
]
);
Regarding the resave/entries
console command - it does also internally use $elementsService->resaveElements()
, but it did not move over any Neo blocks in my testing (or any Matrix blocks, for that matter), so I'm not sure why it worked in your case.
from craft-neo.
Thanks again, this is working now. We also needed to move Matrix in NEO fields as well, but since we had your code, that was easy.
Btw: the resave/entries console command does move NEO blocks and Matrix as well, this would have been our fallback. But since it needs to be done manually, we prefer the migration.
from craft-neo.
Related Issues (20)
- Error trying to propagate Neo field after updating translation settings HOT 2
- Neo Not Saving Changes to Field Layout HOT 2
- Exponential increase of blocks when adding an existing entry to another site HOT 5
- [Craft 5] Allow Neo fields to be reusable in field layouts HOT 1
- How to approach eager-loading in Craft 5 HOT 4
- Neo block queries return duplicate child blocks HOT 8
- [Craft 5] Action Menu won't open after a new Block is added HOT 3
- Craft keeps showing "Unsaved Changes" upon saving of an entry with Neo fields HOT 1
- Getting Invalid Field Layout Error in CP HOT 1
- Copy / Paste of Neo Blocks HOT 1
- Javascript Error When Trying to Add a Block in Neo HOT 2
- Settings menu for fields in the layout designer not opening in Craft 5 HOT 2
- benf\neo\elements\Block::useMemoized(): Argument #1 ($use) must be of type Illuminate\Support\Collection|array|bool, benf\neo\elements\db\BlockQuery HOT 1
- Conditional asset fields not saving values after switching condition HOT 1
- [5.x] Error after changing field handle: Field is not included in the available field layouts HOT 5
- Entries from another site can be selected in the back end, but they are not output in Twig templates. HOT 2
- Entry condition applied even for single pages HOT 3
- Duplicate entries appear in `orders` yaml files when deleting block types HOT 1
- Infinite loop in the cms. Auto saving the draft before the entry is manually saved causes the loop HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from craft-neo.