Hugo Barona
Hugo Barona

Reputation: 1398

Kentico 10 - Web Part content change via database

i was trying to understand in the Kentico's database model how can i change the web parts content using a database script.

So, basically i have a website based on Kentico with several articles, and internal hyperlinks in its content. But the problem is that the format of those hyperlinks are actually invalid. And i was looking for a way to build a script and do a bulk-update in order to replace some characters and update those hyperlinks to the valid format.

Any idea how can i build the query to get the content of all web parts used in all published pages.

Thank you

Upvotes: 0

Views: 260

Answers (2)

mnield
mnield

Reputation: 1869

It depends on your web parts and how the content is rendered. There are different ways that web parts render their content:

  • The web part layout is used for markup
  • The ASCX file for the web part is used for markup
  • The web part makes use of a repeater that uses a Transformation to render the markup- The markup is generated in code behind

The last one can be tricky to change depending on the web part and whether you have access to all the code behind, but the others you can change either in code in your solution or within the Administration area itself.

Doing this in SQL would probably require a combination of T-SQL XML support and regular expressions to find what you're looking for. you effectively need to look in the CMS_WebPart and CMS_WebPartLayout tables to find what you're looking for.

However, reading your query, I'm not 100% sure you're talking about web parts, (my apologies if you are) as you talk about links in the article content itself. If these are set using the Editable text web part, then you need to look in the CMS_Document table at the DocumentContent field to find the links to replace. But you then need to look at how to correctly format those links going forward so that you do not need to repeat this process later.


Note:

  1. You need to be really careful when doing this in SQL to make sure that you don't create invalid XML. Things go bad when you do that.
  2. This won't flush your cache, so you'll need to clear your cache manually afterwards.
  3. If you're using out-of-the-box web parts, you should really make a copy of them and use the copy if you're going to modify, this way, you're less likely to have pain in future upgrades.

Upvotes: 2

Brenden Kehren
Brenden Kehren

Reputation: 6117

Typically "content" is not set in a webpart. Webparts are configured to retrieve content from page types. There is an exception to this with specific webparts like Editable Text, Static Text, Static HTML, etc.

The configuration of a webpart is stored at the template level in the cms_pagetemplate table. The configuration for ALL webparts on that page template are stored in the PageTemplateWebParts field. So you'd have to parse through the XML and get the proper webpart and then perform an update on that field. You maybe able to do a regex to find that content and replace it as well.

Not ideal to do this via SQL simply because of version history and it can cause a lot of problems later on. I'd suggest finding out which API calls you can make to perform these updates and write a small program for it.

Upvotes: 1

Related Questions