Piwik\Filechecks::dieIfDirectoriesNotWritable PHP Method

dieIfDirectoriesNotWritable() public static method

Checks that the directories Piwik needs write access are actually writable Displays a nice error page if permissions are missing on some directories
public static dieIfDirectoriesNotWritable ( array $directoriesToCheck = null )
$directoriesToCheck array Array of directory names to check
    public static function dieIfDirectoriesNotWritable($directoriesToCheck = null)
    {
        $resultCheck = self::checkDirectoriesWritable($directoriesToCheck);
        if (array_search(false, $resultCheck) === false) {
            return;
        }
        $directoryList = '';
        foreach ($resultCheck as $dir => $bool) {
            $realpath = Filesystem::realpath($dir);
            if (!empty($realpath) && $bool === false) {
                $directoryList .= self::getMakeWritableCommand($realpath);
            }
        }
        // Also give the chown since the chmod is only 755
        if (!SettingsServer::isWindows()) {
            $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/');
            $directoryList = "<code>chown -R " . self::getUserAndGroup() . " " . $realpath . "</code><br />" . $directoryList;
        }
        if (function_exists('shell_exec')) {
            $currentUser = self::getUser();
            if (!empty($currentUser)) {
                $optionalUserInfo = " (running as user '" . $currentUser . "')";
            }
        }
        $directoryMessage = "<p><b>Piwik couldn't write to some directories {$optionalUserInfo}</b>.</p>";
        $directoryMessage .= "<p>Try to Execute the following commands on your server, to allow Write access on these directories" . ":</p>" . "<blockquote>{$directoryList}</blockquote>" . "<p>If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 0755 (or 0777 if 0755 is not enough). To do so with your FTP software, right click on the directories then click permissions.</p>" . "<p>After applying the modifications, you can <a href='index.php'>refresh the page</a>.</p>" . "<p>If you need more help, try <a href='?module=Proxy&action=redirect&url=http://piwik.org'>Piwik.org</a>.</p>";
        $ex = new MissingFilePermissionException($directoryMessage);
        $ex->setIsHtmlMessage();
        throw $ex;
    }

Usage Example

Example #1
0
 private function oneClick_Download()
 {
     $pathPiwikZip = PIWIK_USER_PATH . self::PATH_TO_EXTRACT_LATEST_VERSION . 'latest.zip';
     $this->pathPiwikZip = SettingsPiwik::rewriteTmpPathWithInstanceId($pathPiwikZip);
     Filechecks::dieIfDirectoriesNotWritable(array(self::PATH_TO_EXTRACT_LATEST_VERSION));
     // we catch exceptions in the caller (i.e., oneClickUpdate)
     $url = self::getLatestZipUrl($this->newVersion) . '?cb=' . $this->newVersion;
     Http::fetchRemoteFile($url, $this->pathPiwikZip);
 }
All Usage Examples Of Piwik\Filechecks::dieIfDirectoriesNotWritable