| <?php |
| /******************************************************************************* |
| * Copyright (c) 2016, 2017 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 |
| *******************************************************************************/ |
| |
| require_once dirname(__FILE__) . '/../classes/database.inc'; |
| require_once dirname(__FILE__) . '/../classes/common.php'; |
| require_once dirname(__FILE__) . '/../classes/debug.php'; |
| |
| class CQ { |
| var $data; |
| |
| function __construct($data) { |
| $this->data = $data; |
| } |
| |
| function getId() { |
| return $this->data[0]['id']; |
| } |
| |
| function getSummary() { |
| return $this->data[0]['summary']; |
| } |
| |
| function getName() { |
| $value = $this->getSummary(); |
| $value = preg_replace('/\([^\)]*\)/', '', $value); |
| return $value; |
| } |
| |
| function getLicense() { |
| return $this->data[0]['license']; |
| } |
| |
| private function getComment($index = 0) { |
| return $this->data[0]['comment']; |
| } |
| |
| function getProjectUrl() { |
| $comment = $this->getComment(0); |
| if (preg_match('/^Project URL:\s*(\S+)$/m', $comment, $matches)) { |
| return trim($matches[1]); |
| } |
| if ($parent = $this->getParent()) |
| return $parent->getProjectUrl(); |
| } |
| |
| function getSourceUrl() { |
| $comment = $this->getComment(0); |
| if (preg_match('/^Source URL:\s*(\S+)$/m', $comment, $matches)) { |
| return trim($matches[1]); |
| } |
| if ($parent = $this->getParent()) |
| return $parent->getSourceUrl(); |
| } |
| |
| function getRoot() { |
| if ($parent = $this->getParent()) |
| return $parent->getRoot(); |
| return $this; |
| } |
| |
| function getParent() { |
| if ($this->parent === null) { |
| $this->parent = $this->findParent(); |
| } |
| return $this->parent; |
| } |
| |
| private function findParent() { |
| if (!$id = $this->getParentId()) return FALSE; |
| $sql = " |
| select |
| b.bug_id as id, b.short_desc as summary, b.cf_license as license, l.thetext as comment |
| from bugs as b |
| join longdescs as l on b.bug_id=l.bug_id |
| where |
| b.bug_id=$id |
| order by b.bug_id, l.comment_id"; |
| if ($cqs = self::findCqs($sql)) return $cqs[0]; |
| return FALSE; |
| } |
| |
| public function getParentId() { |
| $summary = $this->getSummary(); |
| if (preg_match('/ATO\s+Orbit\s+(\d+)/', $summary, $matches)) |
| return $matches[1]; |
| |
| if (preg_match('/ATO\s*CQ\s*([0-9]+)/', $summary, $matches)) |
| return $matches[1]; |
| |
| if (preg_match('/PB\s*CQ\s*([0-9]+)/', $summary, $matches)) |
| return $matches[1]; |
| |
| if (preg_match('/PB\s*([0-9]+)/', $summary, $matches)) |
| return $matches[1]; |
| |
| if (preg_match('/Orbit\s*(?:CQ)?\s*([0-9]+)/', $summary, $matches)) |
| return $matches[1]; |
| |
| return null; |
| } |
| |
| /** |
| * Answers the approved third party CQs for a project. |
| * |
| * @param string $id A project id, e.g. 'technology.egit' |
| * @return CQ[] |
| */ |
| static function findCqs($id) { |
| $sql = " |
| select |
| b.bug_id as id, b.short_desc as summary, b.cf_license as license, l.thetext as comment |
| from bugs as b |
| join longdescs as l on b.bug_id=l.bug_id |
| join components as c on b.component_id=c.id |
| join keywords as kw on b.bug_id=kw.bug_id |
| join keyworddefs as kwd on kw.keywordid=kwd.id |
| where |
| b.bug_severity='approved' |
| and kwd.name='thirdparty' |
| and c.name='$id' |
| order by b.bug_id, l.comment_id"; |
| |
| $data = array(); |
| query('ipzilla', $sql, array(), function($row) use (&$data) { |
| $id = $row['id']; |
| $data[$id][] = $row; |
| }); |
| |
| $cqs = array(); |
| foreach($data as $id => $rows) { |
| $cqs[] = new CQ($rows); |
| } |
| |
| return $cqs; |
| } |
| } |
| |
| function copyrightStatementsDo($id, $function) { |
| $sql = " |
| select distinct |
| concat( |
| 'Copyright (c) ', |
| if(first=last, first, concat(first, '-', last)), |
| ' ', |
| name, |
| if(!isNull(company), concat(' (',company,')'),'')) as statement |
| from |
| ProjectCopyrights |
| where |
| project=':project'"; |
| |
| query('dashboard', $sql, array(':project' => $id), function($row) use (&$function) { |
| $function($row['statement']); |
| }); |
| } |