Jump to content

Broken Links inside WYSIWYG (urgent)


Orkun
 Share

Recommended Posts

Hi Guys

I had some Branches with some childrens and grandchildrens. I had to change the Page Name of the 'RootParents' to a more unique name because of the Multisite Modul I am using. So I have renamed the pagename. But now I have discovered some broken links inside the Textareas(WYSIWYG). I tought the Page Path History Core Module would take care of all the links inside WYSIWYG Editors/Textareas but it looks like it hasn't. What should I do now? Do I need to manually change all the Links inside the WYSIWYG/Textares?? This is very urgent.

Greetings

Nukro 

Link to comment
Share on other sites

I think the best option might have been the link abstraction feature in the textarea field, although I agree that Page Path History should also have taken care of it - is it definitely installed? Are there entries for the changed pages in the "page_path_history" db table?

Screen Shot 2017-01-31 at 7.00.46 AM.png

One possible way to fix this now would be to use the "Field Set Or Search And Replace" action from the AdminActions module. That will allow you to easily search and replace the old link with the new link in the required textarea fields.

  • Like 1
Link to comment
Share on other sites

10 minutes ago, adrian said:

I think the best option might have been the link abstraction feature in the textarea field, although I agree that Page Path History should also have taken care of it. Are there entries for the changed pages in the "page_path_history" db table?

Screen Shot 2017-01-31 at 7.00.46 AM.png

One possible way to fix this now would be to use the "Field Set Or Search And Replace" action from the AdminActions module. That will allow you to easily search and replace the old link with the new link in the required textarea fields.

Hi @adrian

I have looked inside the 'page_path_history' table and it looks like, that the changed pages are there (the old url as entry). Looks like this 'link abstraction feature' of textareas is only available in 3.x Version of PW. So my last option is probably your AdminActions Module with the 'Field Set Or Search And Replace' option you mentioned. I will dump the database and try you module on localhost. Thanks for your help @adrian.

Link to comment
Share on other sites

3 minutes ago, adrian said:

That might be an issue with PW 2.x

Can you please try replacing :


$tab = $this->wire(new InputfieldWrapper());

with:


$tab = new InputfieldWrapper();

 

Ok thanks, it's working now

Link to comment
Share on other sites

I have now tried the field and replace feature. This isn't working somehow or I am doing it wrong.

 

Lets say I have this url inside an textarea:

<a href="https://test.ch/example.com/test1/test11/">test</a>

and want to replace it like this:

<a href="https://test.ch/example.ch/test1/test11/">test</a>

 

Do I need to add this inside the search: example.com or /example.com/ ?

Do I need to add this inside the replace: example.ch or /example.ch/ ?

Link to comment
Share on other sites

2 minutes ago, adrian said:

I would leave off the "/" completely as that will trigger the replace to use preg_replace, rather than simply str_replace so I would go with example.com and example.ch

I had tried both and somehow it hasn't worked?

Link to comment
Share on other sites

16 minutes ago, adrian said:

I just tested that exact replacement on your source and it works fine here. Are you sure the "Selector" field is correctly finding the required pages that you want the replacement made on?

Is it possible that it doesn't work when the textarea fields are inside an repeater or are multilanguage fields?

Link to comment
Share on other sites

10 minutes ago, Nukro said:

Is it possible that it doesn't work when the textarea fields are inside an repeater or are multilanguage fields?

Yeah, it won't work with repeater fields because it won't target the repeater first and then it's subfield. I will need to make some changed to make it work with repeaters.

You're best bet for the moment will be to go with raw SQL, eg:

UPDATE field_body SET data = REPLACE(data, 'example.com','example.ch');

You may need to do this for each multilanguage version of "data", eg "data1812" etc.

PS, this assumes that the name of the field is "body", which is stored in the "field_body" db table.

PPS - be sure you backup your db before running this :)

Link to comment
Share on other sites

2 minutes ago, adrian said:

Yeah, it won't work with repeater fields because it won't target the repeater first and then it's subfield. I will need to make some changed to make it work with repeaters.

You're best bet for the moment will be to go with raw SQL, eg:


UPDATE field_body SET data = REPLACE(data, 'example.com','example.ch');

You may need to do this for each multilanguage version of "data", eg "data1812" etc.

But this would perhaps replace all data of all pages that has this field am I right? 

Link to comment
Share on other sites

Just now, Nukro said:

But this would perhaps replace all data of all pages that has this field am I right? 

Yes - if you need to limit by pages, then you'll need a WHERE addition to the statement to check the pages_id - this could start getting complicated. You may need to build up an array of IDs of pages that match.

I guess the question is how many pages do you need to make this change on? Would manually doing it be easier at this point?

Link to comment
Share on other sites

6 minutes ago, adrian said:

Yes - if you need to limit by pages, then you'll need a WHERE addition to the statement to check the pages_id - this could start getting complicated. You may need to build up an array of IDs of pages that match.

I guess the question is how many pages do you need to make this change on? Would manually doing it be easier at this point?

No manually doing it would take to long. At the moment I am doing a preg_replace with your module like this:

/\/example\.com\// -> detects '/example.com/'

replace: '/example.ch/'

I have like 15 branches with up to 20-50 pages per branch..

I am using repeater a lot on the pages. damn.

Link to comment
Share on other sites

What's wrong my that SQL statement above - it will replace the contents of the field for all pages on the site, but isn't that what you want?

Again, you shouldn't need a regex for the AdminActions module - I tested with "example.com" and "example.ch" and it worked fine (obviously for normal fields, not repeater sub fields).

Link to comment
Share on other sites

30 minutes ago, adrian said:

What's wrong my that SQL statement above - it will replace the contents of the field for all pages on the site, but isn't that what you want?

Again, you shouldn't need a regex for the AdminActions module - I tested with "example.com" and "example.ch" and it worked fine (obviously for normal fields, not repeater sub fields).

Nothing is wrong with your SQL, I don't wanted to be disrespectfull, sry for that. I am just stressed about the situation that I need to do this.

I am using the regex, because I only want to match url-part inside an Link.

 

Thanks for your Help 

@adrian

Link to comment
Share on other sites

Just now, Nukro said:

Nothing is wrong with your SQL, I don't wanted to be disrespectfull, sry for that. I am just stressed about the situation that I need to do this.

No problem - just wanted to see if there was a reason not to use it.

1 minute ago, Nukro said:

I am using the regex, because I only want to match url-part inside an Link.

Ok, I guess there must be instances outside of the link where example.com exists and you don't want to replace - sorry I wasn't aware of that.

Link to comment
Share on other sites

3 hours ago, adrian said:

 


UPDATE field_body SET data = REPLACE(data, 'example.com','example.ch');

You may need to do this for each multilanguage version of "data", eg "data1812" etc.

You mean like that?

UPDATE field_body SET data1010 = REPLACE(data1010, '/brokenurl-name/','/newurl-name/'); // Default Language
UPDATE field_body SET data1234 = REPLACE(data1234, '/brokenurl-name/','/newurl-name/'); // second Language
UPDATE field_body SET data2345 = REPLACE(data2345, '/brokenurl-name/','/newurl-name/'); // third Language
UPDATE field_body SET data3456 = REPLACE(data3456, '/brokenurl-name/','/newurl-name/'); //fourth Language
...

Do I also need to set the ID for the default language?

Link to comment
Share on other sites

23 minutes ago, adrian said:

Yeah, I think that should work. The default language should be stored in the main "data" field.

Ok, I think I will try this out tomorrow... The only problem I have is, that I need to do this for 9 Fields in 5 Languages and for 16 broken url varieties per field:

5 x 16 = 80 - SQL Queries per Field in 5 languages

80 x 9 = 720 - SQL Queries in Total for 9 Fields

:( Why always me? Anyway I'm very thankfull to you @adrian for your help you provided :)!

PS: If you have suggestions to make multiple REPLACES in one query I would like to know it ;)

Greetings

Nukro

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...