Moodle
  1. Moodle
  2. MDL-3344

Restore course from Bb doesn't play nice with PHP5 libxslt -- workaround included

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: None
    • Component/s: Backup
    • Labels:
      None
    • Environment:
      All
    • Affected Branches:
      MOODLE_15_STABLE
    • Rank:
      10842

      Description

      PHP 5 distributions no longer ship with the XSLT module that is required for restoring Blackboard courses into Moodle. It has been mostly superceded by the XSL module.

      Not wanting to have to go to PECL and fuss with getting the XSLT module from there (along with installing Sablotron, etc.), I wrote an include file that will conditionally install emulation versions of xslt_create and xslt_process using the XSLTProcessor() class in PHP 5.

      Below is a patch that:

      1) Adds backup/bb/xsl_emulate_xslt.inc which creates emulation versions of xslt_create and xslt_process

      2) Modifies backup/bb/restore_bb.php to require() the new include file

      3) Adds <xsl:output method=xml encoding=UTF-8 /> to backup/bb/bb*_to_moodle.xsl so emulated output has the correct encoding and parses properly in backup/restorelib.php:restore_check_moodle_file()

      This has NOT been tested against an installation that still has sablotron XSLT as I don't have access to one, but theoretically will still work.

      I apologize for the odd paths – this isn't from a CVS build

      diff -wur --new-file /var/www/moodle/backup/bb/bb5.5_to_moodle.xsl bb/bb5.5_to_moodle.xsl

      — /var/www/moodle/backup/bb/bb5.5_to_moodle.xsl 2005-02-07 23:19:49.000000000 -0800

      +++ bb/bb5.5_to_moodle.xsl 2005-05-26 12:47:01.000000000 -0700

      @@ -1,6 +1,7 @@

      <?xml version='1.0'?>

      <xsl:stylesheet version=1.0

      xmlns:xsl=http://www.w3.org/1999/XSL/Transform>

      +<xsl:output method=xml encoding=UTF-8 />

      <xsl:template match=/>

      <MOODLE_BACKUP>

      <INFO>

      diff -wur --new-file /var/www/moodle/backup/bb/bb6_to_moodle.xsl bb/bb6_to_moodle.xsl

      — /var/www/moodle/backup/bb/bb6_to_moodle.xsl 2005-02-07 23:19:49.000000000 -0800

      +++ bb/bb6_to_moodle.xsl 2005-05-26 12:45:20.000000000 -0700

      @@ -2,6 +2,7 @@

      <xsl:stylesheet version=1.0

      xmlns:xsl=http://www.w3.org/1999/XSL/Transform

      >

      +<xsl:output method=xml encoding=UTF-8 />

      <xsl:template match=/>

      <MOODLE_BACKUP>

      <INFO>

      diff -wur --new-file /var/www/moodle/backup/bb/restore_bb.php bb/restore_bb.php

      — /var/www/moodle/backup/bb/restore_bb.php 2005-03-04 19:58:13.000000000 -0800

      +++ bb/restore_bb.php 2005-05-26 12:29:02.000000000 -0700

      @@ -3,6 +3,7 @@

      // into a Moodle course export. It assumes an unzipped directory and makes in-place alterations.

      // Ziba Scott <ziba@linuxbox.com> 10-25-04

      +require_once('xsl_emulate_xslt.inc');

      function get_subdirs($directory){

      $opendirectory = opendir( $directory );

      diff -wur --new-file /var/www/moodle/backup/bb/xsl_emulate_xslt.inc bb/xsl_emulate_xslt.inc

      — /var/www/moodle/backup/bb/xsl_emulate_xslt.inc 1969-12-31 16:00:00.000000000 -0800

      +++ bb/xsl_emulate_xslt.inc 2005-05-26 12:48:10.000000000 -0700

      @@ -0,0 +1,43 @@

      +<?php

      +// This file adds xslt_xxx emulation functions.

      +// It is intended for systems, e.g. those running PHP 5, where:

      +// 1) The XSLT library is not installed.

      +// 2) The XSL library is installed.

      +//

      +// Note that not everything is implemented.

      +// In particular, only the bare minimum to support the BB conversion is here.

      +

      +// This silliness is required to prevent PHP from evaluating the function() blocks before processing the return;s

      +if(true) {

      +

      +

      +if(function_exists('xslt_create')) return; // xslt_create() already exists, so emulation isn't needed.

      +if(!class_exists('XSLTProcessor')) return; // There is no XSLTProcessor class, so emulation isn't possible.

      +if(!class_exists('DOMDocument')) return; // There is no DOMDocument class, so emulation isn't possible.

      +

      +

      +

      +function xslt_create()

      { + return new XSLTProcessor(); +}

      +

      +// We don't support arguments or parameters because the Bb import doesn't use them

      +function xslt_process($proc, $xmlfile, $xslfile, $resultfile = null, $unsupported_args = null, $unsupported_params = null) {

      + $doc = new DOMDocument;

      + $doc->load($xmlfile);

      + $xsl = new DOMDocument;

      + $xsl->load($xslfile);

      + $proc->importStylesheet($xsl);

      +

      + // Squash warnings here because xsl complains about COURSE_ACCESS tags which really are invalid XML (multiple root elements)

      + if($resultfile !== null)

      { + $fp = fopen($resultfile, 'w'); + fwrite($fp, @$proc->transformToXML($doc)); + fclose($fp); + return true; + }

      else

      { + return @$proc->transformToXML($doc); + }

      +}

      +

      +} // end if(true)

        Activity

        Hide
        Martin Dougiamas added a comment -

        From Ziba Scott (ziba at linuxbox.com) Thursday, 2 June 2005, 03:40 AM:

        Thanks for the patch. It has been applied to 1.6 dev and tested on PHP 4 and 5.

        From Eloy Lafuente (stronk7 at moodle.org) Saturday, 4 June 2005, 01:56 AM:

        Hi Ziba, great work! B-)

        anyway, should I add you here to be able to assign you this type of BB bugs?

        Has the patch been applied against 15_STABLE too?

        Ciao, Eloy

        From Eloy Lafuente (stronk7 at moodle.org) Sunday, 5 June 2005, 06:33 AM:

        Is this in 15_STABLE too?

        From Ziba Scott (ziba at linuxbox.com) Tuesday, 7 June 2005, 10:31 PM:

        Per Martin's instructions I have merged it into the MOODLE_15_STABLE tree.

        Show
        Martin Dougiamas added a comment - From Ziba Scott (ziba at linuxbox.com) Thursday, 2 June 2005, 03:40 AM: Thanks for the patch. It has been applied to 1.6 dev and tested on PHP 4 and 5. From Eloy Lafuente (stronk7 at moodle.org) Saturday, 4 June 2005, 01:56 AM: Hi Ziba, great work! B-) anyway, should I add you here to be able to assign you this type of BB bugs? Has the patch been applied against 15_STABLE too? Ciao, Eloy From Eloy Lafuente (stronk7 at moodle.org) Sunday, 5 June 2005, 06:33 AM: Is this in 15_STABLE too? From Ziba Scott (ziba at linuxbox.com) Tuesday, 7 June 2005, 10:31 PM: Per Martin's instructions I have merged it into the MOODLE_15_STABLE tree.
        Hide
        Michael Blake added a comment -

        assign to a valid user

        Show
        Michael Blake added a comment - assign to a valid user
        Hide
        Kenneth Newquist added a comment -

        What's the status of this? I don't see the changes in Moodle 1.7; is there a recommended way of dealing with this issue?

        Show
        Kenneth Newquist added a comment - What's the status of this? I don't see the changes in Moodle 1.7; is there a recommended way of dealing with this issue?

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: