Пример #1
0
 function normalizeData()
 {
     // From the PFO spec
     $this->removeObsoleteSettings();
     $this->fetchData($this->getID());
     $projects = $this->getLinkedProjects();
     $new_sa = array();
     $new_pa = array();
     // Add missing settings
     // ...project-wide settings
     if (USE_PFO_RBAC) {
         $arr = array('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'webcal');
         foreach ($projects as $p) {
             foreach ($arr as $section) {
                 $this->normalizePermsForSection($new_pa, $section, $p->getID());
             }
         }
         $this->normalizePermsForSection($new_pa, 'forge_admin', -1);
         $this->normalizePermsForSection($new_pa, 'approve_projects', -1);
         $this->normalizePermsForSection($new_pa, 'approve_news', -1);
         $this->normalizePermsForSection($new_pa, 'forge_stats', -1);
     } else {
         $arr = array('projectadmin', 'frs', 'scm', 'docman', 'forumadmin', 'trackeradmin', 'newtracker', 'pmadmin', 'newpm', 'webcal');
         foreach ($arr as $section) {
             $this->normalizeDataForSection($new_sa, $section);
         }
     }
     $hook_params = array();
     $hook_params['role'] =& $this;
     $hook_params['new_sa'] =& $new_sa;
     $hook_params['new_pa'] =& $new_pa;
     plugin_hook("role_normalize", $hook_params);
     // ...tracker-related settings
     $new_sa['tracker'] = array();
     $new_pa['tracker'] = array();
     foreach ($projects as $p) {
         $atf = new ArtifactTypeFactory($p);
         $trackerids = $atf->getAllArtifactTypeIds();
         foreach ($trackerids as $tid) {
             if (USE_PFO_RBAC) {
                 if (array_key_exists('tracker', $this->perms_array) && array_key_exists($tid, $this->perms_array['tracker'])) {
                     $new_pa['tracker'][$tid] = $this->perms_array['tracker'][$tid];
                 } elseif (array_key_exists('new_tracker', $this->perms_array) && array_key_exists($p->getID(), $this->perms_array['new_tracker'])) {
                     $new_pa['tracker'][$tid] = $new_pa['new_tracker'][$p->getID()];
                 }
             } else {
                 if (array_key_exists('tracker', $this->setting_array) && array_key_exists($tid, $this->setting_array['tracker'])) {
                     $new_sa['tracker'][$tid] = $this->setting_array['tracker'][$tid];
                 } else {
                     $new_sa['tracker'][$tid] = $new_sa['newtracker'][0];
                 }
             }
         }
     }
     // ...forum-related settings
     $new_sa['forum'] = array();
     $new_pa['forum'] = array();
     foreach ($projects as $p) {
         $ff = new ForumFactory($p);
         $fids = $ff->getAllForumIds();
         foreach ($fids as $fid) {
             if (USE_PFO_RBAC) {
                 if (array_key_exists('forum', $this->perms_array) && array_key_exists($fid, $this->perms_array['forum'])) {
                     $new_pa['forum'][$fid] = $this->perms_array['forum'][$fid];
                 } elseif (array_key_exists('new_forum', $this->perms_array) && array_key_exists($p->getID(), $this->perms_array['new_forum'])) {
                     $new_pa['forum'][$fid] = $new_pa['new_forum'][$p->getID()];
                 }
             } else {
                 if (array_key_exists('forum', $this->setting_array) && array_key_exists($fid, $this->setting_array['forum'])) {
                     $new_sa['forum'][$fid] = $this->setting_array['forum'][$fid];
                 } else {
                     $new_sa['forum'][$fid] = $new_sa['newforum'][0];
                 }
             }
         }
     }
     // ...pm-related settings
     $new_sa['pm'] = array();
     $new_pa['pm'] = array();
     foreach ($projects as $p) {
         $pgf = new ProjectGroupFactory($p);
         $pgids = $pgf->getAllProjectGroupIds();
         foreach ($pgids as $gid) {
             if (USE_PFO_RBAC) {
                 if (array_key_exists('pm', $this->perms_array) && array_key_exists($gid, $this->perms_array['pm'])) {
                     $new_pa['pm'][$gid] = $this->perms_array['pm'][$gid];
                 } elseif (array_key_exists('new_pm', $this->perms_array) && array_key_exists($p->getID(), $this->perms_array['new_pm'])) {
                     $new_pa['pm'][$gid] = $new_pa['new_pm'][$p->getID()];
                 }
             } else {
                 if (array_key_exists('pm', $this->setting_array) && array_key_exists($gid, $this->setting_array['pm'])) {
                     $new_sa['pm'][$gid] = $this->setting_array['pm'][$gid];
                 } else {
                     $new_sa['pm'][$gid] = $new_sa['newpm'][0];
                 }
             }
         }
     }
     // Save
     if (USE_PFO_RBAC) {
         $this->update($this->getName(), $new_pa, false);
     } else {
         $this->update($this->getName(), $new_sa);
     }
     return true;
 }