Book import - hard-links on images

Book import - hard-links on images

by Daniel Schimrik -
Number of replies: 11

Hello,

I have a problem importing courses with book module. The courses itself work well, all content and all images are working (links have changed to new course id).

But all images included in books seem to be hard-linked to the original course, and therefore not displayed for students (they are not enrolled in the original course).

I am running Moodle 1.9.9 and book 1.5beta.

Regards,
Daniel

Average of ratings: -
In reply to Daniel Schimrik

Re: Book import - hard-links on images

by Rose Brandt -

We are facing the same problem. This limits the usefulness of books in our course sites, which are copied (with imported content) for each semester. The links on the home page are updated, but not those in the books. Has anyone found a workaround so that the code for each link doesn't have to be individually updated each time the site is copied?

In reply to Rose Brandt

Re: Book import - hard-links on images

by Daniel Schimrik -

Hello,

I have noticed that this link-issue is not directly related to the book module (only).
The created links inside my books have been created using the build-in Moodle Editor. Some look like "../../file.php?" instead of the full path. These ../../-style links are the problem.

It seems that it has been an Editor bug during the time I have created my books, but it looks like it has been fixed later (newer books are working fine).

My solution was to modify each link of a book to the format "http://mymoodle.tld/file.php/course-id/file" which works find during backup-restore and import.
But this does not work well using the Moodle-Editor because it tries to set the links back to the ../../-style. You have to do it manually (disable the editor inside your profile).

Regards, Daniel

In reply to Daniel Schimrik

Re: Book import - hard-links on images

by Rose Brandt -

Thanks for the workaround! When you say that the editor tries to set the links back, do you mean that it changes the code each time you resave the page? Or can you just manually code the link once and it will stay that way even if you edit the page again later?

In reply to Rose Brandt

Re: Book import - hard-links on images

by Daniel Schimrik -

I tried the following three possibilites:

  • Change the link by using the editors image icon -> editor changed back to old layout
  • Change the link by using the editor HTML-icon -> worked sometimes, sometimes not (don't know why)
  • Disable the editor in my profile and change each link in source code -> worked fine
In reply to Daniel Schimrik

Re: Book import - hard-links on images

by Rob Johnson -

There is a find and replace script for changing things like this in the database.  Go to http://yourmoodle/admin/replace.php.  You can replace src="http://www.oldmoodle with src="http://www.newmoodle.

You need to have admin access to do this, and I would backup the database first. ;)

In reply to Rob Johnson

Re: Book import - hard-links on images

by Daniel Schimrik -

Thank you for this info. I haven't noticed this script so far.

A backup of the database before using this script is very recommended.

In reply to Daniel Schimrik

Re: Book import - hard-links on images

by E. L. Cooper -

I have a couple of books that I use over and over and for those I have a folder called bookimages that is not part of the moodle structure- just setting in the schools current theme folder and I link to them there.

In reply to E. L. Cooper

Re: Book import - hard-links on images

by Kevin Brake -

I have a similar issue maybe someone could help!

I can backup my Moodle Book and Restore my Moodle Book, the problem is that the restored book still refers back to questionaires and activities that are located in the previous version.

...but the restore does create a copy of the questionnaire for example.

view.php?id=31392 <- Here is a new id for the restored questionnaire

view.php?id=30394 <- Here is the link to the one in the orginal version

I have full path links to similar questionnaires throughout my Moodle Book.

http://mymoodle.com/mod/questionnaire/view.php?id=31392

The problem is that the links are not updating inside the source of the Moodle Book.  It is just keeping the link that was orginally created for the orginal Moodle Book.

Any ideas would be great.

Thanks,

Kevin

In reply to Kevin Brake

Re: Book import - hard-links on images

by E. L. Cooper -

I use book a lot and I transfer it around a whole bunch so I know exactly what you are talking about. What I do is-

  1. back up the class into gift format and unselect everything but the book I am  moving- no groups no users no grades no assigned roles- including course and site files if any are used in the book.
  2.  download the backup that was created then unzip it Inside the folder is a file called moodle.php. I open that file with my preferred code editing software (I use scrripty which is free http://scriptly.webocton.de/index.php?cid=9&sid=34 but use what ever you want)
  3.  hit CTL-F and copy the URL of the old course for  example -  http://mydoman.com/moodle/course/view.php?id=39
  4. Then I replace all with the url for the course I am moving  everything to
    http://adifferentdoman.com/moodle/course/view.php?id=16
    Of course you have to have already created the new course and get the course URL from there.

Since your issue is specifically questionnaires I would do a similar search and replace for the old hard path and the new hard path.

Of course you will need to have already created the questionnaires in the new course.

Then I save my changes overwriting the moodle.pho in my unzipped folder. Make my unsipped folder into a new zip with a new name- upload that zip into the new class and restore it selecting adding data to current class.

Average of ratings: Useful (1)
In reply to E. L. Cooper

Re: Book import - hard-links on images

by Kevin Brake -

Thanks for providing your assistance:

You mentioned:

Of course you will need to have already created the questionnaires in the new course.

------

The questionnaires are recreated during the restore, however the questionaires have new ids.  As well the new ids are not updated in the Moodle Book instead inside the book the questionaire links still link back to the orginal version of the backed up course.

I have already gone through the entire course and have removed the relative path (../../) and replaced it with an absolute path (http://mymoodle.com/).

So the paths are carried over and the questionairres are recreated.  But the book does not change the links from the old questionairres found in the orginal backup.

I was not able to solve my issue by following your instructions.

Kevin

In reply to Kevin Brake

Re: Book import - hard-links on images

by E. L. Cooper -

Did you search and replace the links in the book backup before restoring it?