blob: ed69e8bae681305e550c0ecf8094a67d67e208ef [file] [log] [blame]
<?php
/**
* *****************************************************************************
* Copyright (c) 2018 Eclipse Foundation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
/*
* FIXME Experimental.
*/
require_once dirname ( __FILE__ ) . '/../classes/Project.class.php';
require_once dirname ( __FILE__ ) . '/../classes/BugzillaClient.class.inc';
require_once dirname ( __FILE__ ) . '/../classes/debug.php';
require_once dirname ( __FILE__ ) . '/../classes/database.inc';
class Release {
var $project;
var $name;
var $date;
/**
* This method answers an array containing all of releases that
* either have occurred or are planned to occur after a particular
* date. The method has two optional parameters. If specified, only
* those projects that descend from a particular root are included.
* If no date (UNIX time) is specified, then the current date is used.
*
* @param string $root the root project
* @param int $date the data in UNIX time
* @return Release[]
*/
public static function releasesAfter($root = null, $date = null) {
$sql = "
select
project as id, name, date
from ProjectReleases
where project regexp ':pattern'
and date > date(':date')
order by date";
$args = array(
':pattern' => $root ? "^${root}(?:\..*)?$" : '',
':date' => date('Y-m-d', $date ? $date : time())
);
return new DatabaseQuery('dashboard', $sql, $args, function ($row) use (&$releases) {
$project = Project::getProject ( $row ['id'] );
$name = $row ['name'];
$date = strtotime ( $row ['date'] );
return new Release ( $project, $name, $date );
} );
}
private function __construct($project, $name, $date) {
$this->project = $project;
$this->name = $name;
$this->date = $date;
}
public function getId() {
return $this->project->getId ();
}
public function getUrl() {
return $this->project->getUrl ();
}
public function getName() {
return $this->project->getName () . ' ' . $this->name;
}
public function getDate() {
return $this->date;
}
public function getVersion() {
return $this->makeThreePartVersionNumber($this->name);
}
public function getTrackingBugUrl() {
$bugzilla = new BugzillaClient('https://bugs.eclipse.org/bugs');
$bugs = $bugzilla->findBugs()
->setProduct('Community')
->setComponent('Proposals and Reviews')
->setSummary($this->getTrackingBugSummary())
->searchBugs();
foreach ($bugs as $bug) {
return $bug->getUrl();
}
return null;
}
private function getTrackingBugSummary() {
return "[release] {$this->project->getId()} {$this->getVersion()}";
}
public static function makeThreePartVersionNumber($value) {
if (preg_match('/(\d+)(\.\d+)?(\.\d+)?/', $value, $matches)) {
$name = $matches[1];
$name .= isset($matches[2]) && $matches[2] ? $matches[2] : '.0';
$name .= isset($matches[3]) && $matches[3] ? $matches[3] : '.0';
return $name;
}
else
if (preg_match('/(\d+(\.\d+){1,2})/', $value)) {
return $match[1];
}
else {
return null;
}
}
private static function getProbableReviewDate($date) {
$diff = date ( 'w', $date ) - 3; // '3' means Wednesday
if ($diff < 0)
$diff += 7;
$date = strtotime ( "-$diff days", $date );
$now = strtotime ( 'now' );
$dates = array ();
while ( $date > $now ) {
// There's probably a better way to do this, but
// the month boundaries are icky, this works, and is simple.
if (self::isFirstOrThirdWeek ( $date )) {
return $date;
}
$date = strtotime ( "-1 week", $date );
}
return 0;
}
/**
* Answers whether the provided date represents either the
* first or the third week of the month.
*
* @see Release::getProbableReviewDate()
* @param int $date
*/
private static function isFirstOrThirdWeek($date) {
$day = date ( 'j', $date ) - 1; // 0-based day of the month
if (floor ( $day / 7 ) == 0)
return true; // first week
if (floor ( $day / 7 ) == 2)
return true; // third week
return false;
}
}