Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-56642

Dataformat – Excel and ODS writer can not generate file in WAMP environment

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1, 3.1.3, 3.2
    • Fix Version/s: 3.1.4, 3.2.1
    • Component/s: Other
    • Labels:
    • Database:
      MySQL
    • Testing Instructions:
      Hide
      1. you need an environment with configured open_basedir setting. The open_basedir (in php.ini) should only point to the moodle directories.
      2. Create a feedback instance.
      3. Add one ore more questions.
      4. Answer the question and submit the answers.
      5. Go to "Show responses" and download the responses as "Microsoft Excel"
      6. Without the fix you get a 404 error and with the fix you get the correct file.
      7. Try all other download formats and make sure they still work
      Show
      you need an environment with configured open_basedir setting. The open_basedir (in php.ini) should only point to the moodle directories. Create a feedback instance. Add one ore more questions. Answer the question and submit the answers. Go to "Show responses" and download the responses as "Microsoft Excel" Without the fix you get a 404 error and with the fix you get the correct file. Try all other download formats and make sure they still work
    • Workaround:
      Hide

      I traced source codes of Spout module. I found Spout used sys_get_temp_dir() php builtin function. Windows system default temp directory
      is C:\Windows\temp. PHP process lacked list folder permissions in temp directory, so occurred RecursiveDirectoryIterator executing error.
      I fixed this problem by adding some lines in \lib\classes\dataformat\spout_base.php are shown below:

      public function send_http_headers() {
      $this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype);
      //======================================================
      // added as below
      if( $this->spouttype == 'ods' || $this->spouttype == 'xlsx' )

      { global $CFG ; $this->writer->setTempFolder( $CFG->dataroot.'/temp/dataformat' ); }

      // =====================================================
      $filename = $this->filename . $this->get_extension();
      $this->writer->openToBrowser($filename);
      if ($this->sheettitle && $this->writer instanceof \Box\Spout\Writer\AbstractMultiSheetsWriter)

      { $sheet = $this->writer->getCurrentSheet(); $sheet->setName($this->sheettitle); }

      }

      Show
      I traced source codes of Spout module. I found Spout used sys_get_temp_dir() php builtin function. Windows system default temp directory is C:\Windows\temp. PHP process lacked list folder permissions in temp directory, so occurred RecursiveDirectoryIterator executing error. I fixed this problem by adding some lines in \lib\classes\dataformat\spout_base.php are shown below: public function send_http_headers() { $this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype); //====================================================== // added as below if( $this->spouttype == 'ods' || $this->spouttype == 'xlsx' ) { global $CFG ; $this->writer->setTempFolder( $CFG->dataroot.'/temp/dataformat' ); } // ===================================================== $filename = $this->filename . $this->get_extension(); $this->writer->openToBrowser($filename); if ($this->sheettitle && $this->writer instanceof \Box\Spout\Writer\AbstractMultiSheetsWriter) { $sheet = $this->writer->getCurrentSheet(); $sheet->setName($this->sheettitle); } }
    • Affected Branches:
      MOODLE_31_STABLE, MOODLE_32_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE, MOODLE_32_STABLE
    • Pull Master Branch:
      wip-MDL-56642-master

      Description

      My issue with downloading excel or ods file of statistics of Offline Quiz in Moodle 3.1.2.
      When I select the statistics report in Excel or ODS format to download, it fails. The error
      in the console is:
      GETHTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
      All other formats appear to be working correctly however.
      The error log file of php found this:
      [28-Oct-2016 16:37:35 Etc/GMT-8] Default exception handler: Exception - RecursiveDirectoryIterator::__construct(C:\Windows\TEMP/ods58130e4f1795c,C:\Windows\TEMP/ods58130e4f1795c): Access is denied. (code: 5) Debug:
      Error code: generalexceptionmessage

      • line 152 of \lib\spout\src\Spout\Writer\Common\Helper\ZipHelper.php: UnexpectedValueException thrown
      • line 152 of \lib\spout\src\Spout\Writer\Common\Helper\ZipHelper.php: call to RecursiveDirectoryIterator->__construct()
      • line 273 of \lib\spout\src\Spout\Writer\ODS\Helper\FileSystemHelper.php: call to Box\Spout\Writer\Common\Helper\ZipHelper->addFolderToArchive()
      • line 104 of \lib\spout\src\Spout\Writer\ODS\Internal\Workbook.php: call to Box\Spout\Writer\ODS\Helper\FileSystemHelper->zipRootFolderAndCopyToStream()
      • line 90 of \lib\spout\src\Spout\Writer\ODS\Writer.php: call to Box\Spout\Writer\ODS\Internal\Workbook->close()
      • line 331 of \lib\spout\src\Spout\Writer\AbstractWriter.php: call to Box\Spout\Writer\ODS\Writer->closeWriter()
      • line 99 of \lib\classes\dataformat\spout_base.php: call to Box\Spout\Writer\AbstractWriter->close()
      • line 1770 of \lib\tablelib.php: call to core\dataformat\spout_base->write_footer()
      • line 951 of \mod\offlinequiz\report\statistics\report.php: call to table_dataformat_export_format->finish_table()
      • line 301 of \mod\offlinequiz\report\statistics\report.php: call to offlinequiz_statistics_report->download_offlinequiz_info_table()
      • line 107 of \mod\offlinequiz\report.php: call to offlinequiz_statistics_report->display()

      Same problem occured in feedback module.

      https://moodle.org/mod/forum/discuss.php?d=336437

      I traced source codes of Spout module. I found Spout used sys_get_temp_dir() php builtin function. Windows system default temp directory
      is C:\Windows\temp. PHP process lacked list folder permissions in temp directory, so occurred RecursiveDirectoryIterator executing error.

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Jan/17