grid format images all broken after upgrade from moodle 1.9 to 2.2

grid format images all broken after upgrade from moodle 1.9 to 2.2

by Fred Yankowski -
Number of replies: 8

I'm testing an upgrade of our Moodle site from 1.9.10 to 2.2 (and from there to 2.5). After completing the upgrade to 2.2 all images for the grid format display as broken; each such image URL results in a 404 HTTP response.  Other files and images in the site work fine after the upgrade.  What might be causing this?  Is this an upgrade that should work?

We are starting from moodle 1.9.10 (Build: 20101025), grid version 2010080101 (commit 15960662cbb95ed98d69ff0ecb48f2ebe67c3829 in git).  Grid works fine here.

I then upgrade to the latest moodle 1.9 version, 1.9.19+ (Build: 20130513), with the same version of grid.  Grid display in courses works fine after this upgrade.

I then upgrade to moodle 2.2.  Details to follow.

Average of ratings: -
In reply to Fred Yankowski

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Fred,

I started work on the format with Julian well after the Moodle 1.9 version was released.  Please give me a little time and I'll see what I can find out.

Cheers,

Gareth

In reply to Fred Yankowski

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Fred Yankowski -

After getting our moodle system to 1.9.19+ as above I then update the moodle code to version 2.2.11 (Build: 20130708) and courses/format/grid to version 2.2.2 (2012042301). Then I run upgrade.php. The resulting site works fine except that all the grid images are broken.

I just recreated the problem with a from-scratch moodle system.

  1. Build a new moodle instance on moodle 1.9.19+ and grid version 2010080101.
  2. Create a new course with grid format. Change the image for topic 1, uploading an image file.
  3. Update the moodle code to version 2.2.11 and grid version 2.2.2 as above. Run the upgrade.php script.

The result is the same as for my legacy system: the grid image is broken.

In reply to Fred Yankowski

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Fred Yankowski -

An example SRC URL for a grid image that fails looks like .../pluginfile.php/10/course/section/2/SummerIMSA.png.  Watching the code I see that file_storage::get_file(10, course, section, 2, /, SummerIMSA.png) is called and (in a convoluted manner) looks for a matching entry in the 'files' table and does not find one, resulting in a file_not_found.

The files table does have a row for the SummerIMSA.png file but its field values look like this (as would appear in a get_file() call:  (10, course, legacy, 0, /icons/, SummerIMSA.png).

If I now set a grid image for topic 2 it works and gets a row in the files table like this (per above):  (10, course, section, 3, /, foo.png).

So it seems like the upgrade left the grid image file in the legacy/icons area and did not give it the right 'files' entry as expected by the grid layout.

In reply to Fred Yankowski

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Fred,

Yes I can replicate the issue and it looks like in M2.2 that the function 'upgrade_migrate_files_course' in '/lib/db/upgradelib.php' is doing something with the course files that it does not know what to do with.

I don't have a code solution.  But I think the solution will be to provide an update mechanism in M2.2+ that moves images from the 'icons' folder in the 'legacy' area and regenerates the image in the right place.  However there is a perceived issue that the 'itemid' is no longer the section id (as in the 'id' attribute of the 'course_sections' table) and hence no way of fixing this as that is required to know what section the image belongs.

Also, I only fixed the backup and restore code in M2.2 as previously it was broken.  And looking at the M1.9 code it has no backup code.

So the only solution I can think of at the moment is to alter the way 'upgrade_migrate_files_course' works so that the damage is not done - but I'm not sure how to do this yet - possibly looking at the data in the M1.9 version and going from there to detect the images and set the correct properties for '$fs->create_file_from_pathname'.

Gareth

In reply to Gareth J Barnard

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Fred Yankowski -

Gareth, thank you so much for looking into this. This grid layout problem is a show-stopper for me as we have 32 highly-visible courses using it (comprising 307 grid images) and important users/stakeholders in our moodle community really want the grid layout to continue to work.  (It's very popular with our more technically savvy teachers).

I will investigate the upgrade_migrate_files_course function to see if I can help solve the problem. I am new to Moodle internals and unfamiliar with the Moodle 2 file scheme so it's slow going.  The upgrade.php function takes 2.5 hours to run over (a copy of) our production system so each test against our real data is expensive.

In reply to Fred Yankowski

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Fred,

I re-ran the process and noticed that I may have enough information upon which to write a conversion script at the M2.2 stage.  I'll let you know how I get on.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Fred,

Ok, I think I have a solution script that converts the images.  If you look at the bottom of the 'readme.txt' on: https://github.com/gjb2048/moodle-courseformat_grid/tree/Upgrade_Image_M22 you will find instructions on how to use the script.  Then get the two files: 'convert_legacy_image.php' and 'gdlib_m25.php' and put them in your Moodle 2.2 version of the grid format folder so that you can proceed with the instructions.

Please in the first instance try this on a 'test' upgrade.  I've only run the script once on an installation with one course.  The script is designed to convert all courses.

EDIT: Script updated after running with two courses.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: grid format images all broken after upgrade from moodle 1.9 to 2.2

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Fred,

I've just updated the script to deal with the logging issues you were having though the addition of a 'logverbose' parameter.  I've also tested with two courses containing some identical images in the same section numbers including '0' and it works.

Cheers,

Gareth