Exemplo n.º 1
0
 private function createProject(SimpleXMLElement $xml, Tuleap\Project\SystemEventRunner $event_runner)
 {
     $event_runner->checkPermissions();
     $this->logger->info("Create project {$xml['unix-name']}");
     $data = ProjectCreationData::buildFromXML($xml, 100, $this->xml_validator, ServiceManager::instance(), $this->project_manager);
     $project = $this->project_creator->build($data);
     $this->logger->info("Execute system events to finish creation of project {$project->getID()}, this can take a while...");
     $event_runner->runSystemEvents();
     $this->logger->info("System events success");
     return $project;
 }
Exemplo n.º 2
0
 function Project($param)
 {
     $this->Group($param);
     //for right now, just point our prefs array at Group's data array
     //this will change later when we split the project_data table off from groups table
     $this->project_data_array = $this->data_array;
     // Get defined classname of services
     // TODO: Move this in a helper for performances pov (load of many projects)
     $this->serviceClassnames = array('file' => 'ServiceFile', 'svn' => 'ServiceSVN');
     EventManager::instance()->processEvent(Event::SERVICE_CLASSNAMES, array('classnames' => &$this->serviceClassnames));
     // Get Service data
     $allowed_services = ServiceManager::instance()->getListOfAllowedServicesForProject($this);
     if (count($allowed_services) < 1) {
         $this->service_data_array = array();
     }
     $j = 1;
     foreach ($allowed_services as $service) {
         $res_row = $service->data;
         $short_name = $service->getShortName();
         if (!$short_name) {
             $short_name = $j++;
         }
         // needed for localisation
         $matches = array();
         if ($res_row['description'] == "service_" . $short_name . "_desc_key") {
             $res_row['description'] = $GLOBALS['Language']->getText('project_admin_editservice', $res_row['description']);
         } elseif (preg_match('/(.*):(.*)/', $res_row['description'], $matches)) {
             if ($GLOBALS['Language']->hasText($matches[1], $matches[2])) {
                 $res_row['description'] = $GLOBALS['Language']->getText($matches[1], $matches[2]);
             }
         }
         if ($res_row['label'] == "service_" . $short_name . "_lbl_key") {
             $res_row['label'] = $GLOBALS['Language']->getText('project_admin_editservice', $res_row['label']);
         } elseif (preg_match('/(.*):(.*)/', $res_row['label'], $matches)) {
             if ($GLOBALS['Language']->hasText($matches[1], $matches[2])) {
                 $res_row['label'] = $GLOBALS['Language']->getText($matches[1], $matches[2]);
             }
         }
         $this->service_data_array[$short_name] = $res_row;
         if ($short_name) {
             $this->use_service[$short_name] = $service->isUsed();
         }
         $this->services[$short_name] = $service;
         if ($service->isActive()) {
             $this->cache_active_services[] = $service;
         }
     }
 }
Exemplo n.º 3
0
 /** @return ServiceManager */
 private function getServiceManager()
 {
     return ServiceManager::instance();
 }
 private function fromXML(SimpleXMLElement $xml, $template_id, XML_RNGValidator $xml_validator = null, ServiceManager $service_manager = null, ProjectManager $project_manager = null)
 {
     if (empty($xml_validator)) {
         $xml_validator = new XML_RNGValidator();
     }
     if (empty($service_manager)) {
         $service_manager = ServiceManager::instance();
     }
     if (empty($project_manager)) {
         $project_manager = ProjectManager::instance();
     }
     $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/project/project.rng');
     $xml_validator->validate($xml, $rng_path);
     $long_description_tagname = 'long-description';
     $attrs = $xml->attributes();
     $this->unix_name = (string) $attrs['unix-name'];
     $this->full_name = (string) $attrs['full-name'];
     $this->short_description = (string) $attrs['description'];
     $this->built_from_template = (int) $template_id;
     $this->is_test = (bool) false;
     $this->is_public = null;
     $this->trove_data = array();
     $this->data_services = array();
     $this->data_fields = array('form_101' => $xml->{$long_description_tagname});
     if ($attrs['access'] == 'public') {
         $this->is_public = true;
     } else {
         if ($attrs['access'] == 'private') {
             $this->is_public = false;
         }
     }
     $this->markUsedServicesFromXML($xml, $template_id, $service_manager, $project_manager);
 }
Exemplo n.º 5
0
 private function cacheServices()
 {
     if ($this->services !== null) {
         return;
     }
     $this->serviceClassnames = array('file' => 'ServiceFile', 'svn' => 'ServiceSVN');
     EventManager::instance()->processEvent(Event::SERVICE_CLASSNAMES, array('classnames' => &$this->serviceClassnames));
     // Get Service data
     $allowed_services = ServiceManager::instance()->getListOfAllowedServicesForProject($this);
     if (count($allowed_services) < 1) {
         $this->service_data_array = array();
     }
     $j = 1;
     foreach ($allowed_services as $service) {
         $res_row = $service->data;
         $short_name = $service->getShortName();
         if (!$short_name) {
             $short_name = $j++;
         }
         // needed for localisation
         $matches = array();
         if ($res_row['description'] == "service_" . $short_name . "_desc_key") {
             $res_row['description'] = $GLOBALS['Language']->getText('project_admin_editservice', $res_row['description']);
         } elseif (preg_match('/(.*):(.*)/', $res_row['description'], $matches)) {
             if ($GLOBALS['Language']->hasText($matches[1], $matches[2])) {
                 $res_row['description'] = $GLOBALS['Language']->getText($matches[1], $matches[2]);
             }
         }
         if ($res_row['label'] == "service_" . $short_name . "_lbl_key") {
             $res_row['label'] = $GLOBALS['Language']->getText('project_admin_editservice', $res_row['label']);
         } elseif (preg_match('/(.*):(.*)/', $res_row['label'], $matches)) {
             if ($GLOBALS['Language']->hasText($matches[1], $matches[2])) {
                 $res_row['label'] = $GLOBALS['Language']->getText($matches[1], $matches[2]);
             }
         }
         $this->service_data_array[$short_name] = $res_row;
         $this->services[$short_name] = $service;
         if ($service->isActive()) {
             $this->cache_active_services[] = $service;
         }
     }
 }
Exemplo n.º 6
0
        echo '<TD align="center"><A HREF="?group_id=' . $group_id . '&service_id=' . $service_id . '&func=delete' . $short . '" onClick="return confirm(\'';
        if ($group_id == 100) {
            echo $Language->getText('project_admin_servicebar', 'warning_del_s', $hp->purify($label, CODENDI_PURIFIER_JS_QUOTE));
        } else {
            echo $Language->getText('project_admin_servicebar', 'del_s');
        }
        echo '\')"><IMG SRC="' . util_get_image_theme("ic/trash.png") . '" HEIGHT="16" WIDTH="16" BORDER="0" ALT="DELETE"></A></TD>';
    } else {
        echo '<TD align="center">-</TD>';
    }
    echo '</TR>';
    $row_num++;
}
$group_id = $request->getValidated('group_id', 'uint', 0);
session_require(array('group' => $group_id, 'admin_flags' => 'A'));
$service_manager = ServiceManager::instance();
$pm = ProjectManager::instance();
$project = $pm->getProject($group_id);
$is_superuser = false;
if (user_is_super_user()) {
    $is_superuser = true;
}
$is_used = $request->getValidated('is_used', 'uint', false);
$func = $request->getValidated('func', 'string', '');
if ($func == 'delete') {
    $service_id = $request->getValidated('service_id', 'uint', 0);
    // Delete service
    if (!$service_id) {
        $GLOBALS['Response']->addFeedback('error', $Language->getText('project_admin_servicebar', 's_id_not_given'));
    } else {
        $sql = "DELETE FROM service WHERE group_id=" . db_ei($group_id) . " AND service_id=" . db_ei($service_id);
 /**
  * createDefaultLayoutForUser
  *
  * Create the first layout for the user and add some initial widgets:
  * - MyArtifacts
  * - MyProjects
  * - MyBookmarks
  * - MySurveys
  * - MyMonitoredFP
  * - MyMonitoredForums
  * - and widgets of plugins if they want to listen to the event default_widgets_for_new_owner
  *
  * @param  owner_id The id of the newly created user
  */
 function createDefaultLayoutForUser($owner_id)
 {
     $service_manager = ServiceManager::instance();
     $owner_type = self::OWNER_TYPE_USER;
     $sql = "INSERT INTO owner_layouts(layout_id, is_default, owner_id, owner_type) VALUES (1, 1, {$owner_id}, '{$owner_type}')";
     if (db_query($sql)) {
         $sql = "INSERT INTO layouts_contents(owner_id, owner_type, layout_id, column_id, name, rank) VALUES ";
         $sql .= "({$owner_id}, '{$owner_type}', 1, 1, 'myprojects', 0)";
         $sql .= ",({$owner_id}, '{$owner_type}', 1, 1, 'mybookmarks', 1)";
         if ($service_manager->isServiceAvailableAtSiteLevelByShortName(Service::FORUM)) {
             $sql .= ",({$owner_id}, '{$owner_type}', 1, 1, 'mymonitoredforums', 2)";
         }
         if ($service_manager->isServiceAvailableAtSiteLevelByShortName(Service::SURVEY)) {
             $sql .= ",({$owner_id}, '{$owner_type}', 1, 1, 'mysurveys', 4)";
         }
         if ($service_manager->isServiceAvailableAtSiteLevelByShortName(Service::TRACKERV3)) {
             $sql .= ",({$owner_id}, '{$owner_type}', 1, 2, 'myartifacts', 10)";
         }
         if ($service_manager->isServiceAvailableAtSiteLevelByShortName(Service::FILE)) {
             $sql .= ",({$owner_id}, '{$owner_type}', 1, 2, 'mymonitoredfp', 20)";
         }
         $em = EventManager::instance();
         $widgets = array();
         $em->processEvent('default_widgets_for_new_owner', array('widgets' => &$widgets, 'owner_type' => $owner_type));
         foreach ($widgets as $widget) {
             $sql .= ",({$owner_id}, '{$owner_type}', 1, " . $widget['column'] . ", '" . $widget['name'] . "', " . $widget['rank'] . ")";
         }
         db_query($sql);
     }
     echo db_error();
 }
Exemplo n.º 8
0
    }
    display_service_creation_form($group_id, $is_superuser);
} else {
    $service_id = $request->getValidated('service_id', 'uint', 0);
    if (!$service_id) {
        exit_error('ERROR', 'Service Id was not specified ');
    }
    $sql = "SELECT * FROM service WHERE group_id={$group_id} AND service_id={$service_id}";
    $result = db_query($sql);
    if (db_numrows($result) < 1) {
        exit_error($Language->getText('global', 'error'), $Language->getText('project_admin_editservice', 's_not_exist', $service_id));
    }
    $service = db_fetch_array($result);
    $readonly = false;
    $is_superuser = true;
    if (!user_is_super_user()) {
        $is_superuser = false;
        if (!$service['is_active']) {
            exit_error($Language->getText('project_admin_editservice', 'forbidden'), $Language->getText('project_admin_editservice', 'no_access_inactive_s'));
        }
        if ($service['scope'] == "system") {
            // Display service as read-only
            $readonly = true;
        }
    }
    if (!ServiceManager::instance()->isServiceAllowedForProject($project, $service_id)) {
        exit_error('ERROR', $GLOBALS['Language']->getText('project_admin_servicebar', 'not_allowed'));
    }
    display_service_configuration_form($group_id, $service_id, $service, $readonly, $is_superuser);
}
project_admin_footer(array());
 private function createProject(SimpleXMLElement $xml)
 {
     $data = ProjectCreationData::buildFromXML($xml, 100, $this->xml_validator, ServiceManager::instance(), $project_manager = $this->project_manager);
     return $this->project_creator->build($data);
 }
Exemplo n.º 10
0
 /**
  * Only for testing purpose
  */
 public function clearInstance()
 {
     self::$instance = null;
 }