moosh icon indicating copy to clipboard operation
moosh copied to clipboard

bug: config-plugin-import crashes on configurations with extra files

Open maxandron opened this issue 1 year ago • 1 comments

  • moosh version: 1.13 (tested with 1.13. I see the code error exists in master as well)
  • moodle version: 4.1
    • database: mariadb
  • php version: 8.0.29
  • operating system: Ubuntu

Actual behaviour

When executing the config-plugin-import command on a plugin that contains additional files exported via config-plugin-export, Moosh crashes with the following error:

> moosh config-plugin-import /tmp/plugins/theme_alpha/theme_alpha_config_1700458174.xml
Imported file logo.ico
Default exception handler: Cannot read file. Either the file does not exist or there is a permission problem. Debug: /tmp/plugins/theme_alpha/theme_alpha_config_1700458174.xmlf00c6f0664dbd9dd6744c7497b8a164014072560
Error code: storedfilecannotread
* line 523 of /lib/filestorage/file_system.php: file_exception thrown
* line 348 of /lib/filestorage/file_system_filedir.php: call to file_system->validate_hash_and_file_size()
* line 1831 of /lib/filestorage/file_storage.php: call to file_system_filedir->add_file_from_path()
* line 1360 of /lib/filestorage/file_storage.php: call to file_storage->add_file_to_pool()
* line 145 of /root/moosh/Moosh/Command/Moodle39/Config/ConfigPluginimport.php: call to file_storage->create_file_from_pathname()
* line 53 of /root/moosh/Moosh/Command/Moodle39/Config/ConfigPluginimport.php: call to Moosh\Command\Moodle39\Config\ConfigPluginimport->import_settings()
* line 365 of /root/moosh/moosh.php: call to Moosh\Command\Moodle39\Config\ConfigPluginimport->execute()

!!! Cannot read file. Either the file does not exist or there is a permission problem. !!!

Expected behaviour

Plugin config should be imported without errors

Steps to reproduce

Use config-plugin-export on a plugin that has an additional file.
Use config-plugin-import to import exported configuration.

maxandron avatar Nov 20 '23 06:11 maxandron

The culprit (I think) is the line $filepath = $this->inputfilepath.$setting->getAttribute('file'); in the file ConfigPluginimport.php

$filepath = $this->inputfilepath is not only the directory, but the entire path

While $setting->getAttribute('file') contains the hash of the file

In my setup, simply changing to $filepath = $this->inputfilepath.$setting->getAttribute('file'); to $filepath = $this->inputfilepath; or using $this->inputfilepath directly in the create_file_from_pathname function call, solves the issue.

I'll open a PR

maxandron avatar Nov 20 '23 06:11 maxandron