Ejemplo n.º 1
0
 public static function generate()
 {
     $config = Zend_Registry::get('config');
     $oldUserConfig = self::loadExistingAuthzData($config->subversion->authz);
     $text = "# This is an auto generated file! Edit at your own risk!\n";
     $text .= "# You can edit this \"/\" section. Settings will be kept.\n#\n";
     $text .= "[/]\n";
     foreach ($oldUserConfig as $key => $value) {
         $text .= $key . " = " . $value . "\n";
     }
     $text .= "\n#\n# Don't edit anything below! All manual changes will be overwritten. \n#\n";
     $text .= "\n[groups]\n";
     $array = array();
     $groups = new USVN_Db_Table_Groups();
     foreach ($groups->fetchAllAndUsers() as $group) {
         $array[$group->name][] = $group->users_login;
     }
     foreach ($array as $group => $users) {
         $users = implode(", ", $users);
         $text .= "{$group} = {$users}\n";
     }
     $array = array();
     $projects = new USVN_Db_Table_Projects();
     foreach ($projects->fetchAllAndFilesRightsAndGroups() as $project) {
         /* @var $project USVN_Db_Table_Row_Project */
         if (!isset($array[$project->name])) {
             $array[$project->name] = array();
         }
         if ($project->files_rights_path) {
             if (!isset($array[$project->name][$project->files_rights_path])) {
                 $array[$project->name][$project->files_rights_path] = array();
             }
             if ($project->groups_name) {
                 $rights = $project->files_rights_is_readable ? "r" : "";
                 $rights .= $project->files_rights_is_writable ? "w" : "";
                 $array[$project->name][$project->files_rights_path][$project->groups_name] = $rights;
             }
         }
     }
     foreach ($array as $project => $files_paths) {
         $text .= "\n\n# Project {$project}\n";
         foreach ($files_paths as $files_path => $files_rights) {
             $text .= "[{$project}:{$files_path}]\n";
             foreach ($files_rights as $group => $rights) {
                 $text .= "@{$group} = {$rights}\n";
             }
             $text .= "\n";
         }
     }
     @file_put_contents($config->subversion->authz, $text);
 }