blob: 7edc803f592bfdc45ecbcc35aa5aadbfce8575be [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2010 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wayne Beaton (Eclipse Foundation)- initial API and implementation
*******************************************************************************/
/*
* This script assumes that it is being included by another script. We
* assume that the $App variable has already been defined.
*/
require_once(dirname(__FILE__) . "/Project.class.php");
require_once(dirname(__FILE__) . "/debug.php");
trace_file_info(__FILE__);
class ProjectRoot {
/**
* @internal
* @var Project[]
*/
var $topLevelProjects;
/**
* All the projects that we know about (even inactive ones).
* @internal
* @var Project[]
*/
var $allProjects;
/**
* Only the active projects (duh).
*
* @internal
* @var Project[]
*/
var $activeProjects;
/**
* @internal
* @var bool
*/
var $isProjectInfoLoaded = false;
function __construct() {
$this->load_project_hierarchy();
}
/**
* @deprecated
*/
function isValidProjectName($name) {
global $projectNamePattern;
return preg_match("/^$projectNamePattern$/", $name);
}
/**
* Answers an array containing all top-level projects. Only
* active projects are included.
*
* @return Project[]
*/
function getTopLevelProjects() {
return $this->topLevelProjects;
}
/**
* @deprecated
* @see #getTopLevelProjects()
*/
function get_project_hierarchy() {
return $this->getTopLevelProjects();
}
/**
* @deprecated
* @see #getActiveProjects()
*/
function get_all_projects() {
return $this->getActiveProjects();
}
function getActiveProjects() {
return $this->activeProjects;
}
function getAllProjects() {
return $this->allProjects;
}
/**
* @deprecated
* @see #getProject()
*/
function get_project($id) {
return $this->getProject($id);
}
/**
* This function answers the project with the given id.
*
* @return Project
*/
function getProject($id) {
return $this->allProjects[$id];
}
/**
* @internal
*/
function load_project_hierarchy() {
if ($this->topLevelProjects) return;
global $App;
$project_fields = array('ProjectId', 'Name','Level','ParentProjectID','Description',
'UrlDownload','UrlIndex','DateActive','SortOrder','IsActive',
'BugsName','ProjectPhase','DiskQuotaGB','IsComponent','IsStandard');
$project_fields_string = implode(',', $project_fields);
$where = "ProjectId != 'Eclipse Foundation' and ProjectId not like 'foundation-internal%' and ProjectId not like 'locationtech%'";
// if ($activeOnly) $where = "$where and IsActive";
$query = "
SELECT
$project_fields_string
FROM
Projects
WHERE
$where
ORDER BY ProjectID";
$result = $App->foundation_sql($query);
$top_level = array();
$projects = array();
$activeProjects = array();
while($row = mysql_fetch_assoc($result)) {
$id = $row["ProjectId"];
$parentId = $row['ParentProjectID'];
$project = new Project($this, $row);
$projects[$id] = $project;
if ($project->isActive()) {
$activeProjects[$id] = $project;
if ($parentId == "root" || !$parentId) {
$top_level[] = $project;
} else {
$parent = $projects[$parentId];
if ($parent) {
$project->parent = $parent;
$parent->children[] = $project;
} else {
// TODO Deal with the orphan
}
}
}
}
mysql_free_result($result);
$this->topLevelProjects = $top_level;
$this->allProjects = $projects;
$this->activeProjects = $activeProjects;
$this->_loadProjectHistory();
}
/**
* This function loads the project information on demand. Since
* we don't necessarily know if we need this information when the
* object is constructed, we delay loading until we're asked. This
* function loads the information for all projects. The amount of
* data is relatively small, so it doesn't make a lot of sense to
* load it piecemeal. At least not for the time being.
*
* This function is called from methods in the Project class.
*
* @internal
*
* PRIVATE: THIS FUNCTION IS NOT API.
*/
/* private */ function load_project_info() {
if ($this->isProjectInfoLoaded) return;
$tracer = trace("Loading project information from Eclipse DB.");
global $App;
$sql = "
SELECT distinct
i.ProjectInfoID as ProjectInfoID, i.ProjectID as ProjectID,
i.MainKey as MainKey, v.SubKey as SubKey, i.LastModified as LastModified, v.Value as Value
FROM
ProjectInfo as i
join ProjectInfoValues as v on (i.ProjectInfoID = v.ProjectInfoID)
ORDER By ProjectID, ProjectInfoID, MainKey, SubKey
";
$result = $App->eclipse_sql($sql);
while($row = mysql_fetch_assoc($result)) {
$projectId = $row['ProjectID'];
if (!isset($this->allProjects[$projectId])) continue;
$id = $row['ProjectInfoID'];
$key = $row['MainKey'];
$subkey = $row['SubKey'];
$value = $row['Value'];
$project = $this->allProjects[$projectId];
if ($project) {
$tracer->trace("$id > $projectId > $key/$subkey > $value");
$project->values[] = $row;
}
}
mysql_free_result($result);
$this->isProjectInfoLoaded = true;
}
/**
* This function walks through the array of projects (recursing
* into the child projects as necessary) to find and answer the
* project with the given id.
*
* PRIVATE: THIS FUNCTION IS NOT API.
* @deprecated
*/
/* private */ function find_project(&$projects, $id) {
foreach($projects as $project) {
if (strcmp($project->getId(),$id) == 0) return $project;
$match = $this->find_project($project->getChildren(), $id);
if ($match) return $match;
}
return null;
}
function _loadProjectHistory() {
// SELECT i.projectid as active, a.projectid as inactive from Projects as a join Projects as i on (substring_index(a.projectid, '.', -1) = substring_index(i.projectid, '.', -1) and not i.IsActive) where a.IsActive
$moveMap = array(
"rt.ercp","dsdp.ercp",
"technology.rtsc","dsdp.rtsc",
"tools.tm","dsdp.tm",
"rt.equinox","technology.equinox",
"rt.equinox","eclipse.equinox",
"rt.equinox.bundles","eclipse.equinox.bundles",
"rt.equinox.framework","eclipse.equinox.framework",
"rt.equinox.p2","eclipse.equinox.p2",
"rt.equinox.security","eclipse.equinox.security",
// "rt.equinox","eclipse.incubator.equinox",
// "modeling.emf.compare","eclipse.platform.compare",
// "eclipse.jdt.core","eclipse.platform.core",
// "stp.core","eclipse.platform.core",
// "modeling.emft.search","eclipse.platform.search",
"modeling.emf.cdo","modeling.emft.cdo",
"modeling.emf.compare","modeling.emft.compare",
"modeling.emf.mwe","modeling.emft.mwe",
"modeling.emf.teneo","modeling.emft.teneo",
"modeling.mdt.modisco","modeling.gmt.modisco",
//"modeling.mdt.uml2","modeling.uml2",
"soa.swordfish","rt.swordfish",
"soa.bpmnmodeler","stp.bpmnmodeler",
"soa.sca","stp.sca",
"technology.dash.athena","technology.athena",
"tools.buckminster","technology.buckminster",
"webtools.dali","technology.dali",
"rt.ecf","technology.ecf",
"rt.eclipselink","technology.eclipselink",
"soa.jwt","technology.jwt",
"tools.mat","technology.mat",
"tools.ptp.photran","technology.photran",
"tools.ptp","technology.ptp",
"rt.rap","technology.rap",
"rt.riena","technology.riena",
"technology.dash.athena","technology.soc.athena",
"technology.ide4edu","technology.soc.ide4edu",
"soa.swordfish","technology.swordfish",
"modeling.mdt.xsd","technology.xsd",
"mylyn.reviews","tools.mylyn.reviews",
// "eclipse.jdt.core","tools.pdt.core",
// "stp.core","tools.pdt.core",
"tools.atf","webtools.atf");
while (current($moveMap)) {
$new = current($moveMap);
$old = next($moveMap);
next($moveMap);
if (!isset($this->allProjects[$new])) continue;
if (!isset($this->allProjects[$old])) continue;
trace("Project $old was moved to $new.");
$newProject = $this->allProjects[$new];
$oldProject = $this->allProjects[$old];
$newProject->movedFrom[] = $oldProject;
}
}
}
?>