In Matomo for WordPress we are getting this error
Warning: file_put_contents(/var/www/matomo/matomo/matomo-for-wordpress/app/tmp/empty): Failed to open stream: No such file or directory in /var/www/matomo/matomo/matomo-for-wordpress/app/plugins/Diagnostics/Diagnostic/RecommendedPrivateDirectories.php on line 23
It doesn't use the correct path from DI as it uses a hard coded path but not everyone is using this.
I was going to create this PR
diff --git a/plugins/Diagnostics/Diagnostic/RecommendedPrivateDirectories.php b/plugins/Diagnostics/Diagnostic/RecommendedPrivateDirectories.php
index 4add05f395..f93215865b 100644
--- a/plugins/Diagnostics/Diagnostic/RecommendedPrivateDirectories.php
+++ b/plugins/Diagnostics/Diagnostic/RecommendedPrivateDirectories.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\Diagnostics\Diagnostic;
+use Piwik\Container\StaticContainer;
use Piwik\Filesystem;
use Piwik\Translation\Translator;
@@ -19,8 +20,9 @@ class RecommendedPrivateDirectories extends AbstractPrivateDirectories
public function __construct(Translator $translator)
{
parent::__construct($translator);
- Filesystem::mkdir(PIWIK_INCLUDE_PATH . '/tmp');
- file_put_contents(PIWIK_INCLUDE_PATH . '/tmp/empty', 'test');
+ $tmpDir = rtrim(StaticContainer::get('path.tmp'), '/');
+ Filesystem::mkdir($tmpDir);
+ file_put_contents($tmpDir . '/empty', 'test');
}
protected function addError(DiagnosticResult &$result)
However, I noticed that while this would use the correct tmp directory, it would still use the wrong URL to try and fetch that tmp file. It would always use $matomoUrl/tmp/empty
but the tmp directory might be outside the root directory or it might be in a very different directory and therefore the URL used to check if the file is readable would be wrong.
Meaning if it's outside the root directory we would completely need to skip the check for tmp
files and when it's inside the root directory, the URL would need to change.