Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: file_put_contents(/matomo-for-wordpress/app/tmp/empty): Failed to open stream: No such file or directory in RecommendedPrivateDirectories.php on line 23 #18684

Open
tsteur opened this issue Jan 25, 2022 · 1 comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.

Comments

@tsteur
Copy link
Member

tsteur commented Jan 25, 2022

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.

@tsteur tsteur added the Bug For errors / faults / flaws / inconsistencies etc. label Jan 25, 2022
@tsteur tsteur added this to the Priority Backlog (Help wanted) milestone Jan 25, 2022
@ASponch
Copy link

ASponch commented Apr 26, 2022

Hello,

I have upgraded from 4.7.1 to 4.9.0 today and I got the same error. All seems to work correctly but the message appears. I created a file named "empty" in /tmp/ and the message disappeared (logical).

Best regards

@mattab mattab added the c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Projects
None yet
Development

No branches or pull requests

3 participants