BobRay / UpgradeMODX

A dashboard widget that detects upgrades and (optionally) installs them from within the MODX Manager
https://bobsguides.com/upgrade-modx-package.html
22 stars 14 forks source link

Error creating log folder in cache directory #58

Closed travisbotello closed 5 years ago

travisbotello commented 5 years ago

When trying to upgrade I am receiving the following error:

[2018-11-30 12:04:41] (ERROR @ /home/modx/core/components/upgrademodx/processors/ugmprocessor.class.php : 107) PHP warning: fopen(/home/modx/core/cache/logs/upgrademodx.log): failed to open stream: File or Directory not found

When I create the logs folder manually it is working. I am not having any permission or owner issues on my Linode.

Running MODx 2.6.5 with ugm 2.1.0

BobRay commented 5 years ago

Sorry, I can't duplicate that problem.

travisbotello commented 5 years ago

I think I've found the problem: Advanced installation with custom config key

When using advanced installation the cache/logs folder is not generated by MODx. Therefore the upgrademodx.log can't be generated in there using fopen. Instead the logs folder is generated like this when using advanced installation with custom config key:

core/cache/<custom_config_key>/logs

BobRay commented 5 years ago

Good catch. 👍

I can't imagine what the point of that is, since if someone has access to your core directory, making it a tiny bit harder to find your logs isn't going to help much. ;)

I could check for that directory with MODX_CONFIG_KEY, but I'm inclined to just create a new /logs directory in the traditional location with this code at line 57 of the core/components/upgrademodx/processors/ugmprocessor.class.php file:

 $logDir = $this->modxCorePath . 'cache/logs/';
 $this->mmkDir($logDir);
 $this->logFilePath = $logDir . 'upgrademodx.log';

That way everyone's UGM log will be in the same place. Could you try that code for me?

travisbotello commented 5 years ago

Great! Your fix is working for me!

I can't imagine what the point of that is, since if someone has access to your core directory, making it a tiny bit harder to find your logs isn't going to help much. ;)

I think this was introduced to run multiple MODx sites with one core. In that case it is very important to distinguish these different installations by using the unique config_key in the cache path. Since I am not doing this I can't help to debug this scenario when using just one single UGM log...

BobRay commented 5 years ago

Thanks. That makes sense. In fact my fix might cause confusion for people with multiple sites like that. I've been trying to find the code that writes the error log file for guidance, but still haven't located it.

BobRay commented 5 years ago

Found it! Could you delete that bogus logs directory, then try replacing the code above with this:

        $cm = $this->modx->getCacheManager();
        $cachePath = $cm->getCachePath();
        $logDir = $cachePath . 'logs/';
        $this->mmkDir($logDir);
        $this->logFilePath = $logDir . 'upgrademodx.log';
travisbotello commented 5 years ago

Perfect! It is working as expected and the log file is created in the correct directory.

BobRay commented 5 years ago

Thanks for letting me know. 👍