Piwik\Filechecks::getOwnerOfPiwikFiles PHP Method

getOwnerOfPiwikFiles() public static method

public static getOwnerOfPiwikFiles ( )
    public static function getOwnerOfPiwikFiles()
    {
        $index = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/index.php');
        $stat = stat($index);
        if (!$stat) {
            return '';
        }
        if (function_exists('posix_getgrgid')) {
            $group = posix_getgrgid($stat[5]);
            $group = $group['name'];
        } else {
            return '';
        }
        if (function_exists('posix_getpwuid')) {
            $user = posix_getpwuid($stat[4]);
            $user = $user['name'];
        } else {
            return '';
        }
        return "{$user}:{$group}";
    }

Usage Example

Beispiel #1
0
 /**
  * @param OutputInterface $output
  */
 protected function writeAlertMessageWhenCommandExecutedWithUnexpectedUser(OutputInterface $output)
 {
     if (SettingsServer::isWindows()) {
         // does not work on windows
         return;
     }
     $processUserAndGroup = Filechecks::getUserAndGroup();
     $fileOwnerUserAndGroup = Filechecks::getOwnerOfPiwikFiles();
     if (!$fileOwnerUserAndGroup || $processUserAndGroup == $fileOwnerUserAndGroup) {
         // current process user/group appear to be same as the Piwik filesystem user/group -> OK
         return;
     }
     $output->writeln(sprintf("<comment>It appears you have executed this update with user %s, while your Piwik files are owned by %s. \n\nTo ensure that the Piwik files are readable by the correct user, you may need to run the following command (or a similar command depending on your server configuration):\n\n\$ %s</comment>", $processUserAndGroup, $fileOwnerUserAndGroup, Filechecks::getCommandToChangeOwnerOfPiwikFiles()));
 }