Help!!! How to fix the restore broken image/video links

Help!!! How to fix the restore broken image/video links

by Andy An -
Number of replies: 5
I have just restore a course from its backup to a new one and find that the image/video links inserted in the book/chapters are broken since the moodldata folder id #  is changed from /32/ to /62/. it means I have to replace all the id# in the broken code like "../file.php?file=/32/" to"../file.php?file=/62/" all over thousands of pages. I am sure there is one quick way instaed of do it manually.
Thanks for any suggestions.
Average of ratings: -
In reply to Andy An

Re: Help!!! How to fix the restore broken image/video links

by David Banach -
Hi Andy,

I've had this problem too. I'm something of an mMYQL newbie, so I'm sure others here could give better advice, but I do know that it is possible to do a search and replace both within MYSQL from the command line or from phpmyadmin. Backed up or dumped databases are also just text files. You can search and replace within the queries using a good text editor. I've done this a few times and it worked out OK, but it can be a little risky if you aren't careful. ALWAYS MAKE A BACKUP.

My other idea is just to make a copy of all the files in the current folder into your moodledata/32 folder if the old course is still there and open to guests. Unless there are permission issues, it may be a lot easier. than editing all those links. Does anyone know of any issues with this? I know that if the courseid doesn't exist you will get an error when you try to access files in the folder. I imagine there might be ways of getting around this, but I haven't had to try them yet.

Someone else here, undoubtedly, will be able to give you better advice, but until you hear from them, that is my two cents worth. (and I don't offer a money back gaurantee even on that)  grin

Good Luck

Let us know if you find a good solution.
There are a number of threads active on this because of problems with restore not preserving links.

David
In reply to David Banach

Re: Help!!! How to fix the restore broken image/video links

by James . -
Not all content in the backup files is plain text - the content of some blocks, like the HTML one, is compressed.

You'll miss occurrences in this non-plain content if you do a strait search/replace over the backup file.

In reply to James .

Re: Help!!! How to fix the restore broken image/video links

by David Banach -

Thanks James

I didn't know that.

Have you found anyway of fixing links in the html blocks all at once?

David
In reply to David Banach

Re: Help!!! How to fix the restore broken image/video links

by James . -
Unfortunately, no. 

If anyone does find out how to encode in-course links within HTML blocks in such a way as to make them survive through a backup/restore then I'd be ver interested in knowing it.
In reply to Andy An

Re: Help!!! How to fix the restore broken image/video links

by James . -
If you specify the URL as a full url, in the form
   http://YOURMOODLEDOMAIN/file.php/COURSEID/etc/etc.gif

Then when you backup and restore the process will be able to replace the YOURMOODLEDOMAIN with the new domain and the old COURSEID with the new COURSEID.

A couple of provisos: 
 - you must make the YOURMOODLEDOMAIN exactly match the value specified in the moodle site config.
 - This doesn't work in all places, for example within HTML blocks (an issue that's bugging me at the moment).  It does work in books though.