blob: 65a26fd0653fc10790659ac169dc0c4ea25be5f8 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2014 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
*******************************************************************************/
/*
* Export committer information from the Foundation database. The information
* includes the name, committer id, email addresses, and project affiliations.
*
* e.g. http://www.eclipse.org/projects/export/committers.json.php
*
* INTERNAL USE ONLY: restricted to callers within the Eclipse Foundation.
*/
require_once(dirname(__FILE__) . "/../../eclipse.org-common/system/app.class.php");
$App = new App();
require_once(dirname(__FILE__) . "/../classes/common.php");
require_once(dirname(__FILE__) . "/../classes/debug.php");
mustBeEclipseFoundationCaller();
$data = array();
$sql = "SELECT
p.PersonId as id, p.FName, p.LName, p.Email, pe.Email as secondary, p.comments,
pp.ProjectId, pp.ActiveDate, pp.InactiveDate,
o.OrganizationId, o.Name1 as OrganizationName
from People as p
join PeopleProjects as pp on p.PersonId = pp.PersonId and pp.Relation='CM'
left join PeopleEmails as pe on p.PersonId=pe.PersonId
left join OrganizationContacts as oc on p.PersonId = oc.PersonId and oc.Relation='EMPLY'
left join Organizations as o on oc.OrganizationId=o.OrganizationId";
$result = $App->foundation_sql($sql);
function addEmail(&$committer, $email) {
if (!$email) return;
$email = utf8_encode($email);
if (empty($committer['email'])) $committer['email'] = array();
if (in_array($email, $committer['email'])) return;
$committer['email'][] = $email;
}
while ($row=mysql_fetch_assoc($result)) {
$id = utf8_encode($row['id']);
$data['committers'][$id]['id'] = $id;
$data['committers'][$id]['first'] = utf8_encode($row['FName']);
$data['committers'][$id]['last'] = utf8_encode($row['LName']);
$data['committers'][$id]['primary'] = $row['Email'];
addEmail($data['committers'][$id], $row['Email']);
addEmail($data['committers'][$id], $row['secondary']);
if (preg_match_all('/alt-email:(\S+)/i', $row['comments'], $matches)) {
foreach($matches[1] as $email) {
addEmail($data['committers'][$id], $email);
}
}
$data['committers'][$id]['projects'][$row['ProjectId']] = array(
'active' => $row['ActiveDate'],
'inactive' => isset($row['InactiveDate']) ? $row['InactiveDate'] : null
);
// TODO Include start/end time
if (isset($row['OrganizationId'])) {
$data['committers'][$id]['affiliations'][$row['OrganizationId']] = array(
'name' => $row['OrganizationName'],
'active' => '2000-01-01',
'inactive' => null
);
$data['organizations'][$row['OrganizationId']] = $row['OrganizationName'];
}
}
echo json_encode($data);
?>