Page MenuHomePhabricator

Error on Special:ImportSpreadsheet in MW 1.34.x: "Could not open for reading! File does not exist." / "PHP Warning: stream_get_meta_data() expects parameter 1 to be resource, object given"
Closed, ResolvedPublic

Description

Environment

  • MediaWiki 1.34.1 (b1f6480) 18:15, 30 April 20
  • PHP 7.2.30 (apache2handler)
  • Data Transfer 1.1.1 (1fc1c61) 04:42, 20 September 2019
  • phpoffice/phpexcel dev-master

[XrIAjzTNAOBUFE21T0p@MQAAAAo] /test/Special:ImportSpreadsheet PHPExcel_Reader_Exception from line 73 of /opt/htdocs/mediawiki/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php: Could not open for reading! File does not exist.

Backtrace:

#0 /opt/htdocs/mediawiki/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(281): PHPExcel_Reader_Excel2007->canRead(NULL)
#1 /opt/htdocs/mediawiki/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(191): PHPExcel_IOFactory::createReaderForFile(NULL)
#2 /opt/htdocs/mediawiki/extensions/DataTransfer/specials/DT_ImportSpreadsheet.php(42): PHPExcel_IOFactory::load(NULL)
#3 /opt/htdocs/mediawiki/extensions/DataTransfer/specials/DT_ImportCSV.php(60): DTImportSpreadsheet->importFromFile(ImportStreamSource, NULL, array)
#4 /opt/htdocs/mediawiki/extensions/DataTransfer/specials/DT_ImportCSV.php(29): DTImportCSV->importFromUploadAndModifyPages()
#5 /opt/htdocs/mediawiki/includes/specialpage/SpecialPage.php(575): DTImportCSV->execute(NULL)
#6 /opt/htdocs/mediawiki/includes/specialpage/SpecialPageFactory.php(611): SpecialPage->run(NULL)
#7 /opt/htdocs/mediawiki/includes/MediaWiki.php(296): MediaWiki\Special\SpecialPageFactory->executePath(Title, RequestContext)
#8 /opt/htdocs/mediawiki/includes/MediaWiki.php(900): MediaWiki->performRequest()
#9 /opt/htdocs/mediawiki/includes/MediaWiki.php(527): MediaWiki->main()
#10 /opt/htdocs/mediawiki/index.php(44): MediaWiki->run()
#11 {main}

And here's the pertinent lines from the debug data:

Unstubbing $wgLang on call of $wgLang::_unstub from ParserOptions->__construct

[error] [XrIKvf9myczl4IVZkwmjCgAAAAs] /test/Special:ImportSpreadsheet ErrorException from line 39 of /opt/htdocs/mediawiki/extensions/DataTransfer/specials/DT_ImportSpreadsheet.php: PHP Warning: stream_get_meta_data() expects parameter 1 to be resource, object given

[exception] [XrIKvf9myczl4IVZkwmjCgAAAAs] /test/Special:ImportSpreadsheet PHPExcel_Reader_Exception from line 73 of /opt/htdocs/mediawiki/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php: Could not open for reading! File does not exist.

It all used to work on my php 5.6 mw 1.31 set-up a few weeks ago.. could this be a result of the upgrade to php 7.2? Please help!

Event Timeline

Aklapper renamed this task from Internal error on Special:ImportSpreadsheet in MW 1.34.x to Error on Special:ImportSpreadsheet in MW 1.34.x: "Could not open for reading! File does not exist." / "PHP Warning: stream_get_meta_data() expects parameter 1 to be resource, object given".May 6 2020, 10:37 AM
Osnard changed the task status from Open to In Progress.Jan 25 2022, 3:56 PM

Can you explain what the compatibility is here? Which PHP/MediaWiki versions does the current code work with, and which versions does your proposed patch work with?

(It's also possible that the current code does not work with any versions - hopefully that is not the case!)

Osnard triaged this task as Medium priority.Jan 26 2022, 9:22 AM

Well, I tested and fixed on MediaWiki 1.35, PHP 7.4. The original author of this task used MW 1.34, PHP 7.2. But I don't think this is really important. I believe the functionality is actually broken up to the latest extension and MW versions and in any PHP version.

An overview:

  1. ImportStreamSource::mHandle : resource got set to private in https://github.com/wikimedia/mediawiki/commit/290ab29617d830d20cdc72cb9e5e199f5e091d9d#diff-a1b65a88942d6c703d0e2fc1d85efdd2c379e098d03910c2db658877363bd238R33-R35, which was released with MW 1.34
  2. Since then, it was not possible to pass in a resource handle into DTImportCSV::importFromFile
  3. rEDTRe27e04b274bf14e2ada5609be941641f0170c1c7 fixed this for DTImportCSV, by passing in the actual ImportStreamSource object.
  4. Unforutnately in this patch the DTImportSpreadsheet subclass was not fixed.
  5. Therefore DTImportSpreadsheet::importFromFile still expects a resource handle, but now gets passed a ImportStreamSource object by the base class. This is still the case in DataTransfer version 1.3 (https://github.com/wikimedia/mediawiki-extensions-DataTransfer/blob/1.3/includes/specials/DT_ImportSpreadsheet.php#L38-L39), and even master
  6. My fix just applies to that issue in DTImportSpreadsheet, as DTImportCSV is already fixed

Okay, thank you for that detailed explanation - this all makes sense now. I had forgotten that DTImportSpreadsheet inherits from DTImportCSV. (Among other things I had forgotten!)

Given that, maybe the header of DTImportSpreadsheet::importFromFile() should be changed to match the one from DTImportCSV?

@Yaron_Koren Welcome. Could you please make a 1.3.1 release of the extension?