Initial commit
This commit is contained in:
commit
3b1e713fc4
165
indefero/src/IDF/ActivityTaxonomy.php
Normal file
165
indefero/src/IDF/ActivityTaxonomy.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that calculates the activity value for all projects on a
|
||||||
|
* specific date and time.
|
||||||
|
*
|
||||||
|
* We do this by counting adds or updates of database objects in
|
||||||
|
* the particular section (according to the timeline) and relate this
|
||||||
|
* value to the overall activity of a section in the forge.
|
||||||
|
*
|
||||||
|
* To illustrate the behaviour, a simple example could be a forge with
|
||||||
|
* only two projects that both have only issue tracking enabled.
|
||||||
|
* The first project created or updated 10 tickets during the past period,
|
||||||
|
* the other 20. The activity index for the first should therefor be
|
||||||
|
* calculated as 0.33 and the second as 0.66.
|
||||||
|
* Note that this simple example doesn't take activity in other
|
||||||
|
* sections into account, so the the total activity of all projects
|
||||||
|
* for a certain time period might add up to more than 1.0.
|
||||||
|
*
|
||||||
|
* @author tommyd
|
||||||
|
*/
|
||||||
|
class IDF_ActivityTaxonomy
|
||||||
|
{
|
||||||
|
public static function recalculateTaxnomies(DateTime $date)
|
||||||
|
{
|
||||||
|
$sectionWeights = Pluf::f('activity_section_weights', null);
|
||||||
|
$lookback = Pluf::f('activity_lookback', null);
|
||||||
|
if ($sectionWeights === null || $lookback === null) {
|
||||||
|
throw new LogicException('activity configuration is missing in idf.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// query and normalize the section weights
|
||||||
|
//
|
||||||
|
$allWeights = array_sum($sectionWeights);
|
||||||
|
if ($allWeights == 0) {
|
||||||
|
throw new LogicException('the sum of all "activity_section_weights" must not be 0');
|
||||||
|
}
|
||||||
|
foreach ($sectionWeights as $section => $weight) {
|
||||||
|
$sectionWeights[$section] = $weight / (float) $allWeights;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// determine the date boundaries
|
||||||
|
//
|
||||||
|
if ($lookback < 1) {
|
||||||
|
throw new LogicException('lookback must be greater or equal to 1');
|
||||||
|
}
|
||||||
|
$dateCopy = new DateTime();
|
||||||
|
$dateCopy->setTimestamp($date->getTimestamp());
|
||||||
|
$dateBoundaries = array(
|
||||||
|
$dateCopy->format('Y-m-d 23:59:59'),
|
||||||
|
$dateCopy->sub(new DateInterval('P'.$lookback.'D'))->format('Y-m-d 00:00:00')
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// now recalculate the values for all projects
|
||||||
|
//
|
||||||
|
$projects = Pluf::factory('IDF_Project')->getList();
|
||||||
|
foreach ($projects as $project) {
|
||||||
|
self::recalculateTaxonomy($date, $project, $dateBoundaries, $sectionWeights);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function recalculateTaxonomy(DateTime $date, IDF_Project $project, array $dateBoundaries, array $sectionWeights)
|
||||||
|
{
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
|
||||||
|
$sectionClasses = array(
|
||||||
|
'source' => array('IDF_Commit'),
|
||||||
|
'issues' => array('IDF_Issue'),
|
||||||
|
'wiki' => array('IDF_Wiki_Page', 'IDF_Wiki_Resource'),
|
||||||
|
'review' => array('IDF_Review'),
|
||||||
|
'downloads' => array('IDF_Upload')
|
||||||
|
);
|
||||||
|
|
||||||
|
$value = 0;
|
||||||
|
foreach ($sectionWeights as $section => $weight) {
|
||||||
|
// skip closed / non-existant sections
|
||||||
|
if ($conf->getVal($section.'_access_rights') === 'none')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!array_key_exists($section, $sectionClasses))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$sectionValue = self::calculateActivityValue(
|
||||||
|
$dateBoundaries, $sectionClasses[$section], $project->id);
|
||||||
|
$value = ((1 - $weight) * $value) + ($weight * $sectionValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "project {$project->name} has an activity value of $value\n";
|
||||||
|
|
||||||
|
$sql = new Pluf_SQL('project=%s AND date=%s', array($project->id, $date->format('Y-m-d')));
|
||||||
|
$activity = Pluf::factory('IDF_ProjectActivity')->getOne(array('filter' => $sql->gen()));
|
||||||
|
|
||||||
|
if ($activity == null) {
|
||||||
|
$activity = new IDF_ProjectActivity();
|
||||||
|
$activity->project = $project;
|
||||||
|
$activity->date = $date->format('Y-m-d');
|
||||||
|
$activity->value = $value;
|
||||||
|
$activity->create();
|
||||||
|
} else {
|
||||||
|
$activity->value = $value;
|
||||||
|
$activity->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function calculateActivityValue(array $dateBoundaries, array $classes, $projectId)
|
||||||
|
{
|
||||||
|
$allCount = self::countActivityFor($dateBoundaries, $classes);
|
||||||
|
if ($allCount == 0) return 0;
|
||||||
|
$prjCount = self::countActivityFor($dateBoundaries, $classes, $projectId);
|
||||||
|
return $prjCount / (float) $allCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function countActivityFor(array $dateBoundaries, array $classes, $projectId = null)
|
||||||
|
{
|
||||||
|
static $cache = array();
|
||||||
|
$argIdent = md5(serialize(func_get_args()));
|
||||||
|
if (array_key_exists($argIdent, $cache)) {
|
||||||
|
return $cache[$argIdent];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache[$argIdent] = 0;
|
||||||
|
list($higher, $lower) = $dateBoundaries;
|
||||||
|
$db = Pluf::db();
|
||||||
|
$classes_esc = array();
|
||||||
|
foreach ($classes as $class) {
|
||||||
|
$classes_esc[] = $db->esc($class);
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('model_class IN ('.implode(',', $classes_esc).') '.
|
||||||
|
'AND creation_dtime >= %s AND creation_dtime <= %s',
|
||||||
|
array($lower, $higher));
|
||||||
|
|
||||||
|
if ($projectId !== null) {
|
||||||
|
$sql->SAnd(new Pluf_SQL('project=%s', array($projectId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache[$argIdent] = Pluf::factory('IDF_Timeline')->getCount(array('filter' => $sql->gen()));
|
||||||
|
|
||||||
|
return $cache[$argIdent];
|
||||||
|
}
|
||||||
|
}
|
353
indefero/src/IDF/Commit.php
Normal file
353
indefero/src/IDF/Commit.php
Normal file
@ -0,0 +1,353 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
n# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
Pluf::loadFunction('Pluf_Template_dateAgo');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base definition of a commit.
|
||||||
|
*
|
||||||
|
* By having a reference in the database for each commit, one can
|
||||||
|
* easily generate a timeline or use the search engine. Commit details
|
||||||
|
* are normally always taken from the underlining SCM.
|
||||||
|
*/
|
||||||
|
class IDF_Commit extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
public $extra = null; /**< Extra data as IDF_Gconf object */
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_commits';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'project' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Project',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('project'),
|
||||||
|
'relate_name' => 'commits',
|
||||||
|
),
|
||||||
|
'author' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'is_null' => true,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
'relate_name' => 'submitted_commit',
|
||||||
|
'help_text' => 'This will allow us to list the latest commits of a user in its profile.',
|
||||||
|
),
|
||||||
|
'origauthor' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 150,
|
||||||
|
'help_text' => 'As we do not necessary have the mapping between the author in the database and the scm, we store the scm author commit information here. That way we can update the author info later in the process.',
|
||||||
|
),
|
||||||
|
'scm_id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 50,
|
||||||
|
'index' => true,
|
||||||
|
'help_text' => 'The id of the commit. For git, it will be the SHA1 hash, for subversion it will be the revision id.',
|
||||||
|
),
|
||||||
|
'summary' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'verbose' => __('summary'),
|
||||||
|
),
|
||||||
|
'fullmessage' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('changelog'),
|
||||||
|
'help_text' => 'This is the full message of the commit.',
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
'index' => true,
|
||||||
|
'help_text' => 'Date of creation by the scm',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __toString()
|
||||||
|
{
|
||||||
|
return $this->summary.' - ('.$this->scm_id.')';
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
$str = str_repeat($this->summary.' ', 4).' '.$this->fullmessage;
|
||||||
|
return Pluf_Text::cleanString(html_entity_decode($str, ENT_QUOTES, 'UTF-8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
IDF_Search::index($this);
|
||||||
|
if ($create) {
|
||||||
|
IDF_Timeline::insert($this, $this->get_project(),
|
||||||
|
$this->get_author(), $this->creation_dtime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
IDF_Timeline::remove($this);
|
||||||
|
IDF_Search::remove($this);
|
||||||
|
IDF_Gconf::dropForModel($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a commit from a simple class commit info of a changelog.
|
||||||
|
*
|
||||||
|
* @param stdClass Commit info
|
||||||
|
* @param IDF_Project Current project
|
||||||
|
* @return IDF_Commit
|
||||||
|
*/
|
||||||
|
public static function getOrAdd($change, $project)
|
||||||
|
{
|
||||||
|
$sql = new Pluf_SQL('project=%s AND scm_id=%s',
|
||||||
|
array($project->id, $change->commit));
|
||||||
|
$r = Pluf::factory('IDF_Commit')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($r->count() > 0) {
|
||||||
|
$r[0]->extra = new IDF_Gconf();
|
||||||
|
$r[0]->extra->serialize = true;
|
||||||
|
$r[0]->extra->setModel($r[0]);
|
||||||
|
$r[0]->extra->initCache();
|
||||||
|
return $r[0];
|
||||||
|
}
|
||||||
|
if (!isset($change->full_message)) {
|
||||||
|
$change->full_message = '';
|
||||||
|
}
|
||||||
|
$scm = IDF_Scm::get($project);
|
||||||
|
$commit = new IDF_Commit();
|
||||||
|
$commit->project = $project;
|
||||||
|
$commit->scm_id = $change->commit;
|
||||||
|
$commit->summary = self::toUTF8($change->title);
|
||||||
|
$commit->fullmessage = self::toUTF8($change->full_message);
|
||||||
|
$commit->author = $scm->findAuthor($change->author);
|
||||||
|
$commit->origauthor = self::toUTF8($change->author);
|
||||||
|
$commit->creation_dtime = $change->date;
|
||||||
|
$commit->create();
|
||||||
|
$extra = $scm->getExtraProperties($change);
|
||||||
|
$commit->extra = new IDF_Gconf();
|
||||||
|
$commit->extra->serialize = true; // As we can store arrays
|
||||||
|
$commit->extra->setModel($commit);
|
||||||
|
foreach ($extra as $key => $val) {
|
||||||
|
$commit->extra->setVal($key, $val);
|
||||||
|
}
|
||||||
|
$commit->notify($project->getConf());
|
||||||
|
return $commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert encoding to UTF8.
|
||||||
|
*
|
||||||
|
* If an array is given, the encoding is detected only on the
|
||||||
|
* first value and then used to convert all the strings.
|
||||||
|
*
|
||||||
|
* @param mixed String or array of string to be converted
|
||||||
|
* @param bool Returns the encoding together with the converted text (false)
|
||||||
|
* @return mixed String or array of string or array of res + encoding
|
||||||
|
*/
|
||||||
|
public static function toUTF8($text, $get_encoding=False)
|
||||||
|
{
|
||||||
|
$enc = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
|
||||||
|
$ref = $text;
|
||||||
|
if (is_array($text)) {
|
||||||
|
$ref = $text[0];
|
||||||
|
}
|
||||||
|
if (Pluf_Text_UTF8::check($ref)) {
|
||||||
|
return (!$get_encoding) ? $text : array($text, 'UTF-8');
|
||||||
|
}
|
||||||
|
$encoding = mb_detect_encoding($ref, $enc, true);
|
||||||
|
if ($encoding == false) {
|
||||||
|
$encoding = Pluf_Text_UTF8::detect_cyr_charset($ref);
|
||||||
|
}
|
||||||
|
if (is_array($text)) {
|
||||||
|
foreach ($text as $t) {
|
||||||
|
$res[] = mb_convert_encoding($t, 'UTF-8', $encoding);
|
||||||
|
}
|
||||||
|
return (!$get_encoding) ? $res : array($res, $encoding);
|
||||||
|
} else {
|
||||||
|
$res = mb_convert_encoding($text, 'UTF-8', $encoding);
|
||||||
|
return (!$get_encoding) ? $res : array($res, $encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the timeline fragment for the commit.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return Pluf_Template_SafeString
|
||||||
|
*/
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$this->scm_id));
|
||||||
|
$out = '<tr class="log"><td><a href="'.$url.'">'.
|
||||||
|
Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).
|
||||||
|
'</a></td><td>';
|
||||||
|
$stag = new IDF_Template_ShowUser();
|
||||||
|
$user = $stag->start($this->get_author(), $request, $this->origauthor, false);
|
||||||
|
$tag = new IDF_Template_IssueComment();
|
||||||
|
$out .= $tag->start($this->summary, $request, false);
|
||||||
|
if (0 && $this->fullmessage) {
|
||||||
|
$out .= '<br /><br />'.$tag->start($this->fullmessage, $request, false);
|
||||||
|
}
|
||||||
|
$out .= '</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="extra">
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="helptext right">'.sprintf(__('Commit %1$s, by %2$s'), '<a href="'.$url.'" class="mono">'.$this->scm_id.'</a>', $user).'</div></td></tr>';
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the feed fragment for the commit.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return Pluf_Template_SafeString
|
||||||
|
*/
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
$url = Pluf::f('url_base')
|
||||||
|
.Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$this->scm_id));
|
||||||
|
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
|
||||||
|
$author = ($this->get_author()) ?
|
||||||
|
$this->get_author() : $this->origauthor;
|
||||||
|
$cproject = $this->get_project();
|
||||||
|
$context = new Pluf_Template_Context_Request(
|
||||||
|
$request,
|
||||||
|
array(
|
||||||
|
'c' => $this,
|
||||||
|
'cproject' => $cproject,
|
||||||
|
'url' => $url,
|
||||||
|
'date' => $date,
|
||||||
|
'author' => $author,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/source/feedfragment.xml');
|
||||||
|
return $tmpl->render($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification of change of the object.
|
||||||
|
*
|
||||||
|
* @param IDF_Conf Current configuration
|
||||||
|
* @param bool Creation (true)
|
||||||
|
*/
|
||||||
|
public function notify($conf, $create=true)
|
||||||
|
{
|
||||||
|
// Now we add to the queue, soon we will push everything in
|
||||||
|
// the queue, including email notifications and indexing.
|
||||||
|
// Even if the url is empty, we add to the queue as some
|
||||||
|
// plugins may want to do something with this information in
|
||||||
|
// an asynchronous way.
|
||||||
|
$project = $this->get_project();
|
||||||
|
$scm = $project->getConf()->getVal('scm', 'git');
|
||||||
|
$url = str_replace(array('%p', '%r'),
|
||||||
|
array($project->shortname, $this->scm_id),
|
||||||
|
$conf->getVal('webhook_url', ''));
|
||||||
|
|
||||||
|
// trigger a POST instead of the standard PUT if we're asked for
|
||||||
|
$method = 'PUT';
|
||||||
|
if (Pluf::f('webhook_processing', '') === 'compat') {
|
||||||
|
$method = 'POST';
|
||||||
|
}
|
||||||
|
$payload = array('to_send' => array(
|
||||||
|
'project' => $project->shortname,
|
||||||
|
'rev' => $this->scm_id,
|
||||||
|
'scm' => $scm,
|
||||||
|
'summary' => $this->summary,
|
||||||
|
'fullmessage' => $this->fullmessage,
|
||||||
|
'author' => $this->origauthor,
|
||||||
|
'creation_date' => $this->creation_dtime,
|
||||||
|
),
|
||||||
|
'project_id' => $project->id,
|
||||||
|
'authkey' => $project->getWebHookKey(),
|
||||||
|
'url' => $url,
|
||||||
|
'method' => $method,
|
||||||
|
);
|
||||||
|
$item = new IDF_Queue();
|
||||||
|
$item->type = 'new_commit';
|
||||||
|
$item->payload = $payload;
|
||||||
|
$item->create();
|
||||||
|
|
||||||
|
$current_locale = Pluf_Translation::getLocale();
|
||||||
|
|
||||||
|
$from_email = Pluf::f('from_email');
|
||||||
|
$recipients = $project->getNotificationRecipientsForTab('source');
|
||||||
|
|
||||||
|
foreach ($recipients as $address => $language) {
|
||||||
|
|
||||||
|
if (!empty($this->author) && $this->author->email === $address) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($language);
|
||||||
|
|
||||||
|
$context = new Pluf_Template_Context(array(
|
||||||
|
'commit' => $this,
|
||||||
|
'project' => $project,
|
||||||
|
'url_base' => Pluf::f('url_base'),
|
||||||
|
));
|
||||||
|
|
||||||
|
// commits are usually not updated, therefor we do not
|
||||||
|
// distinguish between create and update here
|
||||||
|
$tplfile = 'idf/source/commit-created-email.txt';
|
||||||
|
$subject = __('New Commit %1$s - %2$s (%3$s)');
|
||||||
|
|
||||||
|
$tmpl = new Pluf_Template($tplfile);
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
|
||||||
|
$email = new Pluf_Mail($from_email,
|
||||||
|
$address,
|
||||||
|
sprintf($subject,
|
||||||
|
$this->scm_id, $this->summary,
|
||||||
|
$project->shortname));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->sendMail();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($current_locale);
|
||||||
|
}
|
||||||
|
}
|
140
indefero/src/IDF/Conf.php
Normal file
140
indefero/src/IDF/Conf.php
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of a project.
|
||||||
|
*
|
||||||
|
* It is just storing a list of key/value
|
||||||
|
* pairs. We can that way store quite a lot of data.
|
||||||
|
*/
|
||||||
|
class IDF_Conf extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
public $datacache = null;
|
||||||
|
public $f = null;
|
||||||
|
protected $_project = null;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_conf';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
//It is automatically added.
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'project' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Project',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('project'),
|
||||||
|
),
|
||||||
|
'vkey' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 50,
|
||||||
|
'verbose' => __('key'),
|
||||||
|
),
|
||||||
|
'vdesc' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('value'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->_a['idx'] = array('project_vkey_idx' =>
|
||||||
|
array(
|
||||||
|
'col' => 'project, vkey',
|
||||||
|
'type' => 'unique',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->f = new IDF_Config_DataProxy($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setProject($project)
|
||||||
|
{
|
||||||
|
$this->datacache = null;
|
||||||
|
$this->_project = $project;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initCache()
|
||||||
|
{
|
||||||
|
$this->datacache = array();
|
||||||
|
$sql = new Pluf_SQL('project=%s', $this->_project->id);
|
||||||
|
foreach ($this->getList(array('filter' => $sql->gen())) as $val) {
|
||||||
|
$this->datacache[$val->vkey] = $val->vdesc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME: This is not efficient when setting a large number of
|
||||||
|
* values in a loop.
|
||||||
|
*/
|
||||||
|
function setVal($key, $value)
|
||||||
|
{
|
||||||
|
if (!is_null($this->getVal($key, null))
|
||||||
|
and $value == $this->getVal($key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->delVal($key, false);
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->project = $this->_project;
|
||||||
|
$conf->vkey = $key;
|
||||||
|
$conf->vdesc = $value;
|
||||||
|
$conf->create();
|
||||||
|
$this->initCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVal($key, $default='')
|
||||||
|
{
|
||||||
|
if ($this->datacache === null) {
|
||||||
|
$this->initCache();
|
||||||
|
}
|
||||||
|
return (isset($this->datacache[$key])) ? $this->datacache[$key] : $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
function delVal($key, $initcache=true)
|
||||||
|
{
|
||||||
|
$gconf = new IDF_Conf();
|
||||||
|
$sql = new Pluf_SQL('vkey=%s AND project=%s', array($key, $this->_project->id));
|
||||||
|
foreach ($gconf->getList(array('filter' => $sql->gen())) as $c) {
|
||||||
|
$c->delete();
|
||||||
|
}
|
||||||
|
if ($initcache) {
|
||||||
|
$this->initCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getKeys()
|
||||||
|
{
|
||||||
|
if ($this->datacache === null) {
|
||||||
|
$this->initCache();
|
||||||
|
}
|
||||||
|
return array_keys($this->datacache);
|
||||||
|
}
|
||||||
|
}
|
42
indefero/src/IDF/Config/DataProxy.php
Normal file
42
indefero/src/IDF/Config/DataProxy.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Field proxy to access the configuration data through
|
||||||
|
* {$conf.f.fieldname} in a template.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class IDF_Config_DataProxy
|
||||||
|
{
|
||||||
|
protected $obj = null;
|
||||||
|
|
||||||
|
public function __construct(&$obj)
|
||||||
|
{
|
||||||
|
$this->obj = $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __get($field)
|
||||||
|
{
|
||||||
|
return $this->obj->getVal($field);
|
||||||
|
}
|
||||||
|
}
|
472
indefero/src/IDF/Diff.php
Normal file
472
indefero/src/IDF/Diff.php
Normal file
@ -0,0 +1,472 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diff parser.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Diff
|
||||||
|
{
|
||||||
|
public $path_strip_level = 0;
|
||||||
|
protected $lines = array();
|
||||||
|
|
||||||
|
public $files = array();
|
||||||
|
|
||||||
|
public function __construct($diff, $path_strip_level = 0)
|
||||||
|
{
|
||||||
|
$this->path_strip_level = $path_strip_level;
|
||||||
|
$this->lines = IDF_FileUtil::splitIntoLines($diff, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse()
|
||||||
|
{
|
||||||
|
$current_file = '';
|
||||||
|
$current_chunk = 0;
|
||||||
|
$lline = 0;
|
||||||
|
$rline = 0;
|
||||||
|
$files = array();
|
||||||
|
$indiff = false; // Used to skip the headers in the git patches
|
||||||
|
$i = 0; // Used to skip the end of a git patch with --\nversion number
|
||||||
|
$diffsize = count($this->lines);
|
||||||
|
while ($i < $diffsize) {
|
||||||
|
// look for the potential beginning of a diff
|
||||||
|
if (substr($this->lines[$i], 0, 4) !== '--- ') {
|
||||||
|
$i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we're inside a diff candiate
|
||||||
|
$oldfileline = $this->lines[$i++];
|
||||||
|
$newfileline = $this->lines[$i++];
|
||||||
|
if (substr($newfileline, 0, 4) !== '+++ ') {
|
||||||
|
// not a valid diff here, move on
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use new file name by default
|
||||||
|
preg_match("/^\+\+\+ ([^\t\n\r]+)/", $newfileline, $m);
|
||||||
|
$current_file = $m[1];
|
||||||
|
if ($current_file === '/dev/null') {
|
||||||
|
// except if it's /dev/null, use the old one instead
|
||||||
|
// eg. mtn 0.48 and newer
|
||||||
|
preg_match("/^--- ([^\t\r\n]+)/", $oldfileline, $m);
|
||||||
|
$current_file = $m[1];
|
||||||
|
}
|
||||||
|
if ($this->path_strip_level > 0) {
|
||||||
|
$fileparts = explode('/', $current_file, $this->path_strip_level+1);
|
||||||
|
$current_file = array_pop($fileparts);
|
||||||
|
}
|
||||||
|
$current_chunk = 0;
|
||||||
|
$files[$current_file] = array();
|
||||||
|
$files[$current_file]['chunks'] = array();
|
||||||
|
$files[$current_file]['chunks_def'] = array();
|
||||||
|
|
||||||
|
while ($i < $diffsize && substr($this->lines[$i], 0, 3) === '@@ ') {
|
||||||
|
$elems = preg_match('/@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@.*/',
|
||||||
|
$this->lines[$i++], $results);
|
||||||
|
if ($elems != 1) {
|
||||||
|
// hunk is badly formatted
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$delstart = $results[1];
|
||||||
|
$dellines = $results[2] === '' ? 1 : $results[2];
|
||||||
|
$addstart = $results[3];
|
||||||
|
$addlines = $results[4] === '' ? 1 : $results[4];
|
||||||
|
|
||||||
|
$files[$current_file]['chunks_def'][] = array(
|
||||||
|
array($delstart, $dellines), array($addstart, $addlines)
|
||||||
|
);
|
||||||
|
$files[$current_file]['chunks'][] = array();
|
||||||
|
|
||||||
|
while ($i < $diffsize && ($addlines >= 0 || $dellines >= 0)) {
|
||||||
|
$linetype = $this->lines[$i] != '' ? $this->lines[$i][0] : false;
|
||||||
|
$content = substr($this->lines[$i], 1);
|
||||||
|
switch ($linetype) {
|
||||||
|
case ' ':
|
||||||
|
$files[$current_file]['chunks'][$current_chunk][] =
|
||||||
|
array($delstart, $addstart, $content);
|
||||||
|
$dellines--;
|
||||||
|
$addlines--;
|
||||||
|
$delstart++;
|
||||||
|
$addstart++;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
$files[$current_file]['chunks'][$current_chunk][] =
|
||||||
|
array('', $addstart, $content);
|
||||||
|
$addlines--;
|
||||||
|
$addstart++;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
$files[$current_file]['chunks'][$current_chunk][] =
|
||||||
|
array($delstart, '', $content);
|
||||||
|
$dellines--;
|
||||||
|
$delstart++;
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
// no new line at the end of this file; remove pseudo new line from last line
|
||||||
|
$cur = count($files[$current_file]['chunks'][$current_chunk]) - 1;
|
||||||
|
$files[$current_file]['chunks'][$current_chunk][$cur][2] =
|
||||||
|
rtrim($files[$current_file]['chunks'][$current_chunk][$cur][2], "\r\n");
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$current_chunk++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->files = $files;
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the html version of a parsed diff.
|
||||||
|
*/
|
||||||
|
public function as_html()
|
||||||
|
{
|
||||||
|
$out = '';
|
||||||
|
foreach ($this->files as $filename => $file) {
|
||||||
|
$pretty = '';
|
||||||
|
$fileinfo = IDF_FileUtil::getMimeType($filename);
|
||||||
|
if (IDF_FileUtil::isSupportedExtension($fileinfo[2])) {
|
||||||
|
$pretty = ' prettyprint';
|
||||||
|
}
|
||||||
|
|
||||||
|
$cc = 1;
|
||||||
|
$offsets = array();
|
||||||
|
$contents = array();
|
||||||
|
|
||||||
|
foreach ($file['chunks'] as $chunk) {
|
||||||
|
foreach ($chunk as $line) {
|
||||||
|
list($left, $right, $content) = $line;
|
||||||
|
if ($left and $right) {
|
||||||
|
$class = 'context';
|
||||||
|
} elseif ($left) {
|
||||||
|
$class = 'removed';
|
||||||
|
} else {
|
||||||
|
$class = 'added';
|
||||||
|
}
|
||||||
|
|
||||||
|
$offsets[] = sprintf('<td>%s</td><td>%s</td>', $left, $right);
|
||||||
|
$content = IDF_FileUtil::emphasizeControlCharacters(Pluf_esc($content));
|
||||||
|
$contents[] = sprintf('<td class="%s%s mono">%s</td>', $class, $pretty, $content);
|
||||||
|
}
|
||||||
|
if (count($file['chunks']) > $cc) {
|
||||||
|
$offsets[] = '<td class="next">...</td><td class="next">...</td>';
|
||||||
|
$contents[] = '<td class="next"></td>';
|
||||||
|
}
|
||||||
|
$cc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
list($added, $removed) = end($file['chunks_def']);
|
||||||
|
|
||||||
|
$added = $added[0] + $added[1];
|
||||||
|
$leftwidth = 0;
|
||||||
|
if ($added > 0)
|
||||||
|
$leftwidth = ((ceil(log10($added)) + 1) * 8) + 17;
|
||||||
|
|
||||||
|
$removed = $removed[0] + $removed[1];
|
||||||
|
$rightwidth = 0;
|
||||||
|
if ($removed > 0)
|
||||||
|
$rightwidth = ((ceil(log10($removed)) + 1) * 8) + 17;
|
||||||
|
|
||||||
|
// we need to correct the width of a single column a little
|
||||||
|
// to take less space and to hide the empty one
|
||||||
|
$class = '';
|
||||||
|
if ($leftwidth == 0) {
|
||||||
|
$class = 'left-hidden';
|
||||||
|
$rightwidth -= floor(log10($removed));
|
||||||
|
}
|
||||||
|
else if ($rightwidth == 0) {
|
||||||
|
$class = 'right-hidden';
|
||||||
|
$leftwidth -= floor(log10($added));
|
||||||
|
}
|
||||||
|
|
||||||
|
$inner_linecounts =
|
||||||
|
'<table class="diff-linecounts '.$class.'">' ."\n".
|
||||||
|
'<colgroup><col width="'.$leftwidth.'" /><col width="'. $rightwidth.'" /></colgroup>' ."\n".
|
||||||
|
'<tr class="line">' .
|
||||||
|
implode('</tr>'."\n".'<tr class="line">', $offsets).
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
|
||||||
|
$inner_contents =
|
||||||
|
'<table class="diff-contents">' ."\n".
|
||||||
|
'<tr class="line">' .
|
||||||
|
implode('</tr>'."\n".'<tr class="line">', $contents) .
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
$out .= '<table class="diff unified">' ."\n".
|
||||||
|
'<colgroup><col width="'.($leftwidth + $rightwidth + 1).'" /><col width="*" /></colgroup>' ."\n".
|
||||||
|
'<tr id="diff-'.md5($filename).'">'.
|
||||||
|
'<th colspan="2">'.Pluf_esc($filename).'</th>'.
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'<tr>' .
|
||||||
|
'<td>'. $inner_linecounts .'</td>'. "\n".
|
||||||
|
'<td><div class="scroll">'. $inner_contents .'</div></td>'.
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Review patch.
|
||||||
|
*
|
||||||
|
* Given the original file as a string and the parsed
|
||||||
|
* corresponding diff chunks, generate a side by side view of the
|
||||||
|
* original file and new file with added/removed lines.
|
||||||
|
*
|
||||||
|
* Example of use:
|
||||||
|
*
|
||||||
|
* $diff = new IDF_Diff(file_get_contents($diff_file));
|
||||||
|
* $orig = file_get_contents($orig_file);
|
||||||
|
* $diff->parse();
|
||||||
|
* echo $diff->fileCompare($orig, $diff->files[$orig_file], $diff_file);
|
||||||
|
*
|
||||||
|
* @param string Original file
|
||||||
|
* @param array Chunk description of the diff corresponding to the file
|
||||||
|
* @param string Original file name
|
||||||
|
* @param int Number of lines before/after the chunk to be displayed (10)
|
||||||
|
* @return Pluf_Template_SafeString The table body
|
||||||
|
*/
|
||||||
|
public function fileCompare($orig, $chunks, $filename, $context=10)
|
||||||
|
{
|
||||||
|
$orig_lines = IDF_FileUtil::splitIntoLines($orig);
|
||||||
|
$new_chunks = $this->mergeChunks($orig_lines, $chunks, $context);
|
||||||
|
return $this->renderCompared($new_chunks, $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mergeChunks($orig_lines, $chunks, $context=10)
|
||||||
|
{
|
||||||
|
$spans = array();
|
||||||
|
$new_chunks = array();
|
||||||
|
$min_line = 0;
|
||||||
|
$max_line = 0;
|
||||||
|
//if (count($chunks['chunks_def']) == 0) return '';
|
||||||
|
foreach ($chunks['chunks_def'] as $chunk) {
|
||||||
|
$start = ($chunk[0][0] > $context) ? $chunk[0][0]-$context : 0;
|
||||||
|
$end = (($chunk[0][0]+$chunk[0][1]+$context-1) < count($orig_lines)) ? $chunk[0][0]+$chunk[0][1]+$context-1 : count($orig_lines);
|
||||||
|
$spans[] = array($start, $end);
|
||||||
|
}
|
||||||
|
// merge chunks/get the chunk lines
|
||||||
|
// these are reference lines
|
||||||
|
$chunk_lines = array();
|
||||||
|
foreach ($chunks['chunks'] as $chunk) {
|
||||||
|
foreach ($chunk as $line) {
|
||||||
|
$chunk_lines[] = $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i = 0;
|
||||||
|
foreach ($chunks['chunks'] as $chunk) {
|
||||||
|
$n_chunk = array();
|
||||||
|
// add lines before
|
||||||
|
if ($chunk[0][0] > $spans[$i][0]) {
|
||||||
|
for ($lc=$spans[$i][0];$lc<$chunk[0][0];$lc++) {
|
||||||
|
$exists = false;
|
||||||
|
foreach ($chunk_lines as $line) {
|
||||||
|
if ($lc == $line[0]
|
||||||
|
or ($chunk[0][1]-$chunk[0][0]+$lc) == $line[1]) {
|
||||||
|
$exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$exists) {
|
||||||
|
$orig = isset($orig_lines[$lc-1]) ? $orig_lines[$lc-1] : '';
|
||||||
|
$n_chunk[] = array(
|
||||||
|
$lc,
|
||||||
|
$chunk[0][1]-$chunk[0][0]+$lc,
|
||||||
|
$orig
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add chunk lines
|
||||||
|
foreach ($chunk as $line) {
|
||||||
|
$n_chunk[] = $line;
|
||||||
|
}
|
||||||
|
// add lines after
|
||||||
|
$lline = $line;
|
||||||
|
if (!empty($lline[0]) and $lline[0] < $spans[$i][1]) {
|
||||||
|
for ($lc=$lline[0];$lc<=$spans[$i][1];$lc++) {
|
||||||
|
$exists = false;
|
||||||
|
foreach ($chunk_lines as $line) {
|
||||||
|
if ($lc == $line[0] or ($lline[1]-$lline[0]+$lc) == $line[1]) {
|
||||||
|
$exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$exists) {
|
||||||
|
$n_chunk[] = array(
|
||||||
|
$lc,
|
||||||
|
$lline[1]-$lline[0]+$lc,
|
||||||
|
$orig_lines[$lc-1]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$new_chunks[] = $n_chunk;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
// Now, each chunk has the right length, we need to merge them
|
||||||
|
// when needed
|
||||||
|
$nnew_chunks = array();
|
||||||
|
$i = 0;
|
||||||
|
foreach ($new_chunks as $chunk) {
|
||||||
|
if ($i>0) {
|
||||||
|
$lline = end($nnew_chunks[$i-1]);
|
||||||
|
if ($chunk[0][0] <= $lline[0]+1) {
|
||||||
|
// need merging
|
||||||
|
foreach ($chunk as $line) {
|
||||||
|
if ($line[0] > $lline[0] or empty($line[0])) {
|
||||||
|
$nnew_chunks[$i-1][] = $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$nnew_chunks[] = $chunk;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$nnew_chunks[] = $chunk;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $nnew_chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function renderCompared($chunks, $filename)
|
||||||
|
{
|
||||||
|
$fileinfo = IDF_FileUtil::getMimeType($filename);
|
||||||
|
$pretty = '';
|
||||||
|
if (IDF_FileUtil::isSupportedExtension($fileinfo[2])) {
|
||||||
|
$pretty = ' prettyprint';
|
||||||
|
}
|
||||||
|
|
||||||
|
$cc = 1;
|
||||||
|
$left_offsets = array();
|
||||||
|
$left_contents = array();
|
||||||
|
$right_offsets = array();
|
||||||
|
$right_contents = array();
|
||||||
|
|
||||||
|
$max_lineno_left = $max_lineno_right = 0;
|
||||||
|
|
||||||
|
foreach ($chunks as $chunk) {
|
||||||
|
foreach ($chunk as $line) {
|
||||||
|
$left = '';
|
||||||
|
$right = '';
|
||||||
|
$content = IDF_FileUtil::emphasizeControlCharacters(Pluf_esc($line[2]));
|
||||||
|
|
||||||
|
if ($line[0] and $line[1]) {
|
||||||
|
$class = 'context';
|
||||||
|
$left = $right = $content;
|
||||||
|
} elseif ($line[0]) {
|
||||||
|
$class = 'removed';
|
||||||
|
$left = $content;
|
||||||
|
} else {
|
||||||
|
$class = 'added';
|
||||||
|
$right = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$left_offsets[] = sprintf('<td>%s</td>', $line[0]);
|
||||||
|
$right_offsets[] = sprintf('<td>%s</td>', $line[1]);
|
||||||
|
$left_contents[] = sprintf('<td class="%s%s mono">%s</td>', $class, $pretty, $left);
|
||||||
|
$right_contents[] = sprintf('<td class="%s%s mono">%s</td>', $class, $pretty, $right);
|
||||||
|
|
||||||
|
$max_lineno_left = max($max_lineno_left, $line[0]);
|
||||||
|
$max_lineno_right = max($max_lineno_right, $line[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($chunks) > $cc) {
|
||||||
|
$left_offsets[] = '<td class="next">...</td>';
|
||||||
|
$right_offsets[] = '<td class="next">...</td>';
|
||||||
|
$left_contents[] = '<td></td>';
|
||||||
|
$right_contents[] = '<td></td>';
|
||||||
|
}
|
||||||
|
$cc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$leftwidth = 1;
|
||||||
|
if ($max_lineno_left > 0)
|
||||||
|
$leftwidth = ((ceil(log10($max_lineno_left)) + 1) * 8) + 17;
|
||||||
|
|
||||||
|
$rightwidth = 1;
|
||||||
|
if ($max_lineno_right > 0)
|
||||||
|
$rightwidth = ((ceil(log10($max_lineno_right)) + 1) * 8) + 17;
|
||||||
|
|
||||||
|
$inner_linecounts_left =
|
||||||
|
'<table class="diff-linecounts">' ."\n".
|
||||||
|
'<colgroup><col width="'.$leftwidth.'" /></colgroup>' ."\n".
|
||||||
|
'<tr class="line">' .
|
||||||
|
implode('</tr>'."\n".'<tr class="line">', $left_offsets).
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
$inner_linecounts_right =
|
||||||
|
'<table class="diff-linecounts">' ."\n".
|
||||||
|
'<colgroup><col width="'.$rightwidth.'" /></colgroup>' ."\n".
|
||||||
|
'<tr class="line">' .
|
||||||
|
implode('</tr>'."\n".'<tr class="line">', $right_offsets).
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
$inner_contents_left =
|
||||||
|
'<table class="diff-contents">' ."\n".
|
||||||
|
'<tr class="line">' .
|
||||||
|
implode('</tr>'."\n".'<tr class="line">', $left_contents) .
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
$inner_contents_right =
|
||||||
|
'<table class="diff-contents">' ."\n".
|
||||||
|
'<tr class="line">' .
|
||||||
|
implode('</tr>'."\n".'<tr class="line">', $right_contents) .
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
$out =
|
||||||
|
'<table class="diff context">' ."\n".
|
||||||
|
'<colgroup>' .
|
||||||
|
'<col width="'.($leftwidth + 1).'" /><col width="*" />' .
|
||||||
|
'<col width="'.($rightwidth + 1).'" /><col width="*" />' .
|
||||||
|
'</colgroup>' ."\n".
|
||||||
|
'<tr id="diff-'.md5($filename).'">'.
|
||||||
|
'<th colspan="4">'.Pluf_esc($filename).'</th>'.
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'<tr>' .
|
||||||
|
'<th colspan="2">'.__('Old').'</th><th colspan="2">'.__('New').'</th>' .
|
||||||
|
'</tr>'.
|
||||||
|
'<tr>' .
|
||||||
|
'<td>'. $inner_linecounts_left .'</td>'. "\n".
|
||||||
|
'<td><div class="scroll">'. $inner_contents_left .'</div></td>'. "\n".
|
||||||
|
'<td>'. $inner_linecounts_right .'</td>'. "\n".
|
||||||
|
'<td><div class="scroll">'. $inner_contents_right .'</div></td>'. "\n".
|
||||||
|
'</tr>' ."\n".
|
||||||
|
'</table>' ."\n";
|
||||||
|
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
}
|
96
indefero/src/IDF/EmailAddress.php
Normal file
96
indefero/src/IDF/EmailAddress.php
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage of Email addresses
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_EmailAddress extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_emailaddresses';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
//It is automatically added.
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'user' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('user'),
|
||||||
|
),
|
||||||
|
'address' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Email',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('email'),
|
||||||
|
'unique' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// WARNING: Not using getSqlTable on the Pluf_User object to
|
||||||
|
// avoid recursion.
|
||||||
|
$t_users = $this->_con->pfx.'users';
|
||||||
|
$this->_a['views'] = array(
|
||||||
|
'join_user' =>
|
||||||
|
array(
|
||||||
|
'join' => 'LEFT JOIN '.$t_users
|
||||||
|
.' ON '.$t_users.'.id='.$this->_con->qn('user'),
|
||||||
|
'select' => $this->getSelect().', '
|
||||||
|
.$t_users.'.login AS login',
|
||||||
|
'props' => array('login' => 'login'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_email_addresses_for_user($user)
|
||||||
|
{
|
||||||
|
$addr = $user->get_idf_emailaddress_list();
|
||||||
|
$addr[] = (object)array("address" => $user->email, "id" => -1, "user" => $user);
|
||||||
|
return $addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_user_for_email_address($email)
|
||||||
|
{
|
||||||
|
$sql = new Pluf_SQL('email=%s', array($email));
|
||||||
|
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() > 0) {
|
||||||
|
return $users[0];
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('address=%s', array($email));
|
||||||
|
$matches = Pluf::factory('IDF_EmailAddress')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($matches->count() > 0) {
|
||||||
|
return new Pluf_User($matches[0]->user);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
212
indefero/src/IDF/FileUtil.php
Normal file
212
indefero/src/IDF/FileUtil.php
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File utilities.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_FileUtil
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Extension supported by the syntax highlighter.
|
||||||
|
*/
|
||||||
|
public static $supportedExtenstions = array(
|
||||||
|
'ascx', 'ashx', 'asmx', 'aspx', 'browser', 'bsh', 'c', 'cl', 'cc',
|
||||||
|
'config', 'cpp', 'cs', 'csh', 'csproj', 'css', 'cv', 'cyc', 'el', 'fs',
|
||||||
|
'h', 'hh', 'hpp', 'hs', 'html', 'html', 'java', 'js', 'lisp', 'master',
|
||||||
|
'pas', 'perl', 'php', 'pl', 'pm', 'py', 'rb', 'scm', 'sh', 'sitemap',
|
||||||
|
'skin', 'sln', 'svc', 'vala', 'vb', 'vbproj', 'vbs', 'wsdl', 'xhtml',
|
||||||
|
'xml', 'xsd', 'xsl', 'xslt');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if an extension is supported by the syntax highlighter.
|
||||||
|
*
|
||||||
|
* @param string The extension to test
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isSupportedExtension($extension)
|
||||||
|
{
|
||||||
|
return in_array($extension, self::$supportedExtenstions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a HTML snippet with a line-by-line pre-rendered table
|
||||||
|
* for the given source content
|
||||||
|
*
|
||||||
|
* @param array file information as returned by getMimeType or getMimeTypeFromContent
|
||||||
|
* @param string the content of the file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function highLight($fileinfo, $content)
|
||||||
|
{
|
||||||
|
$pretty = '';
|
||||||
|
if (self::isSupportedExtension($fileinfo[2])) {
|
||||||
|
$pretty = ' prettyprint';
|
||||||
|
}
|
||||||
|
$table = array();
|
||||||
|
$i = 1;
|
||||||
|
foreach (self::splitIntoLines($content) as $line) {
|
||||||
|
$table[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>'
|
||||||
|
.'<td class="code mono'.$pretty.'">'.self::emphasizeControlCharacters(Pluf_esc($line)).'</td></tr>';
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return Pluf_Template::markSafe(implode("\n", $table));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the mime type of a file.
|
||||||
|
*
|
||||||
|
* Use /etc/mime.types to find the type.
|
||||||
|
*
|
||||||
|
* @param string Filename/Filepath
|
||||||
|
* @param array Mime type found or 'application/octet-stream', basename, extension
|
||||||
|
*/
|
||||||
|
public static function getMimeType($file)
|
||||||
|
{
|
||||||
|
static $mimes = null;
|
||||||
|
if ($mimes == null) {
|
||||||
|
$mimes = array();
|
||||||
|
$src = Pluf::f('idf_mimetypes_db', '/etc/mime.types');
|
||||||
|
$filecontent = @file_get_contents($src);
|
||||||
|
if ($filecontent !== false) {
|
||||||
|
$mimes = preg_split("/\015\012|\015|\012/", $filecontent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$info = pathinfo($file);
|
||||||
|
if (isset($info['extension'])) {
|
||||||
|
foreach ($mimes as $mime) {
|
||||||
|
if ('#' != substr($mime, 0, 1)) {
|
||||||
|
$elts = preg_split('/ |\t/', $mime, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
if (in_array($info['extension'], $elts)) {
|
||||||
|
return array($elts[0], $info['basename'], $info['extension']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// we consider that if no extension and base name is all
|
||||||
|
// uppercase, then we have a text file.
|
||||||
|
if ($info['basename'] == strtoupper($info['basename'])) {
|
||||||
|
return array('text/plain', $info['basename'], 'txt');
|
||||||
|
}
|
||||||
|
$info['extension'] = 'bin';
|
||||||
|
}
|
||||||
|
return array('application/octet-stream', $info['basename'], $info['extension']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the mime type of a file using the fileinfo class.
|
||||||
|
*
|
||||||
|
* @param string Filename/Filepath
|
||||||
|
* @param string File content
|
||||||
|
* @return array Mime type found or 'application/octet-stream', basename, extension
|
||||||
|
*/
|
||||||
|
public static function getMimeTypeFromContent($file, $filedata)
|
||||||
|
{
|
||||||
|
$info = pathinfo($file);
|
||||||
|
$res = array('application/octet-stream',
|
||||||
|
$info['basename'],
|
||||||
|
isset($info['extension']) ? $info['extension'] : 'bin');
|
||||||
|
if (function_exists('finfo_open')) {
|
||||||
|
$finfo = finfo_open(FILEINFO_MIME);
|
||||||
|
$mime = finfo_buffer($finfo, $filedata);
|
||||||
|
finfo_close($finfo);
|
||||||
|
if ($mime) {
|
||||||
|
$res[0] = $mime;
|
||||||
|
}
|
||||||
|
if (!isset($info['extension']) && $mime) {
|
||||||
|
$res[2] = (0 === strpos($mime, 'text/')) ? 'txt' : 'bin';
|
||||||
|
} elseif (!isset($info['extension'])) {
|
||||||
|
$res[2] = 'bin';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string into separate lines while retaining the individual
|
||||||
|
* line ending character for every line.
|
||||||
|
*
|
||||||
|
* OS 9 line endings are not supported.
|
||||||
|
*
|
||||||
|
* @param string content
|
||||||
|
* @param boolean if true, skip completely empty lines
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function splitIntoLines($content, $skipEmpty = false)
|
||||||
|
{
|
||||||
|
$last_off = 0;
|
||||||
|
$lines = array();
|
||||||
|
while (preg_match("/\r\n|\n/", $content, $m, PREG_OFFSET_CAPTURE, $last_off)) {
|
||||||
|
$next_off = strlen($m[0][0]) + $m[0][1];
|
||||||
|
$line = substr($content, $last_off, $next_off - $last_off);
|
||||||
|
$last_off = $next_off;
|
||||||
|
if ($line !== $m[0][0] || !$skipEmpty) $lines[] = $line;
|
||||||
|
}
|
||||||
|
$line = substr($content, $last_off);
|
||||||
|
if ($line !== false && strlen($line) > 0) $lines[] = $line;
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This translates most of the C0 ASCII control characters into
|
||||||
|
* their visual counterparts in the 0x24## unicode plane
|
||||||
|
* (http://en.wikipedia.org/wiki/C0_and_C1_control_codes).
|
||||||
|
*
|
||||||
|
* We could add DEL (0x7F) to this set, but unfortunately this
|
||||||
|
* is not nicely mapped to 0x247F in the control plane, but 0x2421
|
||||||
|
* and adding an if expression below just for this is a little bit
|
||||||
|
* of a hassle. And of course, the more esoteric ones from C1 are
|
||||||
|
* missing as well...
|
||||||
|
*
|
||||||
|
* @param string $content
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function emphasizeControlCharacters($content)
|
||||||
|
{
|
||||||
|
return preg_replace(
|
||||||
|
'/([\x00-\x1F])/ue',
|
||||||
|
'"<span class=\"ctrl-char\" title=\"0x".bin2hex("\\1")."\">$".bin2hex("\\1")."</span>"',
|
||||||
|
$content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find if a given mime type is a text file.
|
||||||
|
* This uses the output of the self::getMimeType function.
|
||||||
|
*
|
||||||
|
* @param array (Mime type, file name, extension)
|
||||||
|
* @return bool Is text
|
||||||
|
*/
|
||||||
|
public static function isText($fileinfo)
|
||||||
|
{
|
||||||
|
if (0 === strpos($fileinfo[0], 'text/')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$ext = 'mdtext php-dist h gitignore diff patch';
|
||||||
|
$extra_ext = trim(Pluf::f('idf_extra_text_ext', ''));
|
||||||
|
if (!empty($extra_ext))
|
||||||
|
$ext .= ' ' . $extra_ext;
|
||||||
|
$ext = array_merge(self::$supportedExtenstions, explode(' ' , $ext));
|
||||||
|
return (in_array($fileinfo[2], $ext));
|
||||||
|
}
|
||||||
|
}
|
70
indefero/src/IDF/Forge.php
Normal file
70
indefero/src/IDF/Forge.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A lightweight model for the singleton forge entity
|
||||||
|
*/
|
||||||
|
class IDF_Forge
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
public $id = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var IDF_Gconf
|
||||||
|
*/
|
||||||
|
private $conf;
|
||||||
|
|
||||||
|
private function __construct() {
|
||||||
|
$this->conf = new IDF_Gconf();
|
||||||
|
$this->conf->setModel($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function instance() {
|
||||||
|
return new IDF_Forge();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProjectLabels($default = '') {
|
||||||
|
return $this->conf->getVal('project_labels', $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setProjectLabels($labels) {
|
||||||
|
$this->conf->setVal('project_labels', $labels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCustomForgePageEnabled($enabled) {
|
||||||
|
$this->conf->setVal('custom_forge_page_enabled', $enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isCustomForgePageEnabled($default = false) {
|
||||||
|
return $this->conf->getVal('custom_forge_page_enabled', $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomForgePageContent($default = '') {
|
||||||
|
return $this->conf->getVal('custom_forge_page_content', $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCustomForgePageContent($content) {
|
||||||
|
$this->conf->setVal('custom_forge_page_content', $content);
|
||||||
|
}
|
||||||
|
}
|
47
indefero/src/IDF/Form/Admin/ForgeConf.php
Normal file
47
indefero/src/IDF/Form/Admin/ForgeConf.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright(C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
#(at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the forge's start page.
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_ForgeConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['enabled'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Custom forge page enabled'),
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Content'),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 68,
|
||||||
|
'rows' => 26,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
62
indefero/src/IDF/Form/Admin/LabelConf.php
Normal file
62
indefero/src/IDF/Form/Admin/LabelConf.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright(C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
#(at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of forge labels.
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_LabelConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
const init_project_labels = 'UI:GUI = Applications with graphical user interfaces
|
||||||
|
UI:CLI = Applications with no graphical user interfaces
|
||||||
|
License:BSD = Applications with BSD license
|
||||||
|
License:GPL = Applications with GPL license
|
||||||
|
';
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['project_labels'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Predefined project labels'),
|
||||||
|
'initial' => self::init_project_labels,
|
||||||
|
'widget_attrs' => array('rows' => 13,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_project_labels()
|
||||||
|
{
|
||||||
|
$labels = preg_split("/\s*\n\s*/", $this->cleaned_data['project_labels'], -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
for ($i=0; $i<count($labels); ++$i) {
|
||||||
|
$labels[$i] = trim($labels[$i]);
|
||||||
|
if (!preg_match('/^[\w-]+(:[\w-]+)?(\s*=\s*[^=]+)?$/', $labels[$i])) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(
|
||||||
|
__('The label "%s" is invalid: A label must only consist of alphanumeric '.
|
||||||
|
'characters and dashes, and can optionally contain a ":" with a group prefix.'),
|
||||||
|
$labels[$i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode("\n", $labels);
|
||||||
|
}
|
||||||
|
}
|
422
indefero/src/IDF/Form/Admin/ProjectCreate.php
Normal file
422
indefero/src/IDF/Form/Admin/ProjectCreate.php
Normal file
@ -0,0 +1,422 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a project.
|
||||||
|
*
|
||||||
|
* A kind of merge of the member configuration, overview and the
|
||||||
|
* former source tab.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_ProjectCreate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$choices = array();
|
||||||
|
$options = array(
|
||||||
|
'git' => __('git'),
|
||||||
|
'svn' => __('Subversion'),
|
||||||
|
'mercurial' => __('mercurial'),
|
||||||
|
'mtn' => __('monotone'),
|
||||||
|
);
|
||||||
|
foreach (Pluf::f('allowed_scm', array()) as $key => $class) {
|
||||||
|
$choices[$options[$key]] = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fields['name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Name'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['private_project'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Private project'),
|
||||||
|
'initial' => false,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['shortname'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Shortname'),
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('It must be unique for each project and composed only of letters, digits and dash (-) like "my-project".'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['shortdesc'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Short description'),
|
||||||
|
'help_text' => __('A one line description of the project.'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('size' => '35'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['external_project_url'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('External URL'),
|
||||||
|
'widget_attrs' => array('size' => '35'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['scm'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Repository type'),
|
||||||
|
'initial' => 'git',
|
||||||
|
'widget_attrs' => array('choices' => $choices),
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['svn_remote_url'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Remote Subversion repository'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('size' => '30'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['svn_username'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Repository username'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('size' => '15'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['svn_password'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Repository password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['mtn_master_branch'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Master branch'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('size' => '35'),
|
||||||
|
'help_text' => __('This should be a world-wide unique identifier for your project. A reverse DNS notation like "com.my-domain.my-project" is a good idea.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['owners'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project owners'),
|
||||||
|
'initial' => $extra['user']->login,
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array('rows' => 5,
|
||||||
|
'cols' => 40),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['members'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project members'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$projects = array('--' => '--');
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList(array('order' => 'name ASC')) as $proj) {
|
||||||
|
$projects[$proj->name] = $proj->shortname;
|
||||||
|
}
|
||||||
|
$this->fields['template'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project template'),
|
||||||
|
'initial' => '--',
|
||||||
|
'help_text' => __('Use the given project to initialize the new project. Access rights and general configuration will be taken from the template project.'),
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
'widget_attrs' => array('choices' => $projects),
|
||||||
|
));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Form_Admin_ProjectCreate::initFields
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_Admin_ProjectCreate
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to modify the form
|
||||||
|
* for the creation of a project.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('form' => $form)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('form' => $this);
|
||||||
|
Pluf_Signal::send('IDF_Form_Admin_ProjectCreate::initFields',
|
||||||
|
'IDF_Form_Admin_ProjectCreate', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_owners()
|
||||||
|
{
|
||||||
|
return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['owners']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_members()
|
||||||
|
{
|
||||||
|
return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['members']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_svn_remote_url()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['svn_remote_url'] = (!empty($this->cleaned_data['svn_remote_url'])) ? $this->cleaned_data['svn_remote_url'] : '';
|
||||||
|
$url = trim($this->cleaned_data['svn_remote_url']);
|
||||||
|
if (strlen($url) == 0) return $url;
|
||||||
|
// we accept only starting with http(s):// to avoid people
|
||||||
|
// trying to access the local filesystem.
|
||||||
|
if (!preg_match('#^(http|https)://#', $url)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Only a remote repository available through HTTP or HTTPS is allowed. For example "http://somewhere.com/svn/trunk".'));
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_mtn_master_branch()
|
||||||
|
{
|
||||||
|
// do not validate, but empty the field if a different
|
||||||
|
// SCM should be used
|
||||||
|
if ($this->cleaned_data['scm'] != 'mtn')
|
||||||
|
return '';
|
||||||
|
|
||||||
|
$mtn_master_branch = mb_strtolower($this->cleaned_data['mtn_master_branch']);
|
||||||
|
if (!preg_match('/^([\w\d]+([-][\w\d]+)*)(\.[\w\d]+([-][\w\d]+)*)*$/',
|
||||||
|
$mtn_master_branch)) {
|
||||||
|
throw new Pluf_Form_Invalid(__(
|
||||||
|
'The master branch is empty or contains illegal characters, '.
|
||||||
|
'please use only letters, digits, dashes and dots as separators.'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = new Pluf_SQL('vkey=%s AND vdesc=%s',
|
||||||
|
array('mtn_master_branch', $mtn_master_branch));
|
||||||
|
$l = Pluf::factory('IDF_Conf')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($l->count() > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__(
|
||||||
|
'This master branch is already used. Please select another one.'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mtn_master_branch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_shortname()
|
||||||
|
{
|
||||||
|
$shortname = mb_strtolower($this->cleaned_data['shortname']);
|
||||||
|
if (preg_match('/[^\-A-Za-z0-9]/', $shortname)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('This shortname contains illegal characters, please use only letters, digits and dash (-).'));
|
||||||
|
}
|
||||||
|
if (mb_substr($shortname, 0, 1) == '-') {
|
||||||
|
throw new Pluf_Form_Invalid(__('The shortname cannot start with the dash (-) character.'));
|
||||||
|
}
|
||||||
|
if (mb_substr($shortname, -1) == '-') {
|
||||||
|
throw new Pluf_Form_Invalid(__('The shortname cannot end with the dash (-) character.'));
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('shortname=%s', array($shortname));
|
||||||
|
$l = Pluf::factory('IDF_Project')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($l->count() > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('This shortname is already used. Please select another one.'));
|
||||||
|
}
|
||||||
|
return $shortname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_external_project_url()
|
||||||
|
{
|
||||||
|
return IDF_Form_ProjectConf::checkWebURL($this->cleaned_data['external_project_url']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if ($this->cleaned_data['scm'] != 'svn') {
|
||||||
|
foreach (array('svn_remote_url', 'svn_username', 'svn_password')
|
||||||
|
as $key) {
|
||||||
|
$this->cleaned_data[$key] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->cleaned_data['scm'] != 'mtn') {
|
||||||
|
$this->cleaned_data['mtn_master_branch'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Form_Admin_ProjectCreate::clean
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_Admin_ProjectCreate
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to clean the form
|
||||||
|
* for the creation of a project.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('cleaned_data' => $cleaned_data)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('cleaned_data' => $this->cleaned_data);
|
||||||
|
Pluf_Signal::send('IDF_Form_Admin_ProjectCreate::clean',
|
||||||
|
'IDF_Form_Admin_ProjectCreate', $params);
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a tag for each label
|
||||||
|
$tagids = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::addGlobal($name, $class);
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$project = new IDF_Project();
|
||||||
|
$project->name = $this->cleaned_data['name'];
|
||||||
|
$project->shortname = $this->cleaned_data['shortname'];
|
||||||
|
$project->shortdesc = $this->cleaned_data['shortdesc'];
|
||||||
|
|
||||||
|
$tagids = array();
|
||||||
|
if ($this->cleaned_data['template'] != '--') {
|
||||||
|
// Find the template project
|
||||||
|
$sql = new Pluf_SQL('shortname=%s',
|
||||||
|
array($this->cleaned_data['template']));
|
||||||
|
$tmpl = Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen()));
|
||||||
|
$project->private = $tmpl->private;
|
||||||
|
$project->description = $tmpl->description;
|
||||||
|
|
||||||
|
foreach ($tmpl->get_tags_list() as $tag) {
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$project->private = $this->cleaned_data['private_project'];
|
||||||
|
$project->description = __('Click on the Project Management tab to set the description of your project.');
|
||||||
|
|
||||||
|
// Add a tag for each label
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::addGlobal($name, $class);
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$project->create();
|
||||||
|
$project->batchAssoc('IDF_Tag', $tagids);
|
||||||
|
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
|
||||||
|
if ($this->cleaned_data['template'] != '--') {
|
||||||
|
$tmplconf = new IDF_Conf();
|
||||||
|
$tmplconf->setProject($tmpl);
|
||||||
|
|
||||||
|
$allKeys = $tmplconf->getKeys();
|
||||||
|
$scm = $this->cleaned_data['scm'];
|
||||||
|
$ignoreKeys = array('scm', 'external_project_url', 'logo');
|
||||||
|
|
||||||
|
// copy over all existing variables, except scm-related data and
|
||||||
|
// the project url / logo
|
||||||
|
foreach ($allKeys as $key) {
|
||||||
|
if (in_array($key, $ignoreKeys) || strpos($key, $scm.'_') === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$conf->setVal($key, $tmplconf->getVal($key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$keys = array(
|
||||||
|
'scm', 'svn_remote_url', 'svn_username',
|
||||||
|
'svn_password', 'mtn_master_branch',
|
||||||
|
'external_project_url'
|
||||||
|
);
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
$this->cleaned_data[$key] = !empty($this->cleaned_data[$key]) ?
|
||||||
|
$this->cleaned_data[$key] : '';
|
||||||
|
$conf->setVal($key, $this->cleaned_data[$key]);
|
||||||
|
}
|
||||||
|
$project->created();
|
||||||
|
|
||||||
|
if ($this->cleaned_data['template'] == '--') {
|
||||||
|
IDF_Form_MembersConf::updateMemberships($project,
|
||||||
|
$this->cleaned_data);
|
||||||
|
} else {
|
||||||
|
// Get the membership of the template $tmpl
|
||||||
|
IDF_Form_MembersConf::updateMemberships($project,
|
||||||
|
$tmpl->getMembershipData('string'));
|
||||||
|
}
|
||||||
|
$project->membershipsUpdated();
|
||||||
|
return $project;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the template project exists.
|
||||||
|
*/
|
||||||
|
public function clean_template()
|
||||||
|
{
|
||||||
|
if ($this->cleaned_data['template'] == '--') {
|
||||||
|
return $this->cleaned_data['template'];
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('shortname=%s', array($this->cleaned_data['template']));
|
||||||
|
if (Pluf::factory('IDF_Project')->getOne(array('filter' => $sql->gen())) == null) {
|
||||||
|
throw new Pluf_Form_Invalid(__('This project is not available.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['template'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
88
indefero/src/IDF/Form/Admin/ProjectDelete.php
Normal file
88
indefero/src/IDF/Form/Admin/ProjectDelete.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a project.
|
||||||
|
*
|
||||||
|
* It is also removing the SCM files, so handle with care.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_ProjectDelete extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->fields['code'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Confirmation code'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
$this->fields['agree'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('I have made a backup of all the important data of this project.'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_code()
|
||||||
|
{
|
||||||
|
$code = $this->cleaned_data['code'];
|
||||||
|
if ($code != $this->getCode()) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The confirmation code does not match. Please provide a valid confirmation code to delete the project.'));
|
||||||
|
}
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_agree()
|
||||||
|
{
|
||||||
|
if (!$this->cleaned_data['agree']) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Sorry, you really need to backup your data before deletion.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['agree'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode()
|
||||||
|
{
|
||||||
|
return substr(md5(Pluf::f('secret_key').$this->user->id.'.'.$this->project->id),
|
||||||
|
0, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// So, we drop the project, it will cascade and delete all the
|
||||||
|
// elements of the project. For large projects, this may use
|
||||||
|
// quite some memory.
|
||||||
|
$this->project->delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
196
indefero/src/IDF/Form/Admin/ProjectUpdate.php
Normal file
196
indefero/src/IDF/Form/Admin/ProjectUpdate.php
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a project.
|
||||||
|
*
|
||||||
|
* A kind of merge of the member configuration and overview in the
|
||||||
|
* project administration area.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_ProjectUpdate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
$members = $this->project->getMembershipData('string');
|
||||||
|
$conf = $this->project->getConf();
|
||||||
|
|
||||||
|
$this->fields['name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Name'),
|
||||||
|
'initial' => $this->project->name,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['shortdesc'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Short description'),
|
||||||
|
'help_text' => __('A one line description of the project.'),
|
||||||
|
'initial' => $this->project->shortdesc,
|
||||||
|
'widget_attrs' => array('size' => '35'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['external_project_url'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('External URL'),
|
||||||
|
'widget_attrs' => array('size' => '35'),
|
||||||
|
'initial' => $conf->getVal('external_project_url'),
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->project->getConf()->getVal('scm') == 'mtn') {
|
||||||
|
$this->fields['mtn_master_branch'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Master branch'),
|
||||||
|
'initial' => $conf->getVal('mtn_master_branch'),
|
||||||
|
'widget_attrs' => array('size' => '35'),
|
||||||
|
'help_text' => __('This should be a world-wide unique identifier for your project. A reverse DNS notation like "com.my-domain.my-project" is a good idea.'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tags = $this->project->get_tags_list();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$initial = '';
|
||||||
|
if (isset($tags[$i-1])) {
|
||||||
|
if ($tags[$i-1]->class != 'Other') {
|
||||||
|
$initial = (string) $tags[$i-1];
|
||||||
|
} else {
|
||||||
|
$initial = $tags[$i-1]->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$this->fields['owners'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project owners'),
|
||||||
|
'initial' => $members['owners'],
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array('rows' => 5,
|
||||||
|
'cols' => 40),
|
||||||
|
));
|
||||||
|
$this->fields['members'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project members'),
|
||||||
|
'initial' => $members['members'],
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_mtn_master_branch()
|
||||||
|
{
|
||||||
|
$mtn_master_branch = mb_strtolower($this->cleaned_data['mtn_master_branch']);
|
||||||
|
if (!preg_match('/^([\w\d]+([-][\w\d]+)*)(\.[\w\d]+([-][\w\d]+)*)*$/',
|
||||||
|
$mtn_master_branch)) {
|
||||||
|
throw new Pluf_Form_Invalid(__(
|
||||||
|
'The master branch is empty or contains illegal characters, '.
|
||||||
|
'please use only letters, digits, dashes and dots as separators.'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = new Pluf_SQL('vkey=%s AND vdesc=%s AND project!=%s',
|
||||||
|
array('mtn_master_branch', $mtn_master_branch,
|
||||||
|
(string)$this->project->id));
|
||||||
|
$l = Pluf::factory('IDF_Conf')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($l->count() > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__(
|
||||||
|
'This master branch is already used. Please select another one.'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mtn_master_branch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_owners()
|
||||||
|
{
|
||||||
|
return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['owners']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_members()
|
||||||
|
{
|
||||||
|
return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['members']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_external_project_url()
|
||||||
|
{
|
||||||
|
return IDF_Form_ProjectConf::checkWebURL($this->cleaned_data['external_project_url']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a tag for each label
|
||||||
|
$tagids = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::addGlobal($name, $class);
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->project->batchAssoc('IDF_Tag', $tagids);
|
||||||
|
|
||||||
|
IDF_Form_MembersConf::updateMemberships($this->project,
|
||||||
|
$this->cleaned_data);
|
||||||
|
$this->project->membershipsUpdated();
|
||||||
|
|
||||||
|
$this->project->name = $this->cleaned_data['name'];
|
||||||
|
$this->project->shortdesc = $this->cleaned_data['shortdesc'];
|
||||||
|
$this->project->update();
|
||||||
|
|
||||||
|
$conf = $this->project->getConf();
|
||||||
|
$keys = array('mtn_master_branch', 'external_project_url');
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (array_key_exists($key, $this->cleaned_data)) {
|
||||||
|
if (!empty($this->cleaned_data[$key])) {
|
||||||
|
$conf->setVal($key, $this->cleaned_data[$key]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$conf->delVal($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
215
indefero/src/IDF/Form/Admin/UserCreate.php
Normal file
215
indefero/src/IDF/Form/Admin/UserCreate.php
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow an admin to create a user.
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_UserCreate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $request = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->request = $extra['request'];
|
||||||
|
$this->fields['first_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('First name'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['last_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Last name'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['login'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Login'),
|
||||||
|
'max_length' => 15,
|
||||||
|
'min_length' => 3,
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('The login must be between 3 and 15 characters long and contains only letters and digits.'),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 15,
|
||||||
|
'size' => 10,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['email'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Email'),
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('Double check the email address as the password is sent directly to the user.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['language'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Language'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'choices' =>
|
||||||
|
Pluf_L10n::getInstalledLanguages()
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['public_key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Add a public key'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('rows' => 3,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'help_text' => __('Paste a SSH or monotone public key. Be careful to not provide your private key here!')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
$password = Pluf_Utils::getPassword();
|
||||||
|
$user = new Pluf_User();
|
||||||
|
$user->setFromFormData($this->cleaned_data);
|
||||||
|
$user->active = true;
|
||||||
|
$user->staff = false;
|
||||||
|
$user->administrator = false;
|
||||||
|
$user->setPassword(base64_encode(sha1($password,TRUE)));
|
||||||
|
$user->create();
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* Pluf_User::passwordUpdated
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_Admin_UserCreate
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal is sent when a user is created
|
||||||
|
* by the staff.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('user' => $user)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('user' => $user);
|
||||||
|
Pluf_Signal::send('Pluf_User::passwordUpdated',
|
||||||
|
'IDF_Form_Admin_UserCreate', $params);
|
||||||
|
// Create the public key as needed
|
||||||
|
if ('' !== $this->cleaned_data['public_key']) {
|
||||||
|
$key = new IDF_Key();
|
||||||
|
$key->user = $user;
|
||||||
|
$key->content = $this->cleaned_data['public_key'];
|
||||||
|
$key->create();
|
||||||
|
}
|
||||||
|
// Send an email to the user with the password
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
$url = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views::login', array(), array(), false);
|
||||||
|
$context = new Pluf_Template_Context(
|
||||||
|
array('password' => Pluf_Template::markSafe($password),
|
||||||
|
'user' => $user,
|
||||||
|
'url' => Pluf_Template::markSafe($url),
|
||||||
|
'admin' => $this->request->user,
|
||||||
|
));
|
||||||
|
$tmpl = new Pluf_Template('idf/gadmin/users/createuser-email.txt');
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
$email = new Pluf_Mail(Pluf::f('from_email'), $user->email,
|
||||||
|
__('Your details to access your forge.'));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->sendMail();
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_last_name()
|
||||||
|
{
|
||||||
|
$last_name = trim($this->cleaned_data['last_name']);
|
||||||
|
if ($last_name == mb_strtoupper($last_name)) {
|
||||||
|
return mb_convert_case(mb_strtolower($last_name),
|
||||||
|
MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
return $last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_first_name()
|
||||||
|
{
|
||||||
|
$first_name = trim($this->cleaned_data['first_name']);
|
||||||
|
if ($first_name == mb_strtoupper($first_name)) {
|
||||||
|
return mb_convert_case(mb_strtolower($first_name),
|
||||||
|
MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
return $first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_email()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['email'] = mb_strtolower(trim($this->cleaned_data['email']));
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('email=%s', array($this->cleaned_data['email']));
|
||||||
|
if ($guser->getCount(array('filter' => $sql->gen())) > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The email "%s" is already used.'), $this->cleaned_data['email']));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_login()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['login'] = mb_strtolower(trim($this->cleaned_data['login']));
|
||||||
|
if (preg_match('/[^a-z0-9]/', $this->cleaned_data['login'])) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The login "%s" can only contain letters and digits.'), $this->cleaned_data['login']));
|
||||||
|
}
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('login=%s', $this->cleaned_data['login']);
|
||||||
|
if ($guser->getCount(array('filter' => $sql->gen())) > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The login "%s" is already used, please find another one.'), $this->cleaned_data['login']));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['login'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_public_key()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['public_key'] =
|
||||||
|
IDF_Form_UserAccount::checkPublicKey($this->cleaned_data['public_key']);
|
||||||
|
|
||||||
|
return $this->cleaned_data['public_key'];
|
||||||
|
}
|
||||||
|
}
|
321
indefero/src/IDF/Form/Admin/UserUpdate.php
Normal file
321
indefero/src/IDF/Form/Admin/UserUpdate.php
Normal file
@ -0,0 +1,321 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update user's details.
|
||||||
|
*/
|
||||||
|
class IDF_Form_Admin_UserUpdate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$user_data = IDF_UserData::factory($this->user);
|
||||||
|
|
||||||
|
$this->fields['first_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('First name'),
|
||||||
|
'initial' => $this->user->first_name,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['last_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Last name'),
|
||||||
|
'initial' => $this->user->last_name,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['email'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Email'),
|
||||||
|
'initial' => $this->user->email,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['language'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Language'),
|
||||||
|
'initial' => $this->user->language,
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'choices' =>
|
||||||
|
Pluf_L10n::getInstalledLanguages()
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['password'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'help_text' => Pluf_Template::markSafe(__('Leave blank if you do not want to change the password.').'<br />'.__('The password must be hard for other people to guess, but easy for the user to remember.')),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['password2'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Confirm password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['description'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => $user_data->description,
|
||||||
|
'widget_attrs' => array('rows' => 3,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['twitter'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Twitter username'),
|
||||||
|
'initial' => $user_data->twitter,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['public_email'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Public email address'),
|
||||||
|
'initial' => $user_data->public_email,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['website'] = new Pluf_Form_Field_Url(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Website URL'),
|
||||||
|
'initial' => $user_data->website,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['custom_avatar'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Upload custom avatar'),
|
||||||
|
'initial' => '',
|
||||||
|
'max_size' => Pluf::f('max_upload_size', 2097152),
|
||||||
|
'move_function_params' => array('upload_path' => Pluf::f('upload_path').'/avatars',
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => true,
|
||||||
|
'file_name' => 'user_'.$this->user->id.'_%s'),
|
||||||
|
'help_text' => __('An image file with a width and height not larger than 60 pixels (bigger images are scaled down).'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['remove_custom_avatar'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Remove custom avatar'),
|
||||||
|
'initial' => false,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
'widget_attrs' => array(),
|
||||||
|
'help_text' => __('Tick this to delete the custom avatar.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($extra['request']->user->administrator) {
|
||||||
|
$this->fields['staff'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Staff'),
|
||||||
|
'initial' => $this->user->staff,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
'help_text' => __('If you give staff rights to a user, you really need to trust him.'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$attrs = ($extra['request']->user->id == $this->user->id) ?
|
||||||
|
array('readonly' => 'readonly') : array();
|
||||||
|
$this->fields['active'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Active'),
|
||||||
|
'initial' => $this->user->active,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
'widget_attrs' => $attrs,
|
||||||
|
'help_text' => __('If the user is not getting the confirmation email or is abusing the system, you can directly enable or disable their account here.'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
unset($this->cleaned_data['password2']);
|
||||||
|
$update_pass = false;
|
||||||
|
if (strlen($this->cleaned_data['password']) == 0) {
|
||||||
|
unset($this->cleaned_data['password']);
|
||||||
|
} else {
|
||||||
|
$update_pass = true;
|
||||||
|
}
|
||||||
|
$this->user->setFromFormData($this->cleaned_data);
|
||||||
|
|
||||||
|
if ($commit) {
|
||||||
|
$this->user->update();
|
||||||
|
|
||||||
|
// FIXME: go the extra mile and check the input lengths for
|
||||||
|
// all fields here!
|
||||||
|
// FIXME: this is all doubled in UserAccount!
|
||||||
|
|
||||||
|
$user_data = IDF_UserData::factory($this->user);
|
||||||
|
|
||||||
|
// Add or remove avatar - we need to do this here because every
|
||||||
|
// single setter directly leads to a save in the database
|
||||||
|
if ($user_data->avatar != '' &&
|
||||||
|
($this->cleaned_data['remove_custom_avatar'] == 1 ||
|
||||||
|
$this->cleaned_data['custom_avatar'] != '')) {
|
||||||
|
$avatar_path = Pluf::f('upload_path').'/avatars/'.basename($user_data->avatar);
|
||||||
|
if (basename($avatar_path) != '' && is_file($avatar_path)) {
|
||||||
|
unlink($avatar_path);
|
||||||
|
}
|
||||||
|
$user_data->avatar = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->cleaned_data['custom_avatar'] != '') {
|
||||||
|
$user_data->avatar = $this->cleaned_data['custom_avatar'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_data->description = $this->cleaned_data['description'];
|
||||||
|
$user_data->twitter = $this->cleaned_data['twitter'];
|
||||||
|
$user_data->public_email = $this->cleaned_data['public_email'];
|
||||||
|
$user_data->website = $this->cleaned_data['website'];
|
||||||
|
|
||||||
|
if ($update_pass) {
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* Pluf_User::passwordUpdated
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_UserAccount
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal is sent when the user updated his
|
||||||
|
* password from his account page.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('user' => $user)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('user' => $this->user);
|
||||||
|
Pluf_Signal::send('Pluf_User::passwordUpdated',
|
||||||
|
'IDF_Form_Admin_UserUpdate', $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_last_name()
|
||||||
|
{
|
||||||
|
$last_name = trim($this->cleaned_data['last_name']);
|
||||||
|
if ($last_name == mb_strtoupper($last_name)) {
|
||||||
|
return mb_convert_case(mb_strtolower($last_name),
|
||||||
|
MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
return $last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_first_name()
|
||||||
|
{
|
||||||
|
$first_name = trim($this->cleaned_data['first_name']);
|
||||||
|
if ($first_name == '---') {
|
||||||
|
throw new Pluf_Form_Invalid(__('--- is not a valid first name.'));
|
||||||
|
}
|
||||||
|
if ($first_name == mb_strtoupper($first_name)) {
|
||||||
|
$first_name = mb_convert_case(mb_strtolower($first_name),
|
||||||
|
MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
return $first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_email()
|
||||||
|
{
|
||||||
|
$email = mb_strtolower(trim($this->cleaned_data['email']));
|
||||||
|
$sql = new Pluf_SQL('email=%s AND id!=%s',
|
||||||
|
array($email, $this->user->id));
|
||||||
|
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('A user with this email already exists, please provide another email address.'));
|
||||||
|
}
|
||||||
|
return $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_custom_avatar()
|
||||||
|
{
|
||||||
|
// Just png, jpeg/jpg or gif
|
||||||
|
if (!preg_match('/\.(png|jpg|jpeg|gif)$/i', $this->cleaned_data['custom_avatar']) &&
|
||||||
|
$this->cleaned_data['custom_avatar'] != '') {
|
||||||
|
@unlink(Pluf::f('upload_path').'/avatars/'.$this->cleaned_data['custom_avatar']);
|
||||||
|
throw new Pluf_Form_Invalid(__('For security reason, you cannot upload a file with this extension.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['custom_avatar'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the two passwords are the same.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if (!isset($this->errors['password'])
|
||||||
|
&& !isset($this->errors['password2'])) {
|
||||||
|
$password1 = $this->cleaned_data['password'];
|
||||||
|
$password2 = $this->cleaned_data['password2'];
|
||||||
|
if ($password1 != $password2) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The passwords do not match. Please give them again.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
}
|
51
indefero/src/IDF/Form/Field/EmailList.php
Normal file
51
indefero/src/IDF/Form/Field/EmailList.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to Pluf_Form_Field_Email, this form field validates one or more
|
||||||
|
* email addresses separated by a comma
|
||||||
|
*/
|
||||||
|
class IDF_Form_Field_EmailList extends Pluf_Form_Field
|
||||||
|
{
|
||||||
|
public $widget = 'Pluf_Form_Widget_TextInput';
|
||||||
|
|
||||||
|
public function clean($value)
|
||||||
|
{
|
||||||
|
parent::clean($value);
|
||||||
|
if (in_array($value, $this->empty_values)) {
|
||||||
|
$value = '';
|
||||||
|
}
|
||||||
|
if ($value == '') {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
$emails = preg_split('/\s*,\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
foreach ($emails as $email) {
|
||||||
|
if (!Pluf_Utils::isValidEmail($email)) {
|
||||||
|
throw new Pluf_Form_Invalid(__(
|
||||||
|
'Please enter one or more valid email addresses.'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode(',', $emails);
|
||||||
|
}
|
||||||
|
}
|
473
indefero/src/IDF/Form/IssueCreate.php
Normal file
473
indefero/src/IDF/Form/IssueCreate.php
Normal file
@ -0,0 +1,473 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new issue.
|
||||||
|
*
|
||||||
|
* This create the issue entry and the first comment corresponding to
|
||||||
|
* the description and the attached files.
|
||||||
|
*
|
||||||
|
* It is possible to tag the issue following some rules. For example
|
||||||
|
* you cannot put several "status" or "priority" tags.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_IssueCreate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $show_full = false;
|
||||||
|
public $relation_types = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||||
|
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||||
|
$this->show_full = true;
|
||||||
|
}
|
||||||
|
$this->relation_types = $this->project->getRelationsFromConfig();
|
||||||
|
|
||||||
|
$contentTemplate = $this->project->getConf()->getVal(
|
||||||
|
'labels_issue_template', IDF_Form_IssueTrackingConf::init_template
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Summary'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => $contentTemplate,
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 13,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$upload_path = Pluf::f('upload_issue_path', false);
|
||||||
|
if (false === $upload_path) {
|
||||||
|
throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
|
||||||
|
}
|
||||||
|
$md5 = md5(rand().microtime().Pluf_Utils::getRandomString());
|
||||||
|
// We add .dummy to try to mitigate security issues in the
|
||||||
|
// case of someone allowing the upload path to be accessible
|
||||||
|
// to everybody.
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
$filename = substr($md5, 0, 2).'/'.substr($md5, 2, 2).'/'.substr($md5, 4).'/%s.dummy';
|
||||||
|
$this->fields['attachment'.$i] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Attach a file'),
|
||||||
|
'move_function_params' =>
|
||||||
|
array('upload_path' => $upload_path,
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'file_name' => $filename,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->show_full) {
|
||||||
|
$this->fields['status'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Status'),
|
||||||
|
'initial' => 'New',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 20,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['owner'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Owner'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 20,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['relation_type0'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('This issue'),
|
||||||
|
'initial' => current($this->relation_types),
|
||||||
|
'widget_attrs' => array('size' => 15),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['relation_issue0'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => null,
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('size' => 10),
|
||||||
|
));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get predefined tags for issues from current project
|
||||||
|
*
|
||||||
|
* first Type:<...> and Priority:<...> will be used
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$predefined = preg_split("/[\r\n]+/", $extra['project']->getConf()->getVal(
|
||||||
|
'labels_issue_predefined'
|
||||||
|
));
|
||||||
|
$predefined_type = 'Type:Defect';
|
||||||
|
foreach ($predefined as $tag) {
|
||||||
|
if (strpos($tag, 'Type:') === 0) {
|
||||||
|
$predefined_type = explode('=', $tag, 2);
|
||||||
|
$predefined_type = trim($predefined_type[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$predefined_priority = 'Priority:Medium';
|
||||||
|
foreach ($predefined as $tag) {
|
||||||
|
if (strpos($tag, 'Priority:') === 0) {
|
||||||
|
$predefined_priority = explode('=', $tag, 2);
|
||||||
|
$predefined_priority = trim($predefined_priority[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$initial = '';
|
||||||
|
switch ($i) {
|
||||||
|
case 1:
|
||||||
|
$initial = $predefined_type;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$initial = $predefined_priority;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
// We need to check that no label with the 'Status' class is
|
||||||
|
// given.
|
||||||
|
if (!$this->show_full) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($this->project);
|
||||||
|
$onemax = array();
|
||||||
|
foreach (explode(',', $conf->getVal('labels_issue_one_max', IDF_Form_IssueTrackingConf::init_one_max)) as $class) {
|
||||||
|
if (trim($class) != '') {
|
||||||
|
$onemax[] = mb_strtolower(trim($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$this->cleaned_data['label'.$i] = trim($this->cleaned_data['label'.$i]);
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||||
|
trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'other';
|
||||||
|
$name = $this->cleaned_data['label'.$i];
|
||||||
|
}
|
||||||
|
if ($class == 'status') {
|
||||||
|
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||||
|
$this->errors['label'.$i][] = __('You cannot add a label with the "Status" prefix to an issue.');
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||||
|
}
|
||||||
|
if (!isset($count[$class])) $count[$class] = 1;
|
||||||
|
else $count[$class] += 1;
|
||||||
|
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||||
|
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||||
|
$this->errors['label'.$i][] = sprintf(__('You cannot provide more than one label from the %s class to an issue.'), $class);
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_content()
|
||||||
|
{
|
||||||
|
$content = trim($this->cleaned_data['content']);
|
||||||
|
if (strlen($content) == 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You need to provide a description of the issue.'));
|
||||||
|
}
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_status()
|
||||||
|
{
|
||||||
|
// Check that the status is in the list of official status
|
||||||
|
$tags = $this->project->getTagsFromConfig('labels_issue_open',
|
||||||
|
IDF_Form_IssueTrackingConf::init_open,
|
||||||
|
'Status');
|
||||||
|
$tags = array_merge($this->project->getTagsFromConfig('labels_issue_closed',
|
||||||
|
IDF_Form_IssueTrackingConf::init_closed,
|
||||||
|
'Status')
|
||||||
|
, $tags);
|
||||||
|
$found = false;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if ($tag->name == trim($this->cleaned_data['status'])) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid status.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// this method is not called from Pluf_Form directly, but shared for
|
||||||
|
// among all similar fields
|
||||||
|
function clean_relation_type($value)
|
||||||
|
{
|
||||||
|
$relation_type = trim($value);
|
||||||
|
if (empty($relation_type))
|
||||||
|
return '';
|
||||||
|
|
||||||
|
$found = false;
|
||||||
|
foreach ($this->relation_types as $type) {
|
||||||
|
if ($type == $relation_type) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid relation type.'));
|
||||||
|
}
|
||||||
|
return $relation_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_relation_type0()
|
||||||
|
{
|
||||||
|
return $this->clean_relation_type($this->cleaned_data['relation_type0']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this method is not called from Pluf_Form directly, but shared for
|
||||||
|
// among all similar fields
|
||||||
|
function clean_relation_issue($value)
|
||||||
|
{
|
||||||
|
$issues = trim($value);
|
||||||
|
if (empty($issues))
|
||||||
|
return '';
|
||||||
|
|
||||||
|
$issue_ids = preg_split('/\s*,\s*/', $issues, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
foreach ($issue_ids as $issue_id) {
|
||||||
|
if (!ctype_digit($issue_id) || (int)$issue_id < 1) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(
|
||||||
|
__('The value "%s" is not a valid issue id.'), $issue_id
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$issue = new IDF_Issue($issue_id);
|
||||||
|
if ($issue->id != $issue_id || $issue->project != $this->project->id) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(
|
||||||
|
__('The issue "%s" does not exist.'), $issue_id
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(', ', $issue_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_relation_issue0()
|
||||||
|
{
|
||||||
|
return $this->clean_relation_issue($this->cleaned_data['relation_issue0']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean the attachments post failure.
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
$upload_path = Pluf::f('upload_issue_path', false);
|
||||||
|
if ($upload_path == false) return;
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
if (!empty($this->cleaned_data['attachment'.$i]) and
|
||||||
|
file_exists($upload_path.'/'.$this->cleaned_data['attachment'.$i])) {
|
||||||
|
@unlink($upload_path.'/'.$this->cleaned_data['attachment'.$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// Add a tag for each label
|
||||||
|
$tags = array();
|
||||||
|
if ($this->show_full) {
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tags[] = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tags[] = IDF_Tag::add('Medium', $this->project, 'Priority');
|
||||||
|
$tags[] = IDF_Tag::add('Defect', $this->project, 'Type');
|
||||||
|
}
|
||||||
|
// Create the issue
|
||||||
|
$issue = new IDF_Issue();
|
||||||
|
$issue->project = $this->project;
|
||||||
|
$issue->submitter = $this->user;
|
||||||
|
if ($this->show_full) {
|
||||||
|
$issue->status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
|
||||||
|
$issue->owner = self::findUser($this->cleaned_data['owner']);
|
||||||
|
} else {
|
||||||
|
$_t = $this->project->getTagIdsByStatus('open');
|
||||||
|
$issue->status = new IDF_Tag($_t[0]); // first one is the default
|
||||||
|
$issue->owner = null;
|
||||||
|
}
|
||||||
|
$issue->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$issue->create();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$issue->setAssoc($tag);
|
||||||
|
}
|
||||||
|
// add relations (if any)
|
||||||
|
if (!empty($this->cleaned_data['relation_type0'])) {
|
||||||
|
$verb = $this->cleaned_data['relation_type0'];
|
||||||
|
$other_verb = $this->relation_types[$verb];
|
||||||
|
$related_issues = preg_split('/\s*,\s*/', $this->cleaned_data['relation_issue0'], -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
|
foreach ($related_issues as $related_issue_id) {
|
||||||
|
$related_issue = new IDF_Issue($related_issue_id);
|
||||||
|
$rel = new IDF_IssueRelation();
|
||||||
|
$rel->issue = $issue;
|
||||||
|
$rel->verb = $verb;
|
||||||
|
$rel->other_issue = $related_issue;
|
||||||
|
$rel->submitter = $this->user;
|
||||||
|
$rel->create();
|
||||||
|
|
||||||
|
$other_rel = new IDF_IssueRelation();
|
||||||
|
$other_rel->issue = $related_issue;
|
||||||
|
$other_rel->verb = $other_verb;
|
||||||
|
$other_rel->other_issue = $issue;
|
||||||
|
$other_rel->submitter = $this->user;
|
||||||
|
$other_rel->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the first comment
|
||||||
|
$comment = new IDF_IssueComment();
|
||||||
|
$comment->issue = $issue;
|
||||||
|
$comment->content = $this->cleaned_data['content'];
|
||||||
|
$comment->submitter = $this->user;
|
||||||
|
$comment->create();
|
||||||
|
// If we have a file, create the IDF_IssueFile and attach
|
||||||
|
// it to the comment.
|
||||||
|
$created_files = array();
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
if ($this->cleaned_data['attachment'.$i]) {
|
||||||
|
$file = new IDF_IssueFile();
|
||||||
|
$file->attachment = $this->cleaned_data['attachment'.$i];
|
||||||
|
$file->submitter = $this->user;
|
||||||
|
$file->comment = $comment;
|
||||||
|
$file->create();
|
||||||
|
$created_files[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Issue::create
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_IssueCreate
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform a set of tasks
|
||||||
|
* just after the creation of an issue. The comment contains
|
||||||
|
* the description of the issue.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('issue' => $issue,
|
||||||
|
* 'comment' => $comment,
|
||||||
|
* 'files' => $attached_files);
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('issue' => $issue,
|
||||||
|
'comment' => $comment,
|
||||||
|
'files' => $created_files);
|
||||||
|
Pluf_Signal::send('IDF_Issue::create', 'IDF_Form_IssueCreate',
|
||||||
|
$params);
|
||||||
|
return $issue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on the given string, try to find the matching user.
|
||||||
|
*
|
||||||
|
* Search order is: email, login, last_name.
|
||||||
|
*
|
||||||
|
* If no user found, simply returns null.
|
||||||
|
*
|
||||||
|
* @param string User
|
||||||
|
* @return Pluf_User or null
|
||||||
|
*/
|
||||||
|
public static function findUser($string)
|
||||||
|
{
|
||||||
|
$string = trim($string);
|
||||||
|
if (strlen($string) == 0) return null;
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
foreach (array('email', 'login', 'last_name') as $what) {
|
||||||
|
$sql = new Pluf_SQL($what.'=%s', $string);
|
||||||
|
$users = $guser->getList(array('filter' => $sql->gen()));
|
||||||
|
if ($users->count() > 0) {
|
||||||
|
return $users[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
150
indefero/src/IDF/Form/IssueTrackingConf.php
Normal file
150
indefero/src/IDF/Form/IssueTrackingConf.php
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the labels etc.
|
||||||
|
*/
|
||||||
|
class IDF_Form_IssueTrackingConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Defined as constants to easily access the value in the
|
||||||
|
* IssueUpdate/Create form in the case nothing is in the db yet.
|
||||||
|
*/
|
||||||
|
const init_template = 'Steps to reproduce the problem:
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
|
||||||
|
Expected result:
|
||||||
|
|
||||||
|
Actual result:
|
||||||
|
';
|
||||||
|
const init_open = 'New = Issue has not had initial review yet
|
||||||
|
Accepted = Problem reproduced / Need acknowledged
|
||||||
|
Started = Work on this issue has begun';
|
||||||
|
const init_closed = 'Fixed = Developer made requested changes, QA should verify
|
||||||
|
Verified = QA has verified that the fix worked
|
||||||
|
Invalid = This was not a valid issue report
|
||||||
|
Duplicate = This report duplicates an existing issue
|
||||||
|
WontFix = We decided to not take action on this issue';
|
||||||
|
const init_predefined = 'Type:Defect = Report of a software defect
|
||||||
|
Type:Enhancement = Request for enhancement
|
||||||
|
Type:Task = Work item that doesn\'t change the code or docs
|
||||||
|
Type:Patch = Source code patch for review
|
||||||
|
Type:Other = Some other kind of issue
|
||||||
|
Priority:Critical = Must resolve in the specified milestone
|
||||||
|
Priority:High = Strongly want to resolve in the specified milestone
|
||||||
|
Priority:Medium = Normal priority
|
||||||
|
Priority:Low = Might slip to later milestone
|
||||||
|
OpSys:All = Affects all operating systems
|
||||||
|
OpSys:Windows = Affects Windows users
|
||||||
|
OpSys:Linux = Affects Linux users
|
||||||
|
OpSys:OSX = Affects Mac OS X users
|
||||||
|
Milestone:Release1.0 = All essential functionality working
|
||||||
|
Component:UI = Issue relates to program UI
|
||||||
|
Component:Logic = Issue relates to application logic
|
||||||
|
Component:Persistence = Issue relates to data storage components
|
||||||
|
Component:Scripts = Utility and installation scripts
|
||||||
|
Component:Docs = Issue relates to end-user documentation
|
||||||
|
Security = Security risk to users
|
||||||
|
Performance = Performance issue
|
||||||
|
Usability = Affects program usability
|
||||||
|
Maintainability = Hinders future changes';
|
||||||
|
const init_one_max = 'Type, Priority, Milestone';
|
||||||
|
// ATTENTION: if you change something here, change the values below as well!
|
||||||
|
const init_relations = 'is related to
|
||||||
|
blocks, is blocked by
|
||||||
|
duplicates, is duplicated by';
|
||||||
|
|
||||||
|
// These are actually all noop's, but we have no other chance to
|
||||||
|
// tell IDF's translation mechanism to mark the strings as translatable
|
||||||
|
// FIXME: IDF should get a internal translation system for strings like
|
||||||
|
// that, that can also be easily expanded by users
|
||||||
|
private function noop()
|
||||||
|
{
|
||||||
|
__('is related to');
|
||||||
|
__('blocks');
|
||||||
|
__('is blocked by');
|
||||||
|
__('duplicates');
|
||||||
|
__('is duplicated by');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['labels_issue_template'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Define an issue template to hint the reporter to provide certain information'),
|
||||||
|
'initial' => self::init_template,
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['labels_issue_open'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Open issue status values'),
|
||||||
|
'initial' => self::init_open,
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array('rows' => 5,
|
||||||
|
'cols' => 75),
|
||||||
|
));
|
||||||
|
$this->fields['labels_issue_closed'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Closed issue status values'),
|
||||||
|
'initial' => self::init_closed,
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['labels_issue_predefined'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Predefined issue labels'),
|
||||||
|
'initial' => self::init_predefined,
|
||||||
|
'help_text' => __('The first "Type:" and "Priority:" entries found in this list are automatically chosen as defaults for new issues.'),
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['labels_issue_one_max'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Each issue may have at most one label with each of these classes.'),
|
||||||
|
'initial' => self::init_one_max,
|
||||||
|
'widget_attrs' => array('size' => 60),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['issue_relations'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Issue relations'),
|
||||||
|
'initial' => self::init_relations,
|
||||||
|
'help_text' => __('You can define bidirectional relations like "is related to" or "blocks, is blocked by". For standard relations pre-configured translations exist, new relations should however be defined in a language that is understood by all project members.'),
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
488
indefero/src/IDF/Form/IssueUpdate.php
Normal file
488
indefero/src/IDF/Form/IssueUpdate.php
Normal file
@ -0,0 +1,488 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an issue.
|
||||||
|
*
|
||||||
|
* We extend IDF_Form_IssueCreate to reuse the validation logic.
|
||||||
|
*/
|
||||||
|
class IDF_Form_IssueUpdate extends IDF_Form_IssueCreate
|
||||||
|
{
|
||||||
|
public $issue = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
$this->issue = $extra['issue'];
|
||||||
|
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||||
|
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||||
|
$this->show_full = true;
|
||||||
|
}
|
||||||
|
$this->relation_types = $this->project->getRelationsFromConfig();
|
||||||
|
if ($this->show_full) {
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Summary'),
|
||||||
|
'initial' => $this->issue->summary,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Comment'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 9,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$upload_path = Pluf::f('upload_issue_path', false);
|
||||||
|
if (false === $upload_path) {
|
||||||
|
throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
|
||||||
|
}
|
||||||
|
$md5 = md5(rand().microtime().Pluf_Utils::getRandomString());
|
||||||
|
// We add .dummy to try to mitigate security issues in the
|
||||||
|
// case of someone allowing the upload path to be accessible
|
||||||
|
// to everybody.
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
$filename = substr($md5, 0, 2).'/'.substr($md5, 2, 2).'/'.substr($md5, 4).'/%s.dummy';
|
||||||
|
$this->fields['attachment'.$i] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Attach a file'),
|
||||||
|
'move_function_params' =>
|
||||||
|
array('upload_path' => $upload_path,
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'file_name' => $filename,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->show_full) {
|
||||||
|
$this->fields['status'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Status'),
|
||||||
|
'initial' => $this->issue->get_status()->name,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 20,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$initial = ($this->issue->get_owner() == null) ? '' : $this->issue->get_owner()->login;
|
||||||
|
$this->fields['owner'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Owner'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 20,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$idx = 0;
|
||||||
|
// note: clean_relation_type0 and clean_relation_issue0 already
|
||||||
|
// exist in the base class
|
||||||
|
$this->fields['relation_type'.$idx] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('This issue'),
|
||||||
|
'initial' => current($this->relation_types),
|
||||||
|
'widget_attrs' => array('size' => 15),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['relation_issue'.$idx] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => null,
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('size' => 10),
|
||||||
|
));
|
||||||
|
|
||||||
|
++$idx;
|
||||||
|
$relatedIssues = $this->issue->getGroupedRelatedIssues(array(), true);
|
||||||
|
foreach ($relatedIssues as $verb => $ids) {
|
||||||
|
$this->fields['relation_type'.$idx] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('This issue'),
|
||||||
|
'initial' => $verb,
|
||||||
|
'widget_attrs' => array('size' => 15),
|
||||||
|
));
|
||||||
|
$m = 'clean_relation_type'.$idx;
|
||||||
|
$this->$m = create_function('$form', '
|
||||||
|
return $form->clean_relation_type($form->cleaned_data["relation_type'.$idx.'"]);
|
||||||
|
');
|
||||||
|
|
||||||
|
$this->fields['relation_issue'.$idx] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => null,
|
||||||
|
'initial' => implode(', ', $ids),
|
||||||
|
'widget_attrs' => array('size' => 10),
|
||||||
|
));
|
||||||
|
$m = 'clean_relation_issue'.$idx;
|
||||||
|
$this->$m = create_function('$form', '
|
||||||
|
return $form->clean_relation_issue($form->cleaned_data["relation_issue'.$idx.'"]);
|
||||||
|
');
|
||||||
|
|
||||||
|
++$idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tags = $this->issue->get_tags_list();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$initial = '';
|
||||||
|
if (isset($tags[$i-1])) {
|
||||||
|
if ($tags[$i-1]->class != 'Other') {
|
||||||
|
$initial = (string) $tags[$i-1];
|
||||||
|
} else {
|
||||||
|
$initial = $tags[$i-1]->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean the attachments post failure.
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
$upload_path = Pluf::f('upload_issue_path', false);
|
||||||
|
if ($upload_path == false) return;
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
if (!empty($this->cleaned_data['attachment'.$i]) and
|
||||||
|
file_exists($upload_path.'/'.$this->cleaned_data['attachment'.$i])) {
|
||||||
|
@unlink($upload_path.'/'.$this->cleaned_data['attachment'.$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_content()
|
||||||
|
{
|
||||||
|
$content = trim($this->cleaned_data['content']);
|
||||||
|
if (!$this->show_full and strlen($content) == 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You need to provide a description of the issue.'));
|
||||||
|
}
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We check that something is really changed.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
$this->cleaned_data = parent::clean();
|
||||||
|
|
||||||
|
// normalize the user's input by removing dublettes and by combining
|
||||||
|
// ids from identical verbs in different input fields into one array
|
||||||
|
$normRelatedIssues = array();
|
||||||
|
for ($idx = 0; isset($this->cleaned_data['relation_type'.$idx]); ++$idx) {
|
||||||
|
$verb = $this->cleaned_data['relation_type'.$idx];
|
||||||
|
if (empty($verb))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$ids = preg_split('/\s*,\s*/', $this->cleaned_data['relation_issue'.$idx],
|
||||||
|
-1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
if (count($ids) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!array_key_exists($verb, $normRelatedIssues))
|
||||||
|
$normRelatedIssues[$verb] = array();
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
if (!in_array($id, $normRelatedIssues[$verb]))
|
||||||
|
$normRelatedIssues[$verb][] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now look at any added / removed ids
|
||||||
|
$added = $removed = array();
|
||||||
|
$relatedIssues = $this->issue->getGroupedRelatedIssues(array(), true);
|
||||||
|
$added = array_diff_key($normRelatedIssues, $relatedIssues);
|
||||||
|
$removed = array_diff_key($relatedIssues, $normRelatedIssues);
|
||||||
|
|
||||||
|
$keysToLookAt = array_keys(
|
||||||
|
array_intersect_key($relatedIssues, $normRelatedIssues)
|
||||||
|
);
|
||||||
|
foreach ($keysToLookAt as $key) {
|
||||||
|
$a = array_diff($normRelatedIssues[$key], $relatedIssues[$key]);
|
||||||
|
if (count($a) > 0)
|
||||||
|
$added[$key] = $a;
|
||||||
|
$r = array_diff($relatedIssues[$key], $normRelatedIssues[$key]);
|
||||||
|
if (count($r) > 0)
|
||||||
|
$removed[$key] = $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cache the added / removed data, so we do not have to
|
||||||
|
// calculate that again
|
||||||
|
$this->cleaned_data['_added_issue_relations'] = $added;
|
||||||
|
$this->cleaned_data['_removed_issue_relations'] = $removed;
|
||||||
|
|
||||||
|
// As soon as we know that at least one change was done, we
|
||||||
|
// return the cleaned data and do not go further.
|
||||||
|
if (strlen(trim($this->cleaned_data['content']))) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
if ($this->show_full) {
|
||||||
|
$status = $this->issue->get_status();
|
||||||
|
if (trim($this->cleaned_data['status']) != $status->name) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
if (trim($this->issue->summary) != trim($this->cleaned_data['summary'])) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
$owner = self::findUser($this->cleaned_data['owner']);
|
||||||
|
if ((is_null($owner) and !is_null($this->issue->get_owner()))
|
||||||
|
or (!is_null($owner) and is_null($this->issue->get_owner()))
|
||||||
|
or ((!is_null($owner) and !is_null($this->issue->get_owner())) and $owner->id != $this->issue->get_owner()->id)) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
$tags = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tags[] = array($class, $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$oldtags = $this->issue->get_tags_list();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$found = false;
|
||||||
|
foreach ($oldtags as $otag) {
|
||||||
|
if ($otag->class == $tag[0] and $otag->name == $tag[1]) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
// new tag not found in the old tags
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($oldtags as $otag) {
|
||||||
|
$found = false;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if ($otag->class == $tag[0] and $otag->name == $tag[1]) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
// old tag not found in the new tags
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($this->cleaned_data['_added_issue_relations']) != 0 ||
|
||||||
|
count($this->cleaned_data['_removed_issue_relations']) != 0) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no changes!
|
||||||
|
throw new Pluf_Form_Invalid(__('No changes were entered.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
if ($this->show_full) {
|
||||||
|
// Add a tag for each label
|
||||||
|
$tags = array();
|
||||||
|
$tagids = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
$tags[] = $tag;
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Compare between the old and the new data
|
||||||
|
$changes = array();
|
||||||
|
$oldtags = $this->issue->get_tags_list();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if (!Pluf_Model_InArray($tag, $oldtags)) {
|
||||||
|
if (!isset($changes['lb'])) $changes['lb'] = array();
|
||||||
|
if (!isset($changes['lb']['add'])) $changes['lb']['add'] = array();
|
||||||
|
if ($tag->class != 'Other') {
|
||||||
|
$changes['lb']['add'][] = (string) $tag; //new tag
|
||||||
|
} else {
|
||||||
|
$changes['lb']['add'][] = (string) $tag->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($oldtags as $tag) {
|
||||||
|
if (!Pluf_Model_InArray($tag, $tags)) {
|
||||||
|
if (!isset($changes['lb'])) $changes['lb'] = array();
|
||||||
|
if (!isset($changes['lb']['rem'])) $changes['lb']['rem'] = array();
|
||||||
|
if ($tag->class != 'Other') {
|
||||||
|
$changes['lb']['rem'][] = (string) $tag; //new tag
|
||||||
|
} else {
|
||||||
|
$changes['lb']['rem'][] = (string) $tag->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Status, summary and owner
|
||||||
|
$status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
|
||||||
|
if ($status->id != $this->issue->status) {
|
||||||
|
$changes['st'] = $status->name;
|
||||||
|
}
|
||||||
|
if (trim($this->issue->summary) != trim($this->cleaned_data['summary'])) {
|
||||||
|
$changes['su'] = trim($this->cleaned_data['summary']);
|
||||||
|
}
|
||||||
|
$owner = self::findUser($this->cleaned_data['owner']);
|
||||||
|
if ((is_null($owner) and !is_null($this->issue->get_owner()))
|
||||||
|
or (!is_null($owner) and is_null($this->issue->get_owner()))
|
||||||
|
or ((!is_null($owner) and !is_null($this->issue->get_owner())) and $owner->id != $this->issue->get_owner()->id)) {
|
||||||
|
$changes['ow'] = (is_null($owner)) ? '---' : $owner->login;
|
||||||
|
}
|
||||||
|
// Issue relations - additions
|
||||||
|
foreach ($this->cleaned_data['_added_issue_relations'] as $verb => $ids) {
|
||||||
|
$other_verb = $this->relation_types[$verb];
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$related_issue = new IDF_Issue($id);
|
||||||
|
$rel = new IDF_IssueRelation();
|
||||||
|
$rel->issue = $this->issue;
|
||||||
|
$rel->verb = $verb;
|
||||||
|
$rel->other_issue = $related_issue;
|
||||||
|
$rel->submitter = $this->user;
|
||||||
|
$rel->create();
|
||||||
|
|
||||||
|
$other_rel = new IDF_IssueRelation();
|
||||||
|
$other_rel->issue = $related_issue;
|
||||||
|
$other_rel->verb = $other_verb;
|
||||||
|
$other_rel->other_issue = $this->issue;
|
||||||
|
$other_rel->submitter = $this->user;
|
||||||
|
$other_rel->create();
|
||||||
|
}
|
||||||
|
if (!isset($changes['rel'])) $changes['rel'] = array();
|
||||||
|
if (!isset($changes['rel']['add'])) $changes['rel']['add'] = array();
|
||||||
|
$changes['rel']['add'][] = $verb.' '.implode(', ', $ids);
|
||||||
|
}
|
||||||
|
// Issue relations - removals
|
||||||
|
foreach ($this->cleaned_data['_removed_issue_relations'] as $verb => $ids) {
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$db = &Pluf::db();
|
||||||
|
$table = Pluf::factory('IDF_IssueRelation')->getSqlTable();
|
||||||
|
$sql = new Pluf_SQL('verb=%s AND (
|
||||||
|
(issue=%s AND other_issue=%s) OR
|
||||||
|
(other_issue=%s AND issue=%s))',
|
||||||
|
array($verb,
|
||||||
|
$this->issue->id, $id,
|
||||||
|
$this->issue->id, $id));
|
||||||
|
$db->execute('DELETE FROM '.$table.' WHERE '.$sql->gen());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($changes['rel'])) $changes['rel'] = array();
|
||||||
|
if (!isset($changes['rel']['rem'])) $changes['rel']['rem'] = array();
|
||||||
|
$changes['rel']['rem'][] = $verb.' '.implode(', ', $ids);
|
||||||
|
}
|
||||||
|
// Update the issue
|
||||||
|
$this->issue->batchAssoc('IDF_Tag', $tagids);
|
||||||
|
$this->issue->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$this->issue->status = $status;
|
||||||
|
$this->issue->owner = $owner;
|
||||||
|
}
|
||||||
|
// Create the comment
|
||||||
|
$comment = new IDF_IssueComment();
|
||||||
|
$comment->issue = $this->issue;
|
||||||
|
$comment->content = $this->cleaned_data['content'];
|
||||||
|
$comment->submitter = $this->user;
|
||||||
|
if (!$this->show_full) $changes = array();
|
||||||
|
$comment->changes = $changes;
|
||||||
|
$comment->create();
|
||||||
|
$this->issue->update();
|
||||||
|
if ($this->issue->owner != $this->user->id and
|
||||||
|
$this->issue->submitter != $this->user->id) {
|
||||||
|
$this->issue->setAssoc($this->user); // interested user.
|
||||||
|
}
|
||||||
|
$attached_files = array();
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
if ($this->cleaned_data['attachment'.$i]) {
|
||||||
|
$file = new IDF_IssueFile();
|
||||||
|
$file->attachment = $this->cleaned_data['attachment'.$i];
|
||||||
|
$file->submitter = $this->user;
|
||||||
|
$file->comment = $comment;
|
||||||
|
$file->create();
|
||||||
|
$attached_files[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Issue::update
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_IssueUpdate
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform a set of tasks
|
||||||
|
* just after the update of an issue.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('issue' => $issue,
|
||||||
|
* 'comment' => $comment,
|
||||||
|
* 'files' => $attached_files);
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('issue' => $this->issue,
|
||||||
|
'comment' => $comment,
|
||||||
|
'files' => $attached_files);
|
||||||
|
Pluf_Signal::send('IDF_Issue::update', 'IDF_Form_IssueUpdate',
|
||||||
|
$params);
|
||||||
|
|
||||||
|
return $this->issue;
|
||||||
|
}
|
||||||
|
}
|
138
indefero/src/IDF/Form/MembersConf.php
Normal file
138
indefero/src/IDF/Form/MembersConf.php
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the members.
|
||||||
|
*
|
||||||
|
* To simplify the management. Instead of being obliged to go through
|
||||||
|
* a list of people and then select the rights member/owner, I am
|
||||||
|
* using the same approach as googlecode, that is, asking for the
|
||||||
|
* login. This makes the interface simpler and simplicity is king.
|
||||||
|
*
|
||||||
|
* In background, the row permission framework is used to give the
|
||||||
|
* member/owner permission to the given project to the users.
|
||||||
|
*/
|
||||||
|
class IDF_Form_MembersConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
|
||||||
|
$this->fields['owners'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project owners'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array('rows' => 5,
|
||||||
|
'cols' => 40),
|
||||||
|
));
|
||||||
|
$this->fields['members'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project members'),
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
self::updateMemberships($this->project, $this->cleaned_data);
|
||||||
|
$this->project->membershipsUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_owners()
|
||||||
|
{
|
||||||
|
return self::checkBadLogins($this->cleaned_data['owners']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_members()
|
||||||
|
{
|
||||||
|
return self::checkBadLogins($this->cleaned_data['members']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* From the input, find the bad logins.
|
||||||
|
*
|
||||||
|
* @throws Pluf_Form_Invalid exception when bad logins are found
|
||||||
|
* @param string Comma, new line delimited list of logins
|
||||||
|
* @return string Comma, new line delimited list of logins
|
||||||
|
*/
|
||||||
|
public static function checkBadLogins($logins)
|
||||||
|
{
|
||||||
|
$bad = array();
|
||||||
|
foreach (preg_split("/\015\012|\015|\012|\,/", $logins, -1, PREG_SPLIT_NO_EMPTY) as $login) {
|
||||||
|
$sql = new Pluf_SQL('login=%s', array(trim($login)));
|
||||||
|
try {
|
||||||
|
$user = Pluf::factory('Pluf_User')->getOne(array('filter'=>$sql->gen()));
|
||||||
|
if (null == $user) {
|
||||||
|
$bad[] = $login;
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$bad[] = $login;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$n = count($bad);
|
||||||
|
if ($n) {
|
||||||
|
$badlogins = Pluf_esc(implode(', ', $bad));
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(_n('The following login is invalid: %s.', 'The following logins are invalid: %s.', $n), $badlogins));
|
||||||
|
}
|
||||||
|
return $logins;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The update of the memberships is done in different places. This
|
||||||
|
* avoids duplicating code.
|
||||||
|
*
|
||||||
|
* @param IDF_Project The project
|
||||||
|
* @param array The new memberships data in 'owners' and 'members' keys
|
||||||
|
*/
|
||||||
|
public static function updateMemberships($project, $cleaned_data)
|
||||||
|
{
|
||||||
|
// remove all the permissions
|
||||||
|
$cm = $project->getMembershipData();
|
||||||
|
$def = array('owners' => Pluf_Permission::getFromString('IDF.project-owner'),
|
||||||
|
'members' => Pluf_Permission::getFromString('IDF.project-member'));
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
foreach ($def as $key=>$perm) {
|
||||||
|
foreach ($cm[$key] as $user) {
|
||||||
|
Pluf_RowPermission::remove($user, $project, $perm);
|
||||||
|
}
|
||||||
|
foreach (preg_split("/\015\012|\015|\012|\,/", $cleaned_data[$key], -1, PREG_SPLIT_NO_EMPTY) as $login) {
|
||||||
|
$sql = new Pluf_SQL('login=%s', array(trim($login)));
|
||||||
|
$users = $guser->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() == 1) {
|
||||||
|
Pluf_RowPermission::add($users[0], $project, $perm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
112
indefero/src/IDF/Form/Password.php
Normal file
112
indefero/src/IDF/Form/Password.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask a password recovery.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_Password extends Pluf_Form
|
||||||
|
{
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['account'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your login or email'),
|
||||||
|
'help_text' => __('Provide either your login or your email to recover your password.'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that a user with this login or email exists.
|
||||||
|
*/
|
||||||
|
public function clean_account()
|
||||||
|
{
|
||||||
|
$account = mb_strtolower(trim($this->cleaned_data['account']));
|
||||||
|
$sql = new Pluf_SQL('email=%s OR login=%s',
|
||||||
|
array($account, $account));
|
||||||
|
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() == 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Sorry, we cannot find a user with this email address or login. Feel free to try again.'));
|
||||||
|
}
|
||||||
|
$ok = false;
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if ($user->active) {
|
||||||
|
$ok = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$user->active and $user->first_name == '---') {
|
||||||
|
$ok = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$ok = false; // This ensures an all or nothing ok.
|
||||||
|
}
|
||||||
|
if (!$ok) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Sorry, we cannot find a user with this email address or login. Feel free to try again.'));
|
||||||
|
}
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the reminder email.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
$account = $this->cleaned_data['account'];
|
||||||
|
$sql = new Pluf_SQL('email=%s OR login=%s',
|
||||||
|
array($account, $account));
|
||||||
|
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
|
||||||
|
|
||||||
|
$return_url = '';
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if ($user->active) {
|
||||||
|
$return_url = Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode');
|
||||||
|
$tmpl = new Pluf_Template('idf/user/passrecovery-email.txt');
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
$code = trim($cr->encrypt($user->email.':'.$user->id.':'.time().':primary'),
|
||||||
|
'~');
|
||||||
|
$code = substr(md5(Pluf::f('secret_key').$code), 0, 2).$code;
|
||||||
|
$url = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecovery', array($code), array(), false);
|
||||||
|
$urlic = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode', array(), array(), false);
|
||||||
|
$context = new Pluf_Template_Context(
|
||||||
|
array('url' => Pluf_Template::markSafe($url),
|
||||||
|
'urlik' => Pluf_Template::markSafe($urlic),
|
||||||
|
'user' => Pluf_Template::markSafe($user),
|
||||||
|
'key' => Pluf_Template::markSafe($code)));
|
||||||
|
$email = new Pluf_Mail(Pluf::f('from_email'), $user->email,
|
||||||
|
__('Password Recovery - InDefero'));
|
||||||
|
$email->setReturnPath(Pluf::f('bounce_email', Pluf::f('from_email')));
|
||||||
|
$email->addTextMessage($tmpl->render($context));
|
||||||
|
$email->sendMail();
|
||||||
|
}
|
||||||
|
if (!$user->active and $user->first_name == '---') {
|
||||||
|
$return_url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey');
|
||||||
|
IDF_Form_Register::sendVerificationEmail($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return_url;
|
||||||
|
}
|
||||||
|
}
|
104
indefero/src/IDF/Form/PasswordInputKey.php
Normal file
104
indefero/src/IDF/Form/PasswordInputKey.php
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the validity of a confirmation key to reset a password.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_PasswordInputKey extends Pluf_Form
|
||||||
|
{
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your verification key'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'size' => 50,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the key.
|
||||||
|
*/
|
||||||
|
public function clean_key()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['key'] = trim($this->cleaned_data['key']);
|
||||||
|
$error = __('We are sorry but this validation key is not valid. Maybe you should directly copy/paste it from your validation email.');
|
||||||
|
if (false === ($cres=self::checkKeyHash($this->cleaned_data['key']))) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('email=%s AND id=%s',
|
||||||
|
array($cres[0], $cres[1]));
|
||||||
|
if ($guser->getCount(array('filter' => $sql->gen())) != 1) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
if ((time() - $cres[2]) > 86400) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Sorry, but this verification key has expired, please restart the password recovery sequence. For security reasons, the verification key is only valid 24h.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return string Url to redirect to the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save an invalid form.'));
|
||||||
|
}
|
||||||
|
return Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecovery',
|
||||||
|
array($this->cleaned_data['key']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return false or an array with the email, id and timestamp.
|
||||||
|
*
|
||||||
|
* This is a static function to be reused by other forms.
|
||||||
|
*
|
||||||
|
* @param string Confirmation key
|
||||||
|
* @return mixed Either false or array(email, id, timestamp)
|
||||||
|
*/
|
||||||
|
public static function checkKeyHash($key)
|
||||||
|
{
|
||||||
|
$hash = substr($key, 0, 2);
|
||||||
|
$encrypted = substr($key, 2);
|
||||||
|
if ($hash != substr(md5(Pluf::f('secret_key').$encrypted), 0, 2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
$f = explode(':', $cr->decrypt($encrypted), 3);
|
||||||
|
if (count($f) != 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $f;
|
||||||
|
}
|
||||||
|
}
|
138
indefero/src/IDF/Form/PasswordReset.php
Normal file
138
indefero/src/IDF/Form/PasswordReset.php
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the password of a user.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_PasswordReset extends Pluf_Form
|
||||||
|
{
|
||||||
|
protected $user = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->fields['key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your verification key'),
|
||||||
|
'initial' => $extra['key'],
|
||||||
|
'widget' => 'Pluf_Form_Widget_HiddenInput',
|
||||||
|
));
|
||||||
|
$this->fields['password'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'help_text' => __('Your password must be hard for other people to find it, but easy for you to remember.'),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['password2'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Confirm your password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the passwords.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if ($this->cleaned_data['password'] != $this->cleaned_data['password2']) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The two passwords must be the same.'));
|
||||||
|
}
|
||||||
|
if (!$this->user->active) {
|
||||||
|
throw new Pluf_Form_Invalid(__('This account is not active. Please contact the forge administrator to activate it.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the key.
|
||||||
|
*/
|
||||||
|
public function clean_key()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['key'] = trim($this->cleaned_data['key']);
|
||||||
|
$error = __('We are sorry but this validation key is not valid. Maybe you should directly copy/paste it from your validation email.');
|
||||||
|
if (false === ($cres=IDF_Form_PasswordInputKey::checkKeyHash($this->cleaned_data['key']))) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('email=%s AND id=%s',
|
||||||
|
array($cres[0], $cres[1]));
|
||||||
|
if ($guser->getCount(array('filter' => $sql->gen())) != 1) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
if ((time() - $cres[2]) > 86400) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Sorry, but this verification key has expired, please restart the password recovery sequence. For security reasons, the verification key is only valid 24h.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save an invalid form.'));
|
||||||
|
}
|
||||||
|
$this->user->setFromFormData($this->cleaned_data);
|
||||||
|
if ($commit) {
|
||||||
|
$this->user->update();
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* Pluf_User::passwordUpdated
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_PasswordReset
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal is sent when the user reset his
|
||||||
|
* password from the password recovery page.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('user' => $user)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('user' => $this->user);
|
||||||
|
Pluf_Signal::send('Pluf_User::passwordUpdated',
|
||||||
|
'IDF_Form_PasswordReset', $params);
|
||||||
|
}
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
231
indefero/src/IDF/Form/ProjectConf.php
Normal file
231
indefero/src/IDF/Form/ProjectConf.php
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright(C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
#(at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the project.
|
||||||
|
*/
|
||||||
|
class IDF_Form_ProjectConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
$this->user = $extra["user"];
|
||||||
|
$conf = $this->project->getConf();
|
||||||
|
|
||||||
|
// Basic part
|
||||||
|
$this->fields['name'] = new Pluf_Form_Field_Varchar(array('required' => true,
|
||||||
|
'label' => __('Name'),
|
||||||
|
'initial' => $this->project->name,
|
||||||
|
));
|
||||||
|
$this->fields['shortdesc'] = new Pluf_Form_Field_Varchar(array('required' => true,
|
||||||
|
'label' => __('Short Description'),
|
||||||
|
'initial' => $this->project->shortdesc,
|
||||||
|
'widget_attrs' => array('size' => '68'),
|
||||||
|
));
|
||||||
|
$this->fields['description'] = new Pluf_Form_Field_Varchar(array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => $this->project->description,
|
||||||
|
'widget_attrs' => array('cols' => 68,
|
||||||
|
'rows' => 26,
|
||||||
|
),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
$this->fields['external_project_url'] = new Pluf_Form_Field_Varchar(array('required' => false,
|
||||||
|
'label' => __('External URL'),
|
||||||
|
'widget_attrs' => array('size' => '68'),
|
||||||
|
'initial' => $conf->getVal('external_project_url'),
|
||||||
|
|
||||||
|
));
|
||||||
|
if ($this->user->administrator)
|
||||||
|
{
|
||||||
|
$this->fields['enableads'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Enable advertising'),
|
||||||
|
'initial' => $this->project->enableads,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$this->fields['enableads'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Enable advertising'),
|
||||||
|
'initial' => $this->project->enableads,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
'widget_attrs' => array('disabled' => 'disabled')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$tags = $this->project->get_tags_list();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$initial = '';
|
||||||
|
if (isset($tags[$i-1])) {
|
||||||
|
if ($tags[$i-1]->class != 'Other') {
|
||||||
|
$initial = (string) $tags[$i-1];
|
||||||
|
} else {
|
||||||
|
$initial = $tags[$i-1]->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logo part
|
||||||
|
$upload_path = Pluf::f('upload_path', false);
|
||||||
|
if (false === $upload_path) {
|
||||||
|
throw new Pluf_Exception_SettingError(__('The "upload_path" configuration variable was not set.'));
|
||||||
|
}
|
||||||
|
$upload_path .= '/' . $this->project->shortname;
|
||||||
|
$filename = '/%s';
|
||||||
|
$this->fields['logo'] = new Pluf_Form_Field_File(array('required' => false,
|
||||||
|
'label' => __('Update the logo'),
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('The logo must be a picture with a size of 32 by 32.'),
|
||||||
|
'max_size' => Pluf::f('max_upload_size', 5 * 1024),
|
||||||
|
'move_function_params' =>
|
||||||
|
array('upload_path' => $upload_path,
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => true,
|
||||||
|
'file_name' => $filename,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['logo_remove'] = new Pluf_Form_Field_Boolean(array('required' => false,
|
||||||
|
'label' => __('Remove the current logo'),
|
||||||
|
'initial' => false,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we have uploaded a file, but the form failed remove it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
if (!empty($this->cleaned_data['logo'])
|
||||||
|
&& file_exists(Pluf::f('upload_path').'/'.$this->cleaned_data['logo'])) {
|
||||||
|
unlink(Pluf::f('upload_path').'/'.$this->cleaned_data['logo']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if (!isset($this->cleaned_data['logo_remove'])) {
|
||||||
|
$this->cleaned_data['logo_remove'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_logo()
|
||||||
|
{
|
||||||
|
if (empty($this->cleaned_data['logo'])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta = getimagesize(Pluf::f('upload_path') . '/' . $this->project->shortname . $this->cleaned_data['logo']);
|
||||||
|
|
||||||
|
if ($meta === false) {
|
||||||
|
throw new Pluf_Form_Invalid(__('Could not determine the size of the uploaded picture.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($meta[0] !== 32 || $meta[1] !== 32) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The picture must have a size of 32 by 32.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cleaned_data['logo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_external_project_url()
|
||||||
|
{
|
||||||
|
return self::checkWebURL($this->cleaned_data['external_project_url']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function checkWebURL($url)
|
||||||
|
{
|
||||||
|
$url = trim($url);
|
||||||
|
if (empty($url)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$parsed = parse_url($url);
|
||||||
|
if ($parsed === false || !array_key_exists('scheme', $parsed) ||
|
||||||
|
($parsed['scheme'] != 'http' && $parsed['scheme'] != 'https')) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The entered URL is invalid. Only http and https URLs are allowed.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($commit=true)
|
||||||
|
{
|
||||||
|
// Add a tag for each label
|
||||||
|
$tagids = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::addGlobal($name, $class);
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic part
|
||||||
|
$this->project->name = $this->cleaned_data['name'];
|
||||||
|
$this->project->shortdesc = $this->cleaned_data['shortdesc'];
|
||||||
|
$this->project->description = $this->cleaned_data['description'];
|
||||||
|
$this->project->batchAssoc('IDF_Tag', $tagids);
|
||||||
|
if ($this->user->administrator)
|
||||||
|
$this->project->enableads = $this->cleaned_data['enableads'];
|
||||||
|
$this->project->update();
|
||||||
|
|
||||||
|
$conf = $this->project->getConf();
|
||||||
|
if (!empty($this->cleaned_data['logo'])) {
|
||||||
|
$conf->setVal('logo', $this->cleaned_data['logo']);
|
||||||
|
}
|
||||||
|
if (!empty($this->cleaned_data['external_project_url'])) {
|
||||||
|
$conf->setVal('external_project_url', $this->cleaned_data['external_project_url']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$conf->delVal('external_project_url');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->cleaned_data['logo_remove'] === true) {
|
||||||
|
@unlink(Pluf::f('upload_path') . '/' . $this->project->shortname . $conf->getVal('logo'));
|
||||||
|
$conf->delVal('logo');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
165
indefero/src/IDF/Form/Register.php
Normal file
165
indefero/src/IDF/Form/Register.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new user account.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_Register extends Pluf_Form
|
||||||
|
{
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->request = $extra['request'];
|
||||||
|
$login = '';
|
||||||
|
if (isset($extra['initial']['login'])) {
|
||||||
|
$login = $extra['initial']['login'];
|
||||||
|
}
|
||||||
|
$this->fields['login'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your login'),
|
||||||
|
'max_length' => 15,
|
||||||
|
'min_length' => 3,
|
||||||
|
'initial' => $login,
|
||||||
|
'help_text' => __('The login must be between 3 and 15 characters long and contain only letters and digits.'),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 15,
|
||||||
|
'size' => 10,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['email'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your email'),
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('We will never send you any unsolicited emails. We hate spam too!'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['regkey'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Registration Key'),
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('Please enter the key given to you by adamsna[at]datanethost.net'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['terms'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('I agree to the terms and conditions.'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_regkey()
|
||||||
|
{
|
||||||
|
if ($this->cleaned_data['regkey'] != "2rv9o4nb5")
|
||||||
|
throw new Pluf_Form_Invalid("The regkey was incorrect - please contact Nathan for the key!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean_login()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['login'] = mb_strtolower(trim($this->cleaned_data['login']));
|
||||||
|
if (preg_match('/[^A-Za-z0-9]/', $this->cleaned_data['login'])) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The login "%s" can only contain letters and digits.'), $this->cleaned_data['login']));
|
||||||
|
}
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('login=%s', $this->cleaned_data['login']);
|
||||||
|
if ($guser->getCount(array('filter' => $sql->gen())) > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The login "%s" is already used, please find another one.'), $this->cleaned_data['login']));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['login'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the terms.
|
||||||
|
*/
|
||||||
|
public function clean_terms()
|
||||||
|
{
|
||||||
|
if (!$this->cleaned_data['terms']) {
|
||||||
|
throw new Pluf_Form_Invalid(__('We know, this is boring, but you need to agree with the terms and conditions.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['terms'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_email()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['email'] = mb_strtolower(trim($this->cleaned_data['email']));
|
||||||
|
if (Pluf::factory('IDF_EmailAddress')->get_user_for_email_address($this->cleaned_data['email']) != null) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The email "%1$s" is already used. If you need to, you can <a href="%2$s">recover your password</a>.'), $this->cleaned_data['email'], Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryAsk')));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
$user = new Pluf_User();
|
||||||
|
$user->first_name = '---'; // with both this set and
|
||||||
|
// active==false we can find later
|
||||||
|
// on, all the unconfirmed accounts
|
||||||
|
// that could be purged.
|
||||||
|
$user->last_name = $this->cleaned_data['login'];
|
||||||
|
$user->login = $this->cleaned_data['login'];
|
||||||
|
$user->email = $this->cleaned_data['email'];
|
||||||
|
$user->language = $this->request->language_code;
|
||||||
|
$user->active = false;
|
||||||
|
$user->create();
|
||||||
|
self::sendVerificationEmail($user);
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sendVerificationEmail($user)
|
||||||
|
{
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
$from_email = Pluf::f('from_email');
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
$encrypted = trim($cr->encrypt($user->email.':'.$user->id), '~');
|
||||||
|
$key = substr(md5(Pluf::f('secret_key').$encrypted), 0, 2).$encrypted;
|
||||||
|
$url = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views::registerConfirmation', array($key), array(), false);
|
||||||
|
$urlik = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey', array(), array(), false);
|
||||||
|
$context = new Pluf_Template_Context(
|
||||||
|
array('key' => $key,
|
||||||
|
'url' => $url,
|
||||||
|
'urlik' => $urlik,
|
||||||
|
'user'=> $user,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/register/confirmation-email.txt');
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
$email = new Pluf_Mail($from_email, $user->email,
|
||||||
|
__('Confirm the creation of your account.'));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->sendMail();
|
||||||
|
}
|
||||||
|
}
|
170
indefero/src/IDF/Form/RegisterConfirmation.php
Normal file
170
indefero/src/IDF/Form/RegisterConfirmation.php
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirmation of the form.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_RegisterConfirmation extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $_user = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->_user = $extra['user'];
|
||||||
|
|
||||||
|
$this->fields['key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your confirmation key'),
|
||||||
|
'initial' => $extra['key'],
|
||||||
|
'widget' => 'Pluf_Form_Widget_HiddenInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'readonly' => 'readonly',
|
||||||
|
),
|
||||||
|
|
||||||
|
));
|
||||||
|
$this->fields['first_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('First name'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['last_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Last name'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['password'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'help_text' => __('Your password must be hard for other people to guess, but easy for you to remember.'),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['password2'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Confirm your password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just a simple control.
|
||||||
|
*/
|
||||||
|
public function clean_key()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['key'] = trim($this->cleaned_data['key']);
|
||||||
|
$error = __('We are sorry but this confirmation key is not valid. Maybe you should directly copy/paste it from your confirmation email.');
|
||||||
|
if (false === ($email_id=IDF_Form_RegisterInputKey::checkKeyHash($this->cleaned_data['key']))) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('email=%s AND id=%s', $email_id);
|
||||||
|
$users = $guser->getList(array('filter' => $sql->gen()));
|
||||||
|
if ($users->count() != 1) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
if ($users[0]->active) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('This account has already been confirmed. Maybe should you try to <a href="%s">recover your password</a>.'), Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryAsk')));
|
||||||
|
}
|
||||||
|
$this->_user_id = $email_id[1];
|
||||||
|
return $this->cleaned_data['key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the passwords.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if ($this->cleaned_data['password'] != $this->cleaned_data['password2']) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The two passwords must be the same.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save an invalid form.'));
|
||||||
|
}
|
||||||
|
$this->_user->setFromFormData($this->cleaned_data);
|
||||||
|
$this->_user->active = true;
|
||||||
|
$this->_user->administrator = false;
|
||||||
|
$this->_user->staff = false;
|
||||||
|
if ($commit) {
|
||||||
|
$this->_user->update();
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* Pluf_User::passwordUpdated
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_RegisterConfirmation
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal is sent when the user updated his
|
||||||
|
* password from his account page.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('user' => $user)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('user' => $this->_user);
|
||||||
|
Pluf_Signal::send('Pluf_User::passwordUpdated',
|
||||||
|
'IDF_Form_RegisterConfirmation', $params);
|
||||||
|
}
|
||||||
|
return $this->_user;
|
||||||
|
}
|
||||||
|
}
|
96
indefero/src/IDF/Form/RegisterInputKey.php
Normal file
96
indefero/src/IDF/Form/RegisterInputKey.php
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the validity of a confirmation key.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_RegisterInputKey extends Pluf_Form
|
||||||
|
{
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your confirmation key'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'size' => 50,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the key.
|
||||||
|
*/
|
||||||
|
public function clean_key()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['key'] = trim($this->cleaned_data['key']);
|
||||||
|
$error = __('We are sorry but this confirmation key is not valid. Maybe you should directly copy/paste it from your confirmation email.');
|
||||||
|
if (false === ($email_id=self::checkKeyHash($this->cleaned_data['key']))) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
$sql = new Pluf_SQL('email=%s AND id=%s', $email_id);
|
||||||
|
if ($guser->getCount(array('filter' => $sql->gen())) != 1) {
|
||||||
|
throw new Pluf_Form_Invalid($error);
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return string Url to redirect to the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save an invalid form.'));
|
||||||
|
}
|
||||||
|
return Pluf_HTTP_URL_urlForView('IDF_Views::registerConfirmation',
|
||||||
|
array($this->cleaned_data['key']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return false or an array with the email and id.
|
||||||
|
*
|
||||||
|
* This is a static function to be reused by other forms.
|
||||||
|
*
|
||||||
|
* @param string Confirmation key
|
||||||
|
* @return mixed Either false or array(email, id)
|
||||||
|
*/
|
||||||
|
public static function checkKeyHash($key)
|
||||||
|
{
|
||||||
|
$hash = substr($key, 0, 2);
|
||||||
|
$encrypted = substr($key, 2);
|
||||||
|
if ($hash != substr(md5(Pluf::f('secret_key').$encrypted), 0, 2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
return explode(':', $cr->decrypt($encrypted), 2);
|
||||||
|
}
|
||||||
|
}
|
255
indefero/src/IDF/Form/ReviewCreate.php
Normal file
255
indefero/src/IDF/Form/ReviewCreate.php
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new code review.
|
||||||
|
*
|
||||||
|
* This creates an IDF_Review and the corresponding IDF_Review_Patch.
|
||||||
|
*/
|
||||||
|
class IDF_Form_ReviewCreate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $show_full = false;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||||
|
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||||
|
$this->show_full = true;
|
||||||
|
}
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Summary'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['description'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 7,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$sql = new Pluf_SQL('project=%s', array($this->project->id));
|
||||||
|
$commits = Pluf::factory('IDF_Commit')->getList(array('order' => 'creation_dtime DESC',
|
||||||
|
'nb' => 10,
|
||||||
|
'filter' => $sql->gen()));
|
||||||
|
$choices = array();
|
||||||
|
foreach ($commits as $c) {
|
||||||
|
$id = (strlen($c->scm_id) > 10) ? substr($c->scm_id, 0, 10) : $c->scm_id;
|
||||||
|
$ext = (mb_strlen($c->summary) > 50) ? mb_substr($c->summary, 0, 47).'...' : $c->summary;
|
||||||
|
$choices[$id.' - '.$ext] = $c->scm_id;
|
||||||
|
}
|
||||||
|
$this->fields['commit'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Commit'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'choices' => $choices,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$upload_path = Pluf::f('upload_issue_path', false);
|
||||||
|
if (false === $upload_path) {
|
||||||
|
throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
|
||||||
|
}
|
||||||
|
$md5 = md5(rand().microtime().Pluf_Utils::getRandomString());
|
||||||
|
// We add .dummy to try to mitigate security issues in the
|
||||||
|
// case of someone allowing the upload path to be accessible
|
||||||
|
// to everybody.
|
||||||
|
$filename = substr($md5, 0, 2).'/'.substr($md5, 2, 2).'/'.substr($md5, 4).'/%s.dummy';
|
||||||
|
$this->fields['patch'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Patch'),
|
||||||
|
'move_function_params' =>
|
||||||
|
array('upload_path' => $upload_path,
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'file_name' => $filename,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if ($this->show_full) {
|
||||||
|
$this->fields['status'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Status'),
|
||||||
|
'initial' => 'New',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 20,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_patch()
|
||||||
|
{
|
||||||
|
$diff = new IDF_Diff(file_get_contents(Pluf::f('upload_issue_path').'/'
|
||||||
|
.$this->cleaned_data['patch']));
|
||||||
|
$diff->parse();
|
||||||
|
if (count($diff->files) == 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('We were not able to parse your patch. Please provide a valid patch.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['patch'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_commit()
|
||||||
|
{
|
||||||
|
$commit = self::findCommit($this->cleaned_data['commit']);
|
||||||
|
if (null == $commit) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid commit.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['commit'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_status()
|
||||||
|
{
|
||||||
|
// Check that the status is in the list of official status
|
||||||
|
$tags = $this->project->getTagsFromConfig('labels_issue_open',
|
||||||
|
IDF_Form_IssueTrackingConf::init_open,
|
||||||
|
'Status');
|
||||||
|
$tags = array_merge($this->project->getTagsFromConfig('labels_issue_closed',
|
||||||
|
IDF_Form_IssueTrackingConf::init_closed,
|
||||||
|
'Status')
|
||||||
|
, $tags);
|
||||||
|
$found = false;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if ($tag->name == trim($this->cleaned_data['status'])) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid status.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean the attachments post failure.
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
$upload_path = Pluf::f('upload_issue_path', false);
|
||||||
|
if ($upload_path == false) return;
|
||||||
|
if (!empty($this->cleaned_data['patch']) and
|
||||||
|
file_exists($upload_path.'/'.$this->cleaned_data['patch'])) {
|
||||||
|
@unlink($upload_path.'/'.$this->cleaned_data['patch']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// Create the review
|
||||||
|
$review = new IDF_Review();
|
||||||
|
$review->project = $this->project;
|
||||||
|
$review->summary = $this->cleaned_data['summary'];
|
||||||
|
$review->submitter = $this->user;
|
||||||
|
if (!isset($this->cleaned_data['status'])) {
|
||||||
|
$this->cleaned_data['status'] = 'New';
|
||||||
|
}
|
||||||
|
$review->status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
|
||||||
|
$review->create();
|
||||||
|
// add the first patch
|
||||||
|
$patch = new IDF_Review_Patch();
|
||||||
|
$patch->review = $review;
|
||||||
|
$patch->summary = __('Initial patch to be reviewed.');
|
||||||
|
$patch->description = $this->cleaned_data['description'];
|
||||||
|
$patch->commit = self::findCommit($this->cleaned_data['commit']);
|
||||||
|
$patch->patch = $this->cleaned_data['patch'];
|
||||||
|
$patch->create();
|
||||||
|
$patch->notify($this->project->getConf());
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Review::create
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_ReviewCreate
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform a set of tasks
|
||||||
|
* just after the creation of a review and the notification.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('review' => $review,
|
||||||
|
* 'patch' => $patch);
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('review' => $review,
|
||||||
|
'patch' => $patch);
|
||||||
|
Pluf_Signal::send('IDF_Review::create', 'IDF_Form_ReviewCreate',
|
||||||
|
$params);
|
||||||
|
return $review;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on the given string, try to find the matching commit.
|
||||||
|
*
|
||||||
|
* If no user found, simply returns null.
|
||||||
|
*
|
||||||
|
* @param string Commit
|
||||||
|
* @return IDF_Commit or null
|
||||||
|
*/
|
||||||
|
public static function findCommit($string)
|
||||||
|
{
|
||||||
|
$string = trim($string);
|
||||||
|
if (strlen($string) == 0) return null;
|
||||||
|
$gc = new IDF_Commit();
|
||||||
|
$sql = new Pluf_SQL('scm_id=%s', array($string));
|
||||||
|
$gcs = $gc->getList(array('filter' => $sql->gen()));
|
||||||
|
if ($gcs->count() > 0) {
|
||||||
|
return $gcs[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
181
indefero/src/IDF/Form/ReviewFileComment.php
Normal file
181
indefero/src/IDF/Form/ReviewFileComment.php
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add comments to files in a review.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_ReviewFileComment extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $files = null;
|
||||||
|
public $patch = null;
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->files = $extra['files'];
|
||||||
|
$this->patch = $extra['patch'];
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
|
||||||
|
foreach ($this->files as $filename => $def) {
|
||||||
|
$this->fields[md5($filename)] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Comment'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 9,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('General comment'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 9,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||||
|
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||||
|
$this->show_full = true;
|
||||||
|
} else {
|
||||||
|
$this->show_full = false;
|
||||||
|
}
|
||||||
|
if ($this->show_full) {
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Summary'),
|
||||||
|
'initial' => $this->patch->get_review()->summary,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['status'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Status'),
|
||||||
|
'initial' => $this->patch->get_review()->get_status()->name,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 20,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
$isOk = false;
|
||||||
|
|
||||||
|
foreach($this->files as $filename => $def) {
|
||||||
|
$this->cleaned_data[md5($filename)] = trim($this->cleaned_data[md5($filename)]);
|
||||||
|
if(!empty($this->cleaned_data[md5($filename)])) {
|
||||||
|
$isOk = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($this->cleaned_data['content'])) {
|
||||||
|
$isOk = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$isOk) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You need to provide your general comment about the proposal, or comments on at least one file.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_content()
|
||||||
|
{
|
||||||
|
$content = trim($this->cleaned_data['content']);
|
||||||
|
if(empty($content)) {
|
||||||
|
if ($this->fields['status']->initial != $this->fields['status']->value) {
|
||||||
|
return __('The status have been updated.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Pluf_Form_Invalid(__('This field is required.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// create a base comment
|
||||||
|
$bc = new IDF_Review_Comment();
|
||||||
|
$bc->patch = $this->patch;
|
||||||
|
$bc->submitter = $this->user;
|
||||||
|
$bc->content = $this->cleaned_data['content'];
|
||||||
|
$review = $this->patch->get_review();
|
||||||
|
if ($this->show_full) {
|
||||||
|
// Compare between the old and the new data
|
||||||
|
// Status, summary
|
||||||
|
$changes = array();
|
||||||
|
$status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
|
||||||
|
if ($status->id != $this->patch->get_review()->status) {
|
||||||
|
$changes['st'] = $status->name;
|
||||||
|
}
|
||||||
|
if (trim($this->patch->get_review()->summary) != trim($this->cleaned_data['summary'])) {
|
||||||
|
$changes['su'] = trim($this->cleaned_data['summary']);
|
||||||
|
}
|
||||||
|
// Update the review
|
||||||
|
$review->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$review->status = $status;
|
||||||
|
$bc->changes = $changes;
|
||||||
|
}
|
||||||
|
$bc->create();
|
||||||
|
foreach ($this->files as $filename => $def) {
|
||||||
|
if (!empty($this->cleaned_data[md5($filename)])) {
|
||||||
|
// Add a comment.
|
||||||
|
$c = new IDF_Review_FileComment();
|
||||||
|
$c->comment = $bc;
|
||||||
|
$c->cfile = $filename;
|
||||||
|
$c->content = $this->cleaned_data[md5($filename)];
|
||||||
|
$c->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$review->update(); // reindex and put up in the list.
|
||||||
|
return $bc;
|
||||||
|
}
|
||||||
|
}
|
62
indefero/src/IDF/Form/SourceConf.php
Normal file
62
indefero/src/IDF/Form/SourceConf.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the source.
|
||||||
|
*
|
||||||
|
* Only the modification of the login/password for subversion is
|
||||||
|
* authorized.
|
||||||
|
*/
|
||||||
|
class IDF_Form_SourceConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $conf = null;
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->conf = $extra['conf'];
|
||||||
|
if ($extra['remote_svn']) {
|
||||||
|
$this->fields['svn_username'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Repository username'),
|
||||||
|
'initial' => $this->conf->getVal('svn_username', ''),
|
||||||
|
'widget_attrs' => array('size' => '15'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['svn_password'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Repository password'),
|
||||||
|
'initial' => $this->conf->getVal('svn_password', ''),
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$this->fields['webhook_url'] = new Pluf_Form_Field_Url(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Webhook URL'),
|
||||||
|
'initial' => $this->conf->getVal('webhook_url', ''),
|
||||||
|
'widget_attrs' => array('size' => 35),
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
149
indefero/src/IDF/Form/TabsConf.php
Normal file
149
indefero/src/IDF/Form/TabsConf.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the tabs access.
|
||||||
|
*/
|
||||||
|
class IDF_Form_TabsConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $conf = null;
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->conf = $extra['conf'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
|
||||||
|
$ak = array('downloads_access_rights' => __('Downloads'),
|
||||||
|
'review_access_rights' => __('Code Review'),
|
||||||
|
'wiki_access_rights' => __('Documentation'),
|
||||||
|
'source_access_rights' => __('Source'),
|
||||||
|
'issues_access_rights' => __('Issues'),);
|
||||||
|
foreach ($ak as $key=>$label) {
|
||||||
|
$this->fields[$key] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => $label,
|
||||||
|
'initial' => $this->conf->getVal($key, 'all'),
|
||||||
|
'widget_attrs' => array('choices' =>
|
||||||
|
array(
|
||||||
|
__('Open to all') => 'all',
|
||||||
|
__('Signed in users') => 'login',
|
||||||
|
__('Project members') => 'members',
|
||||||
|
__('Project owners') => 'owners',
|
||||||
|
__('Closed') => 'none',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$sections = array(
|
||||||
|
'downloads_notification',
|
||||||
|
'review_notification',
|
||||||
|
'wiki_notification',
|
||||||
|
'source_notification',
|
||||||
|
'issues_notification',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($sections as $section) {
|
||||||
|
$this->fields[$section.'_owners_enabled'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project owners'),
|
||||||
|
'initial' => $this->conf->getVal($section.'_owners_enabled', false),
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
$this->fields[$section.'_members_enabled'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Project members'),
|
||||||
|
'initial' => $this->conf->getVal($section.'_members_enabled', false),
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
$this->fields[$section.'_email_enabled'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Others'),
|
||||||
|
'initial' => $this->conf->getVal($section.'_email_enabled', false),
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
if ($this->conf->getVal($section.'_email_enabled', false)) {
|
||||||
|
$attrs['readonly'] = 'readonly';
|
||||||
|
}
|
||||||
|
$this->fields[$section.'_email'] = new IDF_Form_Field_EmailList(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => null,
|
||||||
|
'initial' => $this->conf->getVal($section.'_email', ''),
|
||||||
|
'widget_attrs' => array('size' => 20),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fields['private_project'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Private project'),
|
||||||
|
'initial' => $this->project->private,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
));
|
||||||
|
$this->fields['authorized_users'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Extra authorized users'),
|
||||||
|
'widget_attrs' => array('rows' => 7,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_authorized_users()
|
||||||
|
{
|
||||||
|
return IDF_Form_MembersConf::checkBadLogins($this->cleaned_data['authorized_users']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// remove all the permissions
|
||||||
|
$perm = Pluf_Permission::getFromString('IDF.project-authorized-user');
|
||||||
|
$cm = $this->project->getMembershipData();
|
||||||
|
$guser = new Pluf_User();
|
||||||
|
foreach ($cm['authorized'] as $user) {
|
||||||
|
Pluf_RowPermission::remove($user, $this->project, $perm);
|
||||||
|
}
|
||||||
|
if ($this->cleaned_data['private_project']) {
|
||||||
|
foreach (preg_split("/\015\012|\015|\012|\,/", $this->cleaned_data['authorized_users'], -1, PREG_SPLIT_NO_EMPTY) as $login) {
|
||||||
|
$sql = new Pluf_SQL('login=%s', array(trim($login)));
|
||||||
|
$users = $guser->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() == 1) {
|
||||||
|
Pluf_RowPermission::add($users[0], $this->project, $perm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->project->private = 1;
|
||||||
|
} else {
|
||||||
|
$this->project->private = 0;
|
||||||
|
}
|
||||||
|
$this->project->update();
|
||||||
|
$this->project->membershipsUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
177
indefero/src/IDF/Form/UpdateUpload.php
Normal file
177
indefero/src/IDF/Form/UpdateUpload.php
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a file for download.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_UpdateUpload extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $upload = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
$this->upload = $extra['upload'];
|
||||||
|
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Summary'),
|
||||||
|
'initial' => $this->upload->summary,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['changelog'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => $this->upload->changelog,
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 13,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$tags = $this->upload->get_tags_list();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$initial = '';
|
||||||
|
if (isset($tags[$i-1])) {
|
||||||
|
if ($tags[$i-1]->class != 'Other') {
|
||||||
|
$initial = (string) $tags[$i-1];
|
||||||
|
} else {
|
||||||
|
$initial = $tags[$i-1]->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($this->project);
|
||||||
|
$onemax = array();
|
||||||
|
foreach (explode(',', $conf->getVal('labels_download_one_max', IDF_Form_UploadConf::init_one_max)) as $class) {
|
||||||
|
if (trim($class) != '') {
|
||||||
|
$onemax[] = mb_strtolower(trim($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$this->cleaned_data['label'.$i] = trim($this->cleaned_data['label'.$i]);
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||||
|
trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'other';
|
||||||
|
$name = $this->cleaned_data['label'.$i];
|
||||||
|
}
|
||||||
|
if (!isset($count[$class])) $count[$class] = 1;
|
||||||
|
else $count[$class] += 1;
|
||||||
|
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||||
|
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||||
|
$this->errors['label'.$i][] = sprintf(__('You cannot provide more than one label from the %s class to an issue.'), $class);
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// Add a tag for each label
|
||||||
|
$tags = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
$tags[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Create the upload
|
||||||
|
$this->upload->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$this->upload->changelog = trim($this->cleaned_data['changelog']);
|
||||||
|
$this->upload->modif_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
$this->upload->update();
|
||||||
|
$this->upload->batchAssoc('IDF_Tag', $tags);
|
||||||
|
|
||||||
|
// Send the notification
|
||||||
|
$this->upload->notify($this->project->getConf(), false);
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Upload::update
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_UpdateUpload
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform a set of tasks
|
||||||
|
* just after the update of an uploaded file.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('upload' => $upload);
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('upload' => $this->upload);
|
||||||
|
Pluf_Signal::send('IDF_Upload::update',
|
||||||
|
'IDF_Form_UpdateUpload', $params);
|
||||||
|
return $this->upload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
205
indefero/src/IDF/Form/Upload.php
Normal file
205
indefero/src/IDF/Form/Upload.php
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload a file for download.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_Upload extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Summary'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['changelog'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 58,
|
||||||
|
'rows' => 13,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['file'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('File'),
|
||||||
|
'initial' => '',
|
||||||
|
'max_size' => Pluf::f('max_upload_size', 2097152),
|
||||||
|
'move_function_params' => array('upload_path' => Pluf::f('upload_path').'/'.$this->project->shortname.'/files',
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => false),
|
||||||
|
|
||||||
|
));
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function clean_file()
|
||||||
|
{
|
||||||
|
// FIXME: we do the same in IDF_Form_WikiResourceCreate and a couple of other places as well
|
||||||
|
$extra = strtolower(implode('|', explode(' ', Pluf::f('idf_extra_upload_ext'))));
|
||||||
|
if (strlen($extra)) $extra .= '|';
|
||||||
|
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $this->cleaned_data['file'])) {
|
||||||
|
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
|
||||||
|
throw new Pluf_Form_Invalid(__('For security reasons, you cannot upload a file with this extension.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['file'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($this->project);
|
||||||
|
$onemax = array();
|
||||||
|
foreach (explode(',', $conf->getVal('labels_download_one_max', IDF_Form_UploadConf::init_one_max)) as $class) {
|
||||||
|
if (trim($class) != '') {
|
||||||
|
$onemax[] = mb_strtolower(trim($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
$this->cleaned_data['label'.$i] = trim($this->cleaned_data['label'.$i]);
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||||
|
trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'other';
|
||||||
|
$name = $this->cleaned_data['label'.$i];
|
||||||
|
}
|
||||||
|
if (!isset($count[$class])) $count[$class] = 1;
|
||||||
|
else $count[$class] += 1;
|
||||||
|
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||||
|
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||||
|
$this->errors['label'.$i][] = sprintf(__('You cannot provide more than one label from the %s class to a download.'), $class);
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we have uploaded a file, but the form failed remove it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
if (!empty($this->cleaned_data['file'])
|
||||||
|
and file_exists(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file'])) {
|
||||||
|
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// Add a tag for each label
|
||||||
|
$tags = array();
|
||||||
|
for ($i=1;$i<7;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tags[] = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Create the upload
|
||||||
|
$upload = new IDF_Upload();
|
||||||
|
$upload->project = $this->project;
|
||||||
|
$upload->submitter = $this->user;
|
||||||
|
$upload->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$upload->changelog = trim($this->cleaned_data['changelog']);
|
||||||
|
$upload->file = $this->cleaned_data['file'];
|
||||||
|
$upload->filesize = filesize(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
|
||||||
|
$upload->downloads = 0;
|
||||||
|
$upload->create();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$upload->setAssoc($tag);
|
||||||
|
}
|
||||||
|
// Send the notification
|
||||||
|
$upload->notify($this->project->getConf());
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Upload::create
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_Upload
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform a set of tasks
|
||||||
|
* just after the upload of a file and after the notification run.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('upload' => $upload);
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('upload' => $upload);
|
||||||
|
Pluf_Signal::send('IDF_Upload::create', 'IDF_Form_Upload',
|
||||||
|
$params);
|
||||||
|
return $upload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
227
indefero/src/IDF/Form/UploadArchive.php
Normal file
227
indefero/src/IDF/Form/UploadArchive.php
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload and process an archive file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_UploadArchive extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
private $archiveHelper = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
|
||||||
|
$this->fields['archive'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Archive file'),
|
||||||
|
'initial' => '',
|
||||||
|
'max_size' => Pluf::f('max_upload_archive_size', 20971520),
|
||||||
|
'move_function_params' => array(
|
||||||
|
'upload_path' => Pluf::f('upload_path').'/'.$this->project->shortname.'/archives',
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => true,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function clean_archive()
|
||||||
|
{
|
||||||
|
$this->archiveHelper = new IDF_Form_UploadArchiveHelper(
|
||||||
|
Pluf::f('upload_path').'/'.$this->project->shortname.'/archives/'.$this->cleaned_data['archive']);
|
||||||
|
|
||||||
|
// basic archive validation
|
||||||
|
$this->archiveHelper->validate();
|
||||||
|
|
||||||
|
// extension validation
|
||||||
|
$fileNames = $this->archiveHelper->getEntryNames();
|
||||||
|
foreach ($fileNames as $fileName) {
|
||||||
|
$extra = strtolower(implode('|', explode(' ', Pluf::f('idf_extra_upload_ext'))));
|
||||||
|
if (strlen($extra)) $extra .= '|';
|
||||||
|
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $fileName)) {
|
||||||
|
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['archive']);
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('For security reasons, you cannot upload a file (%s) with this extension.'), $fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// label and file name validation
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($this->project);
|
||||||
|
$onemax = array();
|
||||||
|
foreach (explode(',', $conf->getVal('labels_download_one_max', IDF_Form_UploadConf::init_one_max)) as $class) {
|
||||||
|
if (trim($class) != '') {
|
||||||
|
$onemax[] = mb_strtolower(trim($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($fileNames as $fileName) {
|
||||||
|
$meta = $this->archiveHelper->getMetaData($fileName);
|
||||||
|
$count = array();
|
||||||
|
foreach ($meta['labels'] as $label) {
|
||||||
|
$label = trim($label);
|
||||||
|
if (strpos($label, ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $label, 2);
|
||||||
|
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||||
|
trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'other';
|
||||||
|
$name = $label;
|
||||||
|
}
|
||||||
|
if (!isset($count[$class])) $count[$class] = 1;
|
||||||
|
else $count[$class] += 1;
|
||||||
|
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('You cannot provide more than label from the %1$s class to a download (%2$s).'), $class, $name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = new Pluf_SQL('file=%s AND project=%s', array($fileName, $this->project->id));
|
||||||
|
$upload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen()));
|
||||||
|
|
||||||
|
$meta = $this->archiveHelper->getMetaData($fileName);
|
||||||
|
if ($upload != null && $meta['replaces'] !== $fileName) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('A file with the name "%s" has already been uploaded and is not marked to be replaced.'), $fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cleaned_data['archive'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we have uploaded a file, but the form failed remove it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
if (!empty($this->cleaned_data['archive'])
|
||||||
|
and file_exists(Pluf::f('upload_path').'/'.$this->project->shortname.'/archives/'.$this->cleaned_data['archive'])) {
|
||||||
|
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/archives/'.$this->cleaned_data['archive']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadDir = Pluf::f('upload_path').'/'.$this->project->shortname.'/files/';
|
||||||
|
$fileNames = $this->archiveHelper->getEntryNames();
|
||||||
|
|
||||||
|
foreach ($fileNames as $fileName) {
|
||||||
|
$meta = $this->archiveHelper->getMetaData($fileName);
|
||||||
|
|
||||||
|
// add a tag for each label
|
||||||
|
$tags = array();
|
||||||
|
foreach ($meta['labels'] as $label) {
|
||||||
|
$label = trim($label);
|
||||||
|
if (strlen($label) > 0) {
|
||||||
|
if (strpos($label, ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $label, 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = $label;
|
||||||
|
}
|
||||||
|
$tags[] = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// process a possible replacement
|
||||||
|
if (!empty($meta['replaces'])) {
|
||||||
|
$sql = new Pluf_SQL('file=%s AND project=%s', array($meta['replaces'], $this->project->id));
|
||||||
|
$oldUpload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen()));
|
||||||
|
|
||||||
|
if ($oldUpload) {
|
||||||
|
if ($meta['replaces'] === $fileName) {
|
||||||
|
$oldUpload->delete();
|
||||||
|
} else {
|
||||||
|
$tags = $this->project->getTagsFromConfig('labels_download_predefined',
|
||||||
|
IDF_Form_UploadConf::init_predefined);
|
||||||
|
// the deprecate tag is - by definition - always the last one
|
||||||
|
$deprecatedTag = array_pop($tags);
|
||||||
|
$oldUpload->setAssoc($deprecatedTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract the file
|
||||||
|
$this->archiveHelper->extract($fileName, $uploadDir);
|
||||||
|
|
||||||
|
// create the upload
|
||||||
|
$upload = new IDF_Upload();
|
||||||
|
$upload->project = $this->project;
|
||||||
|
$upload->submitter = $this->user;
|
||||||
|
$upload->summary = trim($meta['summary']);
|
||||||
|
$upload->changelog = trim($meta['description']);
|
||||||
|
$upload->file = $fileName;
|
||||||
|
$upload->filesize = filesize($uploadDir.$fileName);
|
||||||
|
$upload->downloads = 0;
|
||||||
|
$upload->create();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$upload->setAssoc($tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// send the notification
|
||||||
|
$upload->notify($this->project->getConf());
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Upload::create
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_Upload
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform a set of tasks
|
||||||
|
* just after the upload of a file and after the notification run.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('upload' => $upload);
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('upload' => $upload);
|
||||||
|
Pluf_Signal::send('IDF_Upload::create', 'IDF_Form_Upload',
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally unlink the uploaded archive
|
||||||
|
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/archives/'.$this->cleaned_data['archive']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
158
indefero/src/IDF/Form/UploadArchiveHelper.php
Normal file
158
indefero/src/IDF/Form/UploadArchiveHelper.php
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
class IDF_Form_UploadArchiveHelper
|
||||||
|
{
|
||||||
|
private $file = null;
|
||||||
|
private $entries = array();
|
||||||
|
|
||||||
|
public function __construct($file)
|
||||||
|
{
|
||||||
|
$this->file = $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the archive; throws a invalid form exception in case the
|
||||||
|
* archive contains invalid data or cannot be read.
|
||||||
|
*/
|
||||||
|
public function validate()
|
||||||
|
{
|
||||||
|
if (!file_exists($this->file)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The archive does not exist.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$za = new ZipArchive();
|
||||||
|
$res = $za->open($this->file);
|
||||||
|
if ($res !== true) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The archive could not be read (code %d).'), $res));
|
||||||
|
}
|
||||||
|
|
||||||
|
$manifest = $za->getFromName('manifest.xml');
|
||||||
|
if ($manifest === false) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The archive does not contain a manifest.xml.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
libxml_use_internal_errors(true);
|
||||||
|
$xml = @simplexml_load_string($manifest);
|
||||||
|
if ($xml === false) {
|
||||||
|
$error = libxml_get_last_error();
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The archive\'s manifest is invalid: %s'), $error->message));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (@$xml->file as $idx => $file)
|
||||||
|
{
|
||||||
|
$entry = array(
|
||||||
|
'name' => (string)@$file->name,
|
||||||
|
'summary' => (string)@$file->summary,
|
||||||
|
'description' => (string)@$file->description,
|
||||||
|
'replaces' => (string)@$file->replaces,
|
||||||
|
'labels' => array(),
|
||||||
|
'stream' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($entry['name'])) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The entry %d in the manifest is missing a file name.'), $idx));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($entry['summary'])) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The entry %d in the manifest is missing a summary.'), $idx));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($entry['name'] === 'manifest.xml') {
|
||||||
|
throw new Pluf_Form_Invalid(__('The manifest must not reference itself.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($za->locateName($entry['name']) === false) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The entry %s in the manifest does not exist in the archive.'), $entry['name']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($entry['name'], $this->entries)) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The entry %s in the manifest is referenced more than once.'), $entry['name']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($file->labels) {
|
||||||
|
foreach (@$file->labels->label as $label) {
|
||||||
|
$entry['labels'][] = (string)$label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: remove this once we allow more than six labels everywhere
|
||||||
|
if (count($entry['labels']) > 6) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
sprintf(__('The entry %s in the manifest has more than the six allowed labels set.'), $entry['name']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->entries[$entry['name']] = $entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
$za->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all entry names
|
||||||
|
*
|
||||||
|
* @return array of string
|
||||||
|
*/
|
||||||
|
public function getEntryNames()
|
||||||
|
{
|
||||||
|
return array_keys($this->entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns meta data for the given entry
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getMetaData($name)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($name, $this->entries)) {
|
||||||
|
throw new Exception('unknown file ' . $name);
|
||||||
|
}
|
||||||
|
return $this->entries[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the file entry $name at $path
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $path
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function extract($name, $path)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($name, $this->entries)) {
|
||||||
|
throw new Exception('unknown file ' . $name);
|
||||||
|
}
|
||||||
|
$za = new ZipArchive();
|
||||||
|
$za->open($this->file);
|
||||||
|
$za->extractTo($path, $name);
|
||||||
|
$za->close();
|
||||||
|
}
|
||||||
|
}
|
78
indefero/src/IDF/Form/UploadConf.php
Normal file
78
indefero/src/IDF/Form/UploadConf.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the labels etc. for the uploaded files.
|
||||||
|
*/
|
||||||
|
class IDF_Form_UploadConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Defined as constants to easily access the value in the
|
||||||
|
* form in the case nothing is in the db yet.
|
||||||
|
*/
|
||||||
|
const init_predefined = 'Featured = Listed on project home page
|
||||||
|
Type:Executable = Executable application
|
||||||
|
Type:Installer = Download and run to install application
|
||||||
|
Type:Package = Your OS package manager installs this
|
||||||
|
Type:Archive = Download, unarchive, then follow directions
|
||||||
|
Type:Source = Source code archive
|
||||||
|
Type:Docs = This file contains documentation
|
||||||
|
OpSys:All = Works with all operating systems
|
||||||
|
OpSys:Windows = Works with Windows
|
||||||
|
OpSys:Linux = Works with Linux
|
||||||
|
OpSys:OSX = Works with Mac OS X
|
||||||
|
Deprecated = Most users should NOT download this';
|
||||||
|
|
||||||
|
const init_one_max = 'Type';
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['labels_download_predefined'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Predefined download labels'),
|
||||||
|
'initial' => self::init_predefined,
|
||||||
|
'widget_attrs' => array('rows' => 13,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['labels_download_one_max'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Each download may have at most one label with each of these classes'),
|
||||||
|
'initial' => self::init_one_max,
|
||||||
|
'widget_attrs' => array('size' => 60),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->conf = $extra['conf'];
|
||||||
|
$this->fields['upload_webhook_url'] = new Pluf_Form_Field_Url(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Webhook URL'),
|
||||||
|
'initial' => $this->conf->getVal('upload_webhook_url', ''),
|
||||||
|
'widget_attrs' => array('size' => 60),
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
469
indefero/src/IDF/Form/UserAccount.php
Normal file
469
indefero/src/IDF/Form/UserAccount.php
Normal file
@ -0,0 +1,469 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow a user to update its details.
|
||||||
|
*/
|
||||||
|
class IDF_Form_UserAccount extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$user_data = IDF_UserData::factory($this->user);
|
||||||
|
|
||||||
|
$this->fields['first_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('First name'),
|
||||||
|
'initial' => $this->user->first_name,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['last_name'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Last name'),
|
||||||
|
'initial' => $this->user->last_name,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['email'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your email'),
|
||||||
|
'initial' => $this->user->email,
|
||||||
|
'help_text' => __('If you change your email address, an email will be sent to the new address to confirm it.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['language'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Language'),
|
||||||
|
'initial' => $this->user->language,
|
||||||
|
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'choices' =>
|
||||||
|
Pluf_L10n::getInstalledLanguages()
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['password'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Your password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'help_text' => Pluf_Template::markSafe(__('Leave blank if you do not want to change your password.').'<br />'.__('Your password must be hard for other people to find it, but easy for you to remember.')),
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'autocomplete' => 'off',
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['password2'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Confirm your password'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget' => 'Pluf_Form_Widget_PasswordInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'autocomplete' => 'off',
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['description'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'initial' => $user_data->description,
|
||||||
|
'widget_attrs' => array('rows' => 3,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['twitter'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Twitter username'),
|
||||||
|
'initial' => $user_data->twitter,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['public_email'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Public email address'),
|
||||||
|
'initial' => $user_data->public_email,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['website'] = new Pluf_Form_Field_Url(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Website URL'),
|
||||||
|
'initial' => $user_data->website,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 15,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['custom_avatar'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Upload custom avatar'),
|
||||||
|
'initial' => '',
|
||||||
|
'max_size' => Pluf::f('max_upload_size', 2097152),
|
||||||
|
'move_function_params' => array('upload_path' => Pluf::f('upload_path').'/avatars',
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => true,
|
||||||
|
'file_name' => 'user_'.$this->user->id.'_%s'),
|
||||||
|
'help_text' => __('An image file with a width and height not larger than 60 pixels (bigger images are scaled down).'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['remove_custom_avatar'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Remove custom avatar'),
|
||||||
|
'initial' => false,
|
||||||
|
'widget' => 'Pluf_Form_Widget_CheckboxInput',
|
||||||
|
'widget_attrs' => array(),
|
||||||
|
'help_text' => __('Tick this to delete the custom avatar.'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['public_key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Add a public key'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array('rows' => 3,
|
||||||
|
'cols' => 40),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'help_text' => __('Paste an SSH or monotone public key. Be careful to not provide your private key here!')
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['secondary_mail'] = new Pluf_Form_Field_Email(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Add a secondary email address'),
|
||||||
|
'initial' => '',
|
||||||
|
'help_text' => __('You will get an email to confirm that you own the address you specify.'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function send_validation_mail($new_email, $secondary_mail=false)
|
||||||
|
{
|
||||||
|
if ($secondary_mail) {
|
||||||
|
$type = "secondary";
|
||||||
|
} else {
|
||||||
|
$type = "primary";
|
||||||
|
}
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
$encrypted = trim($cr->encrypt($new_email.':'.$this->user->id.':'.time().':'.$type), '~');
|
||||||
|
$key = substr(md5(Pluf::f('secret_key').$encrypted), 0, 2).$encrypted;
|
||||||
|
$url = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false);
|
||||||
|
$urlik = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false);
|
||||||
|
$context = new Pluf_Template_Context(
|
||||||
|
array('key' => Pluf_Template::markSafe($key),
|
||||||
|
'url' => Pluf_Template::markSafe($url),
|
||||||
|
'urlik' => Pluf_Template::markSafe($urlik),
|
||||||
|
'email' => $new_email,
|
||||||
|
'user'=> $this->user,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/user/changeemail-email.txt');
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
$email = new Pluf_Mail(Pluf::f('from_email'), $new_email,
|
||||||
|
__('Confirm your new email address.'));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->sendMail();
|
||||||
|
$this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
unset($this->cleaned_data['password2']);
|
||||||
|
$update_pass = false;
|
||||||
|
if (strlen($this->cleaned_data['password']) == 0) {
|
||||||
|
unset($this->cleaned_data['password']);
|
||||||
|
} else {
|
||||||
|
$update_pass = true;
|
||||||
|
}
|
||||||
|
$old_email = $this->user->email;
|
||||||
|
$new_email = $this->cleaned_data['email'];
|
||||||
|
unset($this->cleaned_data['email']);
|
||||||
|
if ($old_email != $new_email) {
|
||||||
|
$this->send_validation_mail($new_email);
|
||||||
|
}
|
||||||
|
$this->user->setFromFormData($this->cleaned_data);
|
||||||
|
// Add key as needed.
|
||||||
|
if ('' !== $this->cleaned_data['public_key']) {
|
||||||
|
$key = new IDF_Key();
|
||||||
|
$key->user = $this->user;
|
||||||
|
$key->content = $this->cleaned_data['public_key'];
|
||||||
|
if ($commit) {
|
||||||
|
$key->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('' !== $this->cleaned_data['secondary_mail']) {
|
||||||
|
$this->send_validation_mail($this->cleaned_data['secondary_mail'], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($commit) {
|
||||||
|
$this->user->update();
|
||||||
|
|
||||||
|
// FIXME: go the extra mile and check the input lengths for
|
||||||
|
// all fields here!
|
||||||
|
// FIXME: this is all doubled in admin/UserUpdate!
|
||||||
|
|
||||||
|
$user_data = IDF_UserData::factory($this->user);
|
||||||
|
|
||||||
|
// Add or remove avatar - we need to do this here because every
|
||||||
|
// single setter directly leads to a save in the database
|
||||||
|
if ($user_data->avatar != '' &&
|
||||||
|
($this->cleaned_data['remove_custom_avatar'] == 1 ||
|
||||||
|
$this->cleaned_data['custom_avatar'] != '')) {
|
||||||
|
$avatar_path = Pluf::f('upload_path').'/avatars/'.basename($user_data->avatar);
|
||||||
|
if (basename($avatar_path) != '' && is_file($avatar_path)) {
|
||||||
|
unlink($avatar_path);
|
||||||
|
}
|
||||||
|
$user_data->avatar = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->cleaned_data['custom_avatar'] != '') {
|
||||||
|
$user_data->avatar = $this->cleaned_data['custom_avatar'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_data->description = $this->cleaned_data['description'];
|
||||||
|
$user_data->twitter = $this->cleaned_data['twitter'];
|
||||||
|
$user_data->public_email = $this->cleaned_data['public_email'];
|
||||||
|
$user_data->website = $this->cleaned_data['website'];
|
||||||
|
|
||||||
|
if ($update_pass) {
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* Pluf_User::passwordUpdated
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Form_UserAccount
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal is sent when the user updated his
|
||||||
|
* password from his account page.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('user' => $user)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('user' => $this->user);
|
||||||
|
Pluf_Signal::send('Pluf_User::passwordUpdated',
|
||||||
|
'IDF_Form_UserAccount', $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check arbitrary public keys.
|
||||||
|
*
|
||||||
|
* It will throw a Pluf_Form_Invalid exception if it cannot
|
||||||
|
* validate the key.
|
||||||
|
*
|
||||||
|
* @param $key string The key
|
||||||
|
* @param $user int The user id of the user of the key (0)
|
||||||
|
* @return string The clean key
|
||||||
|
*/
|
||||||
|
public static function checkPublicKey($key, $user=0)
|
||||||
|
{
|
||||||
|
$key = trim($key);
|
||||||
|
if (strlen($key) == 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$keysearch = '';
|
||||||
|
if (preg_match('#^(ssh\-(?:dss|rsa)\s+\S+)(.*)#', $key, $m)) {
|
||||||
|
$basekey = preg_replace('/\s+/', ' ', $m[1]);
|
||||||
|
$comment = trim(preg_replace('/[\r\n]/', ' ', $m[2]));
|
||||||
|
|
||||||
|
$keysearch = $basekey.'%';
|
||||||
|
$key = $basekey;
|
||||||
|
if (!empty($comment))
|
||||||
|
$key .= ' '.$comment;
|
||||||
|
|
||||||
|
if (Pluf::f('idf_strong_key_check', false)) {
|
||||||
|
|
||||||
|
$tmpfile = Pluf::f('tmp_folder', '/tmp').'/'.$user.'-key';
|
||||||
|
file_put_contents($tmpfile, $key, LOCK_EX);
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').
|
||||||
|
'ssh-keygen -l -f '.escapeshellarg($tmpfile).' > /dev/null 2>&1';
|
||||||
|
exec($cmd, $out, $return);
|
||||||
|
unlink($tmpfile);
|
||||||
|
|
||||||
|
if ($return != 0) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
__('Please check the key as it does not appear '.
|
||||||
|
'to be a valid SSH public key.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (preg_match('#^\[pubkey [^\]]+\]\s*(\S+)\s*\[end\]$#', $key, $m)) {
|
||||||
|
$keysearch = '%'.$m[1].'%';
|
||||||
|
|
||||||
|
if (Pluf::f('idf_strong_key_check', false)) {
|
||||||
|
|
||||||
|
// if monotone can read it, it should be valid
|
||||||
|
$mtn_opts = implode(' ', Pluf::f('mtn_opts', array()));
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').
|
||||||
|
sprintf('%s %s -d :memory: read >/tmp/php-out 2>&1',
|
||||||
|
Pluf::f('mtn_path', 'mtn'), $mtn_opts);
|
||||||
|
$fp = popen($cmd, 'w');
|
||||||
|
fwrite($fp, $key);
|
||||||
|
$return = pclose($fp);
|
||||||
|
|
||||||
|
if ($return != 0) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
__('Please check the key as it does not appear '.
|
||||||
|
'to be a valid monotone public key.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
__('Public key looks like neither an SSH '.
|
||||||
|
'nor monotone public key.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If $user, then check if not the same key stored
|
||||||
|
if ($user) {
|
||||||
|
$ruser = Pluf::factory('Pluf_User', $user);
|
||||||
|
if ($ruser->id > 0) {
|
||||||
|
$sql = new Pluf_SQL('content LIKE %s AND user=%s', array($keysearch, $ruser->id));
|
||||||
|
$keys = Pluf::factory('IDF_Key')->getList(array('filter' => $sql->gen()));
|
||||||
|
if (count($keys) > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(
|
||||||
|
__('You already have uploaded this key.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function clean_custom_avatar()
|
||||||
|
{
|
||||||
|
// Just png, jpeg/jpg or gif
|
||||||
|
if (!preg_match('/\.(png|jpg|jpeg|gif)$/i', $this->cleaned_data['custom_avatar']) &&
|
||||||
|
$this->cleaned_data['custom_avatar'] != '') {
|
||||||
|
@unlink(Pluf::f('upload_path').'/avatars/'.$this->cleaned_data['custom_avatar']);
|
||||||
|
throw new Pluf_Form_Invalid(__('For security reason, you cannot upload a file with this extension.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['custom_avatar'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function clean_last_name()
|
||||||
|
{
|
||||||
|
$last_name = trim($this->cleaned_data['last_name']);
|
||||||
|
if ($last_name == mb_strtoupper($last_name)) {
|
||||||
|
return mb_convert_case(mb_strtolower($last_name),
|
||||||
|
MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
return $last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_first_name()
|
||||||
|
{
|
||||||
|
$first_name = trim($this->cleaned_data['first_name']);
|
||||||
|
if ($first_name == mb_strtoupper($first_name)) {
|
||||||
|
return mb_convert_case(mb_strtolower($first_name),
|
||||||
|
MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
return $first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_email()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['email'] = mb_strtolower(trim($this->cleaned_data['email']));
|
||||||
|
$user = Pluf::factory('IDF_EmailAddress')->get_user_for_email_address($this->cleaned_data['email']);
|
||||||
|
if ($user != null and $user->id != $this->user->id) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The email "%s" is already used.'), $this->cleaned_data['email']));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_secondary_mail()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['secondary_mail'] = mb_strtolower(trim($this->cleaned_data['secondary_mail']));
|
||||||
|
if (Pluf::factory('IDF_EmailAddress')->get_user_for_email_address($this->cleaned_data['secondary_mail']) != null) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(__('The email "%s" is already used.'), $this->cleaned_data['secondary_mail']));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['secondary_mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_public_key()
|
||||||
|
{
|
||||||
|
$this->cleaned_data['public_key'] =
|
||||||
|
self::checkPublicKey($this->cleaned_data['public_key'],
|
||||||
|
$this->user->id);
|
||||||
|
return $this->cleaned_data['public_key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the 2 passwords are the same
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if (!isset($this->errors['password'])
|
||||||
|
&& !isset($this->errors['password2'])) {
|
||||||
|
$password1 = $this->cleaned_data['password'];
|
||||||
|
$password2 = $this->cleaned_data['password2'];
|
||||||
|
if ($password1 != $password2) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The passwords do not match. Please give them again.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
84
indefero/src/IDF/Form/UserChangeEmail.php
Normal file
84
indefero/src/IDF/Form/UserChangeEmail.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the email address of a user.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_UserChangeEmail extends Pluf_Form
|
||||||
|
{
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['key'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Your verification key'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'size' => 50,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_key()
|
||||||
|
{
|
||||||
|
self::validateKey($this->cleaned_data['key']);
|
||||||
|
return $this->cleaned_data['key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the key.
|
||||||
|
*
|
||||||
|
* Throw a Pluf_Form_Invalid exception if the key is not valid.
|
||||||
|
*
|
||||||
|
* @param string Key
|
||||||
|
* @return array array($new_email, $user_id, time(), [primary|secondary])
|
||||||
|
*/
|
||||||
|
public static function validateKey($key)
|
||||||
|
{
|
||||||
|
$hash = substr($key, 0, 2);
|
||||||
|
$encrypted = substr($key, 2);
|
||||||
|
if ($hash != substr(md5(Pluf::f('secret_key').$encrypted), 0, 2)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The validation key is not valid. Please copy/paste it from your confirmation email.'));
|
||||||
|
}
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
return explode(':', $cr->decrypt($encrypted), 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
return Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($this->cleaned_data['key']));
|
||||||
|
}
|
||||||
|
}
|
66
indefero/src/IDF/Form/WikiConf.php
Normal file
66
indefero/src/IDF/Form/WikiConf.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the labels etc. for the wiki pages.
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiConf extends Pluf_Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Defined as constants to easily access the value in the
|
||||||
|
* form in the case nothing is in the db yet.
|
||||||
|
*/
|
||||||
|
const init_predefined = 'Featured = Listed on project home page
|
||||||
|
Phase:Requirements = Project vision and requirements
|
||||||
|
Phase:Design = Project design and key concerns
|
||||||
|
Phase:Implementation = Developers\' guide
|
||||||
|
Phase:QA = Testing plans and QA strategies
|
||||||
|
Phase:Deploy = How to install and configure the program
|
||||||
|
Phase:Support = Plans for user support and advocacy
|
||||||
|
Deprecated = Most users should NOT reference this';
|
||||||
|
|
||||||
|
const init_one_max = '';
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->fields['labels_wiki_predefined'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Predefined documentation page labels'),
|
||||||
|
'initial' => self::init_predefined,
|
||||||
|
'widget_attrs' => array('rows' => 13,
|
||||||
|
'cols' => 75),
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['labels_wiki_one_max'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Each documentation page may have at most one label with each of these classes'),
|
||||||
|
'initial' => self::init_one_max,
|
||||||
|
'widget_attrs' => array('size' => 60),
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
205
indefero/src/IDF/Form/WikiPageCreate.php
Normal file
205
indefero/src/IDF/Form/WikiPageCreate.php
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new documentation page.
|
||||||
|
*
|
||||||
|
* This create a new page and the corresponding revision.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiPageCreate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $show_full = false;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$initial = __('# Introduction
|
||||||
|
|
||||||
|
Add your content here.
|
||||||
|
|
||||||
|
|
||||||
|
# Details
|
||||||
|
|
||||||
|
Add your content here. Format your content with:
|
||||||
|
|
||||||
|
* Text in **bold** or *italic*.
|
||||||
|
* Headings, paragraphs, and lists.
|
||||||
|
* Links to other [[WikiPage]].
|
||||||
|
');
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||||
|
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||||
|
$this->show_full = true;
|
||||||
|
}
|
||||||
|
$initname = (!empty($extra['name'])) ? $extra['name'] : __('PageName');
|
||||||
|
$this->fields['title'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Page title'),
|
||||||
|
'initial' => $initname,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
'help_text' => __('The page name must contains only letters, digits and the dash (-) character.'),
|
||||||
|
));
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'help_text' => __('This one line description is displayed in the list of pages.'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Content'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 68,
|
||||||
|
'rows' => 26,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->show_full) {
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_title()
|
||||||
|
{
|
||||||
|
$title = $this->cleaned_data['title'];
|
||||||
|
if (preg_match('/[^a-zA-Z0-9\-]/', $title)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The title contains invalid characters.'));
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('project=%s AND title=%s',
|
||||||
|
array($this->project->id, $title));
|
||||||
|
$pages = Pluf::factory('IDF_Wiki_Page')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($pages->count() > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('A page with this title already exists.'));
|
||||||
|
}
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if (!$this->show_full) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($this->project);
|
||||||
|
$onemax = array();
|
||||||
|
foreach (explode(',', $conf->getVal('labels_wiki_one_max', IDF_Form_WikiConf::init_one_max)) as $class) {
|
||||||
|
if (trim($class) != '') {
|
||||||
|
$onemax[] = mb_strtolower(trim($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count = array();
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
$this->cleaned_data['label'.$i] = trim($this->cleaned_data['label'.$i]);
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||||
|
trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'other';
|
||||||
|
$name = $this->cleaned_data['label'.$i];
|
||||||
|
}
|
||||||
|
if (!isset($count[$class])) $count[$class] = 1;
|
||||||
|
else $count[$class] += 1;
|
||||||
|
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||||
|
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||||
|
$this->errors['label'.$i][] = sprintf(__('You cannot provide more than one label from the %s class to a page.'), $class);
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
// Add a tag for each label
|
||||||
|
$tags = array();
|
||||||
|
if ($this->show_full) {
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tags[] = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Create the page
|
||||||
|
$page = new IDF_Wiki_Page();
|
||||||
|
$page->project = $this->project;
|
||||||
|
$page->submitter = $this->user;
|
||||||
|
$page->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$page->title = trim($this->cleaned_data['title']);
|
||||||
|
$page->create();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$page->setAssoc($tag);
|
||||||
|
}
|
||||||
|
// add the first revision
|
||||||
|
$rev = new IDF_Wiki_PageRevision();
|
||||||
|
$rev->wikipage = $page;
|
||||||
|
$rev->content = $this->cleaned_data['content'];
|
||||||
|
$rev->submitter = $this->user;
|
||||||
|
$rev->summary = __('Initial page creation');
|
||||||
|
$rev->create();
|
||||||
|
$rev->notify($this->project->getConf());
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
}
|
64
indefero/src/IDF/Form/WikiPageDelete.php
Normal file
64
indefero/src/IDF/Form/WikiPageDelete.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a documentation page.
|
||||||
|
*
|
||||||
|
* This is a hard delete of the page and the revisions.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiPageDelete extends Pluf_Form
|
||||||
|
{
|
||||||
|
protected $page = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->page = $extra['page'];
|
||||||
|
$this->fields['confirm'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Yes, I understand that the page and all its revisions will be deleted.'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the confirmation.
|
||||||
|
*/
|
||||||
|
public function clean_confirm()
|
||||||
|
{
|
||||||
|
if (!$this->cleaned_data['confirm']) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You need to confirm the deletion.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['confirm'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
$this->page->delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
242
indefero/src/IDF/Form/WikiPageUpdate.php
Normal file
242
indefero/src/IDF/Form/WikiPageUpdate.php
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a documentation page.
|
||||||
|
*
|
||||||
|
* This add a corresponding revision.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiPageUpdate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $page = null;
|
||||||
|
public $show_full = false;
|
||||||
|
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->page = $extra['page'];
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
if ($this->user->hasPerm('IDF.project-owner', $this->project)
|
||||||
|
or $this->user->hasPerm('IDF.project-member', $this->project)) {
|
||||||
|
$this->show_full = true;
|
||||||
|
}
|
||||||
|
if ($this->show_full) {
|
||||||
|
$this->fields['title'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Page title'),
|
||||||
|
'initial' => $this->page->title,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
'help_text' => __('The page name must contains only letters, digits and the dash (-) character.'),
|
||||||
|
));
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'help_text' => __('This one line description is displayed in the list of pages.'),
|
||||||
|
'initial' => $this->page->summary,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$rev = $this->page->get_current_revision();
|
||||||
|
$this->fields['content'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Content'),
|
||||||
|
'initial' => $rev->content,
|
||||||
|
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'cols' => 68,
|
||||||
|
'rows' => 26,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['comment'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Comment'),
|
||||||
|
'help_text' => __('One line to describe the changes you made.'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->show_full) {
|
||||||
|
$tags = $this->page->get_tags_list();
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
$initial = '';
|
||||||
|
if (isset($tags[$i-1])) {
|
||||||
|
if ($tags[$i-1]->class != 'Other') {
|
||||||
|
$initial = (string) $tags[$i-1];
|
||||||
|
} else {
|
||||||
|
$initial = $tags[$i-1]->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->fields['label'.$i] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => false,
|
||||||
|
'label' => __('Labels'),
|
||||||
|
'initial' => $initial,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 50,
|
||||||
|
'size' => 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_title()
|
||||||
|
{
|
||||||
|
$title = $this->cleaned_data['title'];
|
||||||
|
if (preg_match('/[^a-zA-Z0-9\-]/', $title)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The title contains invalid characters.'));
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('project=%s AND title=%s',
|
||||||
|
array($this->project->id, $title));
|
||||||
|
$pages = Pluf::factory('IDF_Wiki_Page')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($pages->count() > 0 and $pages[0]->id != $this->page->id) {
|
||||||
|
throw new Pluf_Form_Invalid(__('A page with this title already exists.'));
|
||||||
|
}
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the interconnection in the form.
|
||||||
|
*/
|
||||||
|
public function clean()
|
||||||
|
{
|
||||||
|
if (!$this->show_full) {
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($this->project);
|
||||||
|
$onemax = array();
|
||||||
|
foreach (explode(',', $conf->getVal('labels_wiki_one_max', IDF_Form_WikiConf::init_one_max)) as $class) {
|
||||||
|
if (trim($class) != '') {
|
||||||
|
$onemax[] = mb_strtolower(trim($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count = array();
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
$this->cleaned_data['label'.$i] = trim($this->cleaned_data['label'.$i]);
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(mb_strtolower(trim($class)),
|
||||||
|
trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'other';
|
||||||
|
$name = $this->cleaned_data['label'.$i];
|
||||||
|
}
|
||||||
|
if (!isset($count[$class])) $count[$class] = 1;
|
||||||
|
else $count[$class] += 1;
|
||||||
|
if (in_array($class, $onemax) and $count[$class] > 1) {
|
||||||
|
if (!isset($this->errors['label'.$i])) $this->errors['label'.$i] = array();
|
||||||
|
$this->errors['label'.$i][] = sprintf(__('You cannot provide more than one label from the %s class to a page.'), $class);
|
||||||
|
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->cleaned_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
if ($this->show_full) {
|
||||||
|
$tagids = array();
|
||||||
|
$tags = array();
|
||||||
|
for ($i=1;$i<4;$i++) {
|
||||||
|
if (strlen($this->cleaned_data['label'.$i]) > 0) {
|
||||||
|
if (strpos($this->cleaned_data['label'.$i], ':') !== false) {
|
||||||
|
list($class, $name) = explode(':', $this->cleaned_data['label'.$i], 2);
|
||||||
|
list($class, $name) = array(trim($class), trim($name));
|
||||||
|
} else {
|
||||||
|
$class = 'Other';
|
||||||
|
$name = trim($this->cleaned_data['label'.$i]);
|
||||||
|
}
|
||||||
|
$tag = IDF_Tag::add($name, $this->project, $class);
|
||||||
|
$tags[] = $tag;
|
||||||
|
$tagids[] = $tag->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Compare between the old and the new data
|
||||||
|
$changes = array();
|
||||||
|
$oldtags = $this->page->get_tags_list();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if (!Pluf_Model_InArray($tag, $oldtags)) {
|
||||||
|
if (!isset($changes['lb'])) $changes['lb'] = array();
|
||||||
|
if ($tag->class != 'Other') {
|
||||||
|
$changes['lb'][] = (string) $tag; //new tag
|
||||||
|
} else {
|
||||||
|
$changes['lb'][] = (string) $tag->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($oldtags as $tag) {
|
||||||
|
if (!Pluf_Model_InArray($tag, $tags)) {
|
||||||
|
if (!isset($changes['lb'])) $changes['lb'] = array();
|
||||||
|
if ($tag->class != 'Other') {
|
||||||
|
$changes['lb'][] = '-'.(string) $tag; //new tag
|
||||||
|
} else {
|
||||||
|
$changes['lb'][] = '-'.(string) $tag->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (trim($this->page->summary) != trim($this->cleaned_data['summary'])) {
|
||||||
|
$changes['su'] = trim($this->cleaned_data['summary']);
|
||||||
|
}
|
||||||
|
// Update the page
|
||||||
|
$this->page->batchAssoc('IDF_Tag', $tagids);
|
||||||
|
$this->page->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$this->page->title = trim($this->cleaned_data['title']);
|
||||||
|
} else {
|
||||||
|
$changes = array();
|
||||||
|
}
|
||||||
|
$this->page->update();
|
||||||
|
// add the new revision
|
||||||
|
$rev = new IDF_Wiki_PageRevision();
|
||||||
|
$rev->wikipage = $this->page;
|
||||||
|
$rev->content = $this->cleaned_data['content'];
|
||||||
|
$rev->submitter = $this->user;
|
||||||
|
$rev->summary = $this->cleaned_data['comment'];
|
||||||
|
$rev->changes = $changes;
|
||||||
|
$rev->create();
|
||||||
|
$rev->notify($this->project->getConf(), false);
|
||||||
|
return $this->page;
|
||||||
|
}
|
||||||
|
}
|
169
indefero/src/IDF/Form/WikiResourceCreate.php
Normal file
169
indefero/src/IDF/Form/WikiResourceCreate.php
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new resource.
|
||||||
|
*
|
||||||
|
* This create a new resource and the corresponding revision.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiResourceCreate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $show_full = false;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$initname = (!empty($extra['name'])) ? $extra['name'] : __('ResourceName');
|
||||||
|
|
||||||
|
$this->fields['title'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Resource title'),
|
||||||
|
'initial' => $initname,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
'help_text' => __('The resource name must contains only letters, digits and the dash (-) character.'),
|
||||||
|
));
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'help_text' => __('This one line description is displayed in the list of resources.'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['file'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('File'),
|
||||||
|
'initial' => '',
|
||||||
|
'max_size' => Pluf::f('max_upload_size', 2097152),
|
||||||
|
'move_function_params' => array('upload_path' => $this->getTempUploadPath(),
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => true),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_title()
|
||||||
|
{
|
||||||
|
$title = $this->cleaned_data['title'];
|
||||||
|
if (preg_match('/[^a-zA-Z0-9\-]/', $title)) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The title contains invalid characters.'));
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('project=%s AND title=%s',
|
||||||
|
array($this->project->id, $title));
|
||||||
|
$resources = Pluf::factory('IDF_Wiki_Resource')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($resources->count() > 0) {
|
||||||
|
throw new Pluf_Form_Invalid(__('A resource with this title already exists.'));
|
||||||
|
}
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_file()
|
||||||
|
{
|
||||||
|
// FIXME: we do the same in IDF_Form_Upload and a couple of other places as well
|
||||||
|
$extra = strtolower(implode('|', explode(' ', Pluf::f('idf_extra_upload_ext'))));
|
||||||
|
if (strlen($extra)) $extra .= '|';
|
||||||
|
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $this->cleaned_data['file'])) {
|
||||||
|
@unlink($this->getTempUploadPath().$this->cleaned_data['file']);
|
||||||
|
throw new Pluf_Form_Invalid(__('For security reasons, you cannot upload a file with this extension.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['file'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we have uploaded a file, but the form failed remove it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
if (!empty($this->cleaned_data['file'])
|
||||||
|
and file_exists($this->getTempUploadPath().$this->cleaned_data['file'])) {
|
||||||
|
@unlink($this->getTempUploadPath().$this->cleaned_data['file']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tempFile = $this->getTempUploadPath().$this->cleaned_data['file'];
|
||||||
|
list($mimeType, , $extension) = IDF_FileUtil::getMimeType($tempFile);
|
||||||
|
|
||||||
|
// create the resource
|
||||||
|
$resource = new IDF_Wiki_Resource();
|
||||||
|
$resource->project = $this->project;
|
||||||
|
$resource->submitter = $this->user;
|
||||||
|
$resource->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$resource->title = trim($this->cleaned_data['title']);
|
||||||
|
$resource->mime_type = $mimeType;
|
||||||
|
$resource->create();
|
||||||
|
|
||||||
|
// add the first revision
|
||||||
|
$rev = new IDF_Wiki_ResourceRevision();
|
||||||
|
$rev->wikiresource = $resource;
|
||||||
|
$rev->submitter = $this->user;
|
||||||
|
$rev->summary = __('Initial resource creation');
|
||||||
|
$rev->filesize = filesize($tempFile);
|
||||||
|
$rev->fileext = $extension;
|
||||||
|
$rev->create();
|
||||||
|
|
||||||
|
$finalFile = $rev->getFilePath();
|
||||||
|
if (!@mkdir(dirname($finalFile), 0755, true)) {
|
||||||
|
@unlink($tempFile);
|
||||||
|
$rev->delete();
|
||||||
|
$resource->delete();
|
||||||
|
throw new Exception('could not create final resource path');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!@rename($tempFile, $finalFile)) {
|
||||||
|
@unlink($tempFile);
|
||||||
|
$rev->delete();
|
||||||
|
$resource->delete();
|
||||||
|
throw new Exception('could not move resource to final location');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTempUploadPath()
|
||||||
|
{
|
||||||
|
return Pluf::f('upload_path').'/'.$this->project->shortname.'/wiki/temp/';
|
||||||
|
}
|
||||||
|
}
|
64
indefero/src/IDF/Form/WikiResourceDelete.php
Normal file
64
indefero/src/IDF/Form/WikiResourceDelete.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a documentation page.
|
||||||
|
*
|
||||||
|
* This is a hard delete of the page and the revisions.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiResourceDelete extends Pluf_Form
|
||||||
|
{
|
||||||
|
protected $resource = null;
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->resource = $extra['resource'];
|
||||||
|
$this->fields['confirm'] = new Pluf_Form_Field_Boolean(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Yes, I understand that the resource and all its revisions will be deleted.'),
|
||||||
|
'initial' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the confirmation.
|
||||||
|
*/
|
||||||
|
public function clean_confirm()
|
||||||
|
{
|
||||||
|
if (!$this->cleaned_data['confirm']) {
|
||||||
|
throw new Pluf_Form_Invalid(__('You need to confirm the deletion.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['confirm'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
$this->resource->delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
161
indefero/src/IDF/Form/WikiResourceUpdate.php
Normal file
161
indefero/src/IDF/Form/WikiResourceUpdate.php
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a documentation page.
|
||||||
|
*
|
||||||
|
* This add a corresponding revision.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Form_WikiResourceUpdate extends Pluf_Form
|
||||||
|
{
|
||||||
|
public $user = null;
|
||||||
|
public $project = null;
|
||||||
|
public $page = null;
|
||||||
|
public $show_full = false;
|
||||||
|
|
||||||
|
|
||||||
|
public function initFields($extra=array())
|
||||||
|
{
|
||||||
|
$this->resource = $extra['resource'];
|
||||||
|
$this->user = $extra['user'];
|
||||||
|
$this->project = $extra['project'];
|
||||||
|
|
||||||
|
$this->fields['summary'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Description'),
|
||||||
|
'help_text' => __('This one line description is displayed in the list of resources.'),
|
||||||
|
'initial' => $this->resource->summary,
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->fields['file'] = new Pluf_Form_Field_File(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('File'),
|
||||||
|
'initial' => '',
|
||||||
|
'max_size' => Pluf::f('max_upload_size', 2097152),
|
||||||
|
'move_function_params' => array('upload_path' => $this->getTempUploadPath(),
|
||||||
|
'upload_path_create' => true,
|
||||||
|
'upload_overwrite' => true),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->fields['comment'] = new Pluf_Form_Field_Varchar(
|
||||||
|
array('required' => true,
|
||||||
|
'label' => __('Comment'),
|
||||||
|
'help_text' => __('One line to describe the changes you made.'),
|
||||||
|
'initial' => '',
|
||||||
|
'widget_attrs' => array(
|
||||||
|
'maxlength' => 200,
|
||||||
|
'size' => 67,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean_file()
|
||||||
|
{
|
||||||
|
// FIXME: we do the same in IDF_Form_Upload and a couple of other places as well
|
||||||
|
$extra = strtolower(implode('|', explode(' ', Pluf::f('idf_extra_upload_ext'))));
|
||||||
|
if (strlen($extra)) $extra .= '|';
|
||||||
|
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $this->cleaned_data['file'])) {
|
||||||
|
@unlink($this->getTempUploadPath().$this->cleaned_data['file']);
|
||||||
|
throw new Pluf_Form_Invalid(__('For security reasons, you cannot upload a file with this extension.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
list($mimeType, , $extension) = IDF_FileUtil::getMimeType($this->getTempUploadPath().$this->cleaned_data['file']);
|
||||||
|
if ($this->resource->mime_type != $mimeType) {
|
||||||
|
throw new Pluf_Form_Invalid(sprintf(
|
||||||
|
__('The mime type of the uploaded file "%1$s" does not match the mime type of this resource "%2$s"'),
|
||||||
|
$mimeType, $this->resource->mime_type
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$this->cleaned_data['fileext'] = $extension;
|
||||||
|
|
||||||
|
if (md5_file($this->getTempUploadPath().$this->cleaned_data['file']) ===
|
||||||
|
md5_file($this->resource->get_current_revision()->getFilePath())) {
|
||||||
|
throw new Pluf_Form_Invalid(__('The current version of the resource and the uploaded file are equal.'));
|
||||||
|
}
|
||||||
|
return $this->cleaned_data['file'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we have uploaded a file, but the form failed remove it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function failed()
|
||||||
|
{
|
||||||
|
if (!empty($this->cleaned_data['file'])
|
||||||
|
and file_exists($this->getTempUploadPath().$this->cleaned_data['file'])) {
|
||||||
|
@unlink($this->getTempUploadPath().$this->cleaned_data['file']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the model in the database.
|
||||||
|
*
|
||||||
|
* @param bool Commit in the database or not. If not, the object
|
||||||
|
* is returned but not saved in the database.
|
||||||
|
* @return Object Model with data set from the form.
|
||||||
|
*/
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tempFile = $this->getTempUploadPath().$this->cleaned_data['file'];
|
||||||
|
|
||||||
|
$this->resource->summary = trim($this->cleaned_data['summary']);
|
||||||
|
$this->resource->update();
|
||||||
|
|
||||||
|
// add the new revision
|
||||||
|
$rev = new IDF_Wiki_ResourceRevision();
|
||||||
|
$rev->wikiresource = $this->resource;
|
||||||
|
$rev->submitter = $this->user;
|
||||||
|
$rev->summary = $this->cleaned_data['comment'];
|
||||||
|
$rev->filesize = filesize($tempFile);
|
||||||
|
$rev->fileext = $this->cleaned_data['fileext'];
|
||||||
|
$rev->create();
|
||||||
|
|
||||||
|
$finalFile = $rev->getFilePath();
|
||||||
|
if (!is_dir(dirname($finalFile))) {
|
||||||
|
@unlink($tempFile);
|
||||||
|
$rev->delete();
|
||||||
|
throw new Exception('resource path does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!@rename($tempFile, $finalFile)) {
|
||||||
|
@unlink($tempFile);
|
||||||
|
$rev->delete();
|
||||||
|
throw new Exception('could not move resource to final location');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTempUploadPath()
|
||||||
|
{
|
||||||
|
return Pluf::f('upload_path').'/'.$this->project->shortname.'/wiki/temp/';
|
||||||
|
}
|
||||||
|
}
|
210
indefero/src/IDF/Gconf.php
Normal file
210
indefero/src/IDF/Gconf.php
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of the objects.
|
||||||
|
*
|
||||||
|
* It is just storing a list of key/value pairs associated to
|
||||||
|
* different objects. If you use this table for your model, do not
|
||||||
|
* forget to drop the corresponding keys in your preDelete call.
|
||||||
|
*/
|
||||||
|
class IDF_Gconf extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
public $datacache = null;
|
||||||
|
public $dirty = array();
|
||||||
|
public $f = null;
|
||||||
|
protected $_mod = null;
|
||||||
|
/**
|
||||||
|
* Do we (un)serialize the data when getting/setting them.
|
||||||
|
*/
|
||||||
|
public $serialize = false;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_gconf';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
//It is automatically added.
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'model_class' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 150,
|
||||||
|
'verbose' => __('model class'),
|
||||||
|
),
|
||||||
|
'model_id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('model id'),
|
||||||
|
),
|
||||||
|
'vkey' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 50,
|
||||||
|
'verbose' => __('key'),
|
||||||
|
),
|
||||||
|
'vdesc' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('value'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->_a['idx'] = array('model_vkey_idx' =>
|
||||||
|
array(
|
||||||
|
'col' => 'model_class, model_id, vkey',
|
||||||
|
'type' => 'unique',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->f = new IDF_Config_DataProxy($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setModel($model)
|
||||||
|
{
|
||||||
|
$this->datacache = null;
|
||||||
|
$this->_mod = $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initCache()
|
||||||
|
{
|
||||||
|
$this->datacache = array();
|
||||||
|
$this->dirty = array();
|
||||||
|
$sql = new Pluf_SQL('model_class=%s AND model_id=%s',
|
||||||
|
array($this->_mod->_model, $this->_mod->id));
|
||||||
|
foreach ($this->getList(array('filter' => $sql->gen())) as $val) {
|
||||||
|
$this->datacache[$val->vkey] = ($this->serialize) ? unserialize($val->vdesc) : $val->vdesc;
|
||||||
|
$this->dirty[$val->vkey] = $val->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME: This is not efficient when setting a large number of
|
||||||
|
* values in a loop.
|
||||||
|
*/
|
||||||
|
function setVal($key, $value)
|
||||||
|
{
|
||||||
|
if (!is_null($this->getVal($key, null))
|
||||||
|
and $value == $this->getVal($key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$svalue = ($this->serialize) ? serialize($value) : $value;
|
||||||
|
if (isset($this->dirty[$key])) {
|
||||||
|
// we get to check if deleted by other process + update
|
||||||
|
$conf = new IDF_Gconf($this->dirty[$key]);
|
||||||
|
if ($conf->id == $this->dirty[$key]) {
|
||||||
|
$conf->vdesc = $svalue;
|
||||||
|
$conf->update();
|
||||||
|
$this->datacache[$key] = $value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// we insert
|
||||||
|
$conf = new IDF_Gconf();
|
||||||
|
$conf->model_class = $this->_mod->_model;
|
||||||
|
$conf->model_id = $this->_mod->id;
|
||||||
|
$conf->vkey = $key;
|
||||||
|
$conf->vdesc = $svalue;
|
||||||
|
$conf->create();
|
||||||
|
$this->datacache[$key] = $value;
|
||||||
|
$this->dirty[$key] = $conf->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVal($key, $default='')
|
||||||
|
{
|
||||||
|
if ($this->datacache === null) {
|
||||||
|
$this->initCache();
|
||||||
|
}
|
||||||
|
return (isset($this->datacache[$key])) ? $this->datacache[$key] : $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
function delVal($key, $initcache=true)
|
||||||
|
{
|
||||||
|
$gconf = new IDF_Gconf();
|
||||||
|
$sql = new Pluf_SQL('vkey=%s AND model_class=%s AND model_id=%s', array($key, $this->_mod->_model, $this->_mod->id));
|
||||||
|
foreach ($gconf->getList(array('filter' => $sql->gen())) as $c) {
|
||||||
|
$c->delete();
|
||||||
|
}
|
||||||
|
if ($initcache) {
|
||||||
|
$this->initCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection selection.
|
||||||
|
*
|
||||||
|
* Suppose you have 5 objects with associated meta data in the
|
||||||
|
* Gconf storage, if you load the data independently for each
|
||||||
|
* object, you end up with 5 SELECT queries. With 25 objects, 25
|
||||||
|
* SELECT. You can select with one query all the data and merge in
|
||||||
|
* the code. It is faster. The collection selection get a
|
||||||
|
* model_class and a list of ids and returns an id indexed array
|
||||||
|
* of associative array data. This is for read only access as you
|
||||||
|
* do not get a series of Gconf objects.
|
||||||
|
*/
|
||||||
|
public static function collect($class, $ids)
|
||||||
|
{
|
||||||
|
$gconf = new IDF_Gconf();
|
||||||
|
$stmpl = sprintf('model_class=%%s AND model_id IN (%s)',
|
||||||
|
implode(',' , $ids));
|
||||||
|
$sql = new Pluf_SQL($stmpl, array($class));
|
||||||
|
$out = array_fill_keys($ids, array());
|
||||||
|
foreach ($gconf->getList(array('filter' => $sql->gen())) as $c) {
|
||||||
|
$out[$c->model_id][$c->vkey] = $c->vdesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop the conf of a model.
|
||||||
|
*
|
||||||
|
* If your model is using this table, just add the following line
|
||||||
|
* in your preDelete() method:
|
||||||
|
*
|
||||||
|
* IDF_Gconf::dropForModel($this)
|
||||||
|
*
|
||||||
|
* It will take care of the cleaning.
|
||||||
|
*/
|
||||||
|
static public function dropForModel($model)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory(__CLASS__)->getSqlTable();
|
||||||
|
$sql = new Pluf_SQL('model_class=%s AND model_id=%s',
|
||||||
|
array($model->_model, $model->id));
|
||||||
|
$db = &Pluf::db();
|
||||||
|
$db->execute('DELETE FROM '.$table.' WHERE '.$sql->gen());
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function dropUser($signal, &$params)
|
||||||
|
{
|
||||||
|
self::dropForModel($params['user']);
|
||||||
|
}
|
||||||
|
}
|
327
indefero/src/IDF/Issue.php
Normal file
327
indefero/src/IDF/Issue.php
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
Pluf::loadFunction('Pluf_Template_dateAgo');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base definition of an issue.
|
||||||
|
*
|
||||||
|
* An issue can have labels, comments, can be starred by people.
|
||||||
|
*/
|
||||||
|
class IDF_Issue extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_issues';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'project' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Project',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('project'),
|
||||||
|
'relate_name' => 'issues',
|
||||||
|
),
|
||||||
|
'summary' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'verbose' => __('summary'),
|
||||||
|
),
|
||||||
|
'submitter' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
'relate_name' => 'submitted_issue',
|
||||||
|
),
|
||||||
|
'owner' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => true, // no owner when submitted.
|
||||||
|
'is_null' => true,
|
||||||
|
'verbose' => __('owner'),
|
||||||
|
'relate_name' => 'owned_issue',
|
||||||
|
),
|
||||||
|
'interested' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Manytomany',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('interested users'),
|
||||||
|
'help_text' => __('Interested users will get an email notification when the issue is changed.'),
|
||||||
|
),
|
||||||
|
'tags' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Manytomany',
|
||||||
|
'blank' => true,
|
||||||
|
'model' => 'IDF_Tag',
|
||||||
|
'verbose' => __('labels'),
|
||||||
|
),
|
||||||
|
'status' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'blank' => false,
|
||||||
|
'model' => 'IDF_Tag',
|
||||||
|
'verbose' => __('status'),
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
),
|
||||||
|
'modif_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('modification date'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->_a['idx'] = array(
|
||||||
|
'modif_dtime_idx' =>
|
||||||
|
array(
|
||||||
|
'col' => 'modif_dtime',
|
||||||
|
'type' => 'normal',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$table = $this->_con->pfx.'idf_issue_idf_tag_assoc';
|
||||||
|
$this->_a['views'] = array(
|
||||||
|
'join_tags' =>
|
||||||
|
array(
|
||||||
|
'join' => 'LEFT JOIN '.$table
|
||||||
|
.' ON idf_issue_id=id',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __toString()
|
||||||
|
{
|
||||||
|
return $this->id.' - '.$this->summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
$r = array();
|
||||||
|
foreach ($this->get_comments_list() as $c) {
|
||||||
|
$r[] = $c->_toIndex();
|
||||||
|
}
|
||||||
|
$str = str_repeat($this->summary.' ', 4).' '.implode(' ', $r);
|
||||||
|
return Pluf_Text::cleanString(html_entity_decode($str, ENT_QUOTES, 'UTF-8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
IDF_Timeline::remove($this);
|
||||||
|
IDF_Search::remove($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($this->id == '') {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
$this->modif_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
// Note: No indexing is performed here. The indexing is
|
||||||
|
// triggered in the postSave step of the comment to ensure
|
||||||
|
// that the issue as at least one comment in the database when
|
||||||
|
// doing the indexing.
|
||||||
|
if ($create) {
|
||||||
|
IDF_Timeline::insert($this, $this->get_project(),
|
||||||
|
$this->get_submitter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroupedRelatedIssues($opts = array(), $idsOnly = false)
|
||||||
|
{
|
||||||
|
$rels = $this->get_related_issues_list(array_merge($opts, array(
|
||||||
|
'view' => 'with_other_issue',
|
||||||
|
)));
|
||||||
|
|
||||||
|
$res = array();
|
||||||
|
foreach ($rels as $rel) {
|
||||||
|
$verb = $rel->verb;
|
||||||
|
if (!array_key_exists($verb, $res)) {
|
||||||
|
$res[$verb] = array();
|
||||||
|
}
|
||||||
|
$res[$verb][] = $idsOnly ? $rel->other_issue : $rel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an HTML fragment used to display this issue in the
|
||||||
|
* timeline.
|
||||||
|
*
|
||||||
|
* The request object is given to be able to check the rights and
|
||||||
|
* as such create links to other items etc. You can consider that
|
||||||
|
* if displayed, you can create a link to it.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return Pluf_Template_SafeString
|
||||||
|
*/
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$this->id));
|
||||||
|
$out = '<tr class="log"><td><a href="'.$url.'">'.
|
||||||
|
Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).
|
||||||
|
'</a></td><td>';
|
||||||
|
$stag = new IDF_Template_ShowUser();
|
||||||
|
$user = $stag->start($this->get_submitter(), $request, '', false);
|
||||||
|
$ic = (in_array($this->status, $request->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
|
||||||
|
$out .= sprintf(__('<a href="%1$s" class="%2$s" title="View issue">Issue %3$d</a>, %4$s'), $url, $ic, $this->id, Pluf_esc($this->summary)).'</td>';
|
||||||
|
$out .= "\n".'<tr class="extra"><td colspan="2">
|
||||||
|
<div class="helptext right">'.sprintf(__('Creation of <a href="%1$s" class="%2$s">issue %3$d</a>, by %4$s'), $url, $ic, $this->id, $user).'</div></td></tr>';
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
$url = Pluf::f('url_base')
|
||||||
|
.Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$this->id));
|
||||||
|
$title = sprintf(__('%1$s: Issue %2$d created - %3$s'),
|
||||||
|
$request->project->name,
|
||||||
|
$this->id, $this->summary);
|
||||||
|
$cts = $this->get_comments_list(array('order' => 'id ASC',
|
||||||
|
'nb' => 1));
|
||||||
|
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
|
||||||
|
$context = new Pluf_Template_Context_Request(
|
||||||
|
$request,
|
||||||
|
array('url' => $url,
|
||||||
|
'author' => $this->get_submitter(),
|
||||||
|
'title' => $title,
|
||||||
|
'c' => $cts[0],
|
||||||
|
'issue' => $this,
|
||||||
|
'date' => $date)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/issues/feedfragment.xml');
|
||||||
|
return $tmpl->render($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification of change of the object.
|
||||||
|
*
|
||||||
|
* For the moment, only email, but one can add webhooks later.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* <pre>
|
||||||
|
* $this->notify($conf); // Notify the creation
|
||||||
|
* $this->notify($conf, false); // Notify the update of the object
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param IDF_Conf Current configuration
|
||||||
|
* @param bool Creation (true)
|
||||||
|
*/
|
||||||
|
public function notify($conf, $create=true)
|
||||||
|
{
|
||||||
|
$project = $this->get_project();
|
||||||
|
$current_locale = Pluf_Translation::getLocale();
|
||||||
|
|
||||||
|
$from_email = Pluf::f('from_email');
|
||||||
|
$comments = $this->get_comments_list(array('order' => 'id DESC'));
|
||||||
|
$messageId = '<'.md5('issue'.$this->id.md5(Pluf::f('secret_key'))).'@'.Pluf::f('mail_host', 'localhost').'>';
|
||||||
|
$recipients = $project->getNotificationRecipientsForTab('issues');
|
||||||
|
|
||||||
|
// the submitter (might be skipped later on if he is the one who also
|
||||||
|
// submitted the last comment)
|
||||||
|
if (!array_key_exists($this->get_submitter()->email, $recipients)) {
|
||||||
|
$recipients[$this->get_submitter()->email] = $this->get_submitter()->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the owner of the issue, if we have one
|
||||||
|
$owner = $this->get_owner();
|
||||||
|
if (null != $owner && !array_key_exists($owner->email, $recipients)) {
|
||||||
|
$recipients[$owner->email] = $owner->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
// additional users who starred the issue
|
||||||
|
foreach ($this->get_interested_list() as $interested) {
|
||||||
|
if (array_key_exists($interested->email, $recipients))
|
||||||
|
continue;
|
||||||
|
$recipients[$interested->email] = $interested->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($recipients as $address => $language) {
|
||||||
|
|
||||||
|
// do not notify the creator of the last comment,
|
||||||
|
// i.e. the user who triggered this notification
|
||||||
|
if ($comments[0]->get_submitter()->email === $address) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($language);
|
||||||
|
|
||||||
|
$context = new Pluf_Template_Context(array(
|
||||||
|
'issue' => $this,
|
||||||
|
'owns_issue' => $owner !== null && $owner->email === $address,
|
||||||
|
// the initial comment for create, the last for update
|
||||||
|
'comment' => $comments[0],
|
||||||
|
'comments' => $comments,
|
||||||
|
'project' => $project,
|
||||||
|
'url_base' => Pluf::f('url_base'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$tplfile = 'idf/issues/issue-created-email.txt';
|
||||||
|
$subject = __('Issue %1$s - %2$s (%3$s)');
|
||||||
|
$headers = array('Message-ID' => $messageId);
|
||||||
|
if (!$create) {
|
||||||
|
$tplfile = 'idf/issues/issue-updated-email.txt';
|
||||||
|
$subject = __('Updated Issue %1$s - %2$s (%3$s)');
|
||||||
|
$headers = array('References' => $messageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmpl = new Pluf_Template($tplfile);
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
|
||||||
|
$email = new Pluf_Mail($from_email, $address,
|
||||||
|
sprintf($subject, $this->id, $this->summary, $project->shortname));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->addHeaders($headers);
|
||||||
|
$email->sendMail();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($current_locale);
|
||||||
|
}
|
||||||
|
}
|
213
indefero/src/IDF/IssueComment.php
Normal file
213
indefero/src/IDF/IssueComment.php
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A comment to an issue.
|
||||||
|
*
|
||||||
|
* The first description of an issue is also stored as a comment.
|
||||||
|
*
|
||||||
|
* A comment is also tracking the changes in the main issue.
|
||||||
|
*/
|
||||||
|
class IDF_IssueComment extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_issuecomments';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'issue' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Issue',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('issue'),
|
||||||
|
'relate_name' => 'comments',
|
||||||
|
),
|
||||||
|
'content' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('comment'),
|
||||||
|
),
|
||||||
|
'submitter' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
'relate_name' => 'commented_issue',
|
||||||
|
),
|
||||||
|
'changes' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Serialized',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('changes'),
|
||||||
|
'help_text' => __('Serialized array of the changes in the issue.'),
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->_a['idx'] = array(
|
||||||
|
'creation_dtime_idx' =>
|
||||||
|
array(
|
||||||
|
'col' => 'creation_dtime',
|
||||||
|
'type' => 'normal',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function changedIssue()
|
||||||
|
{
|
||||||
|
return (is_array($this->changes) and count($this->changes) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
IDF_Timeline::remove($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($this->id == '') {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
// Check if more than one comment for this issue. We do
|
||||||
|
// not want to insert the first comment in the timeline as
|
||||||
|
// the issue itself is inserted.
|
||||||
|
$sql = new Pluf_SQL('issue=%s', array($this->issue));
|
||||||
|
$co = Pluf::factory('IDF_IssueComment')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($co->count() > 1) {
|
||||||
|
IDF_Timeline::insert($this, $this->get_issue()->get_project(),
|
||||||
|
$this->get_submitter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IDF_Search::index($this->get_issue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
$issue = $this->get_issue();
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$issue->id));
|
||||||
|
$url .= '#ic'.$this->id;
|
||||||
|
$out = "\n".'<tr class="log"><td><a href="'.$url.'">'.
|
||||||
|
Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).
|
||||||
|
'</a></td><td>';
|
||||||
|
$stag = new IDF_Template_ShowUser();
|
||||||
|
$user = $stag->start($this->get_submitter(), $request, '', false);
|
||||||
|
|
||||||
|
$ic = (in_array($issue->status, $request->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
|
||||||
|
$out .= sprintf(__('<a href="%1$s" class="%2$s" title="View issue">Issue %3$d</a>, %4$s'), $url, $ic, $issue->id, Pluf_esc($issue->summary));
|
||||||
|
|
||||||
|
if ($this->changedIssue()) {
|
||||||
|
$out .= '<div class="issue-changes-timeline">';
|
||||||
|
foreach ($this->changes as $w => $v) {
|
||||||
|
$out .= '<strong>';
|
||||||
|
switch ($w) {
|
||||||
|
case 'su':
|
||||||
|
$out .= __('Summary:'); break;
|
||||||
|
case 'st':
|
||||||
|
$out .= __('Status:'); break;
|
||||||
|
case 'ow':
|
||||||
|
$out .= __('Owner:'); break;
|
||||||
|
case 'lb':
|
||||||
|
$out .= __('Labels:'); break;
|
||||||
|
case 'rel':
|
||||||
|
$out .= __('Relations:'); break;
|
||||||
|
}
|
||||||
|
$out .= '</strong> ';
|
||||||
|
if ($w == 'lb' || $w == 'rel') {
|
||||||
|
foreach ($v as $t => $ls) {
|
||||||
|
foreach ($ls as $l) {
|
||||||
|
if ($t == 'rem') $out .= '<s>';
|
||||||
|
$out .= Pluf_esc($l);
|
||||||
|
if ($t == 'rem') $out .= '</s>';
|
||||||
|
$out .= ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$out .= Pluf_esc($v);
|
||||||
|
}
|
||||||
|
$out .= ' ';
|
||||||
|
}
|
||||||
|
$out .= '</div>';
|
||||||
|
}
|
||||||
|
$out .= '</td></tr>';
|
||||||
|
$out .= "\n".'<tr class="extra"><td colspan="2">
|
||||||
|
<div class="helptext right">'.sprintf(__('Comment on <a href="%1$s" class="%2$s">issue %3$d</a>, by %4$s'), $url, $ic, $issue->id, $user).'</div></td></tr>';
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
$issue = $this->get_issue();
|
||||||
|
$url = Pluf::f('url_base')
|
||||||
|
.Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$issue->id));
|
||||||
|
$title = sprintf(__('%1$s: Comment on issue %2$d - %3$s'),
|
||||||
|
Pluf_esc($request->project->name),
|
||||||
|
$issue->id, Pluf_esc($issue->summary));
|
||||||
|
$url .= '#ic'.$this->id;
|
||||||
|
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
|
||||||
|
$context = new Pluf_Template_Context_Request(
|
||||||
|
$request,
|
||||||
|
array('url' => $url,
|
||||||
|
'author' => $issue->get_submitter(),
|
||||||
|
'title' => $title,
|
||||||
|
'c' => $this,
|
||||||
|
'issue' => $issue,
|
||||||
|
'date' => $date)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/issues/feedfragment.xml');
|
||||||
|
return $tmpl->render($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_submitter_data()
|
||||||
|
{
|
||||||
|
return IDF_UserData::factory($this->get_submitter());
|
||||||
|
}
|
||||||
|
}
|
137
indefero/src/IDF/IssueFile.php
Normal file
137
indefero/src/IDF/IssueFile.php
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A file uploaded with an issue or a comment to an issue.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_IssueFile extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_issuefiles';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
//It is automatically added.
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'comment' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_IssueComment',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('comment'),
|
||||||
|
'relate_name' => 'attachment',
|
||||||
|
),
|
||||||
|
'submitter' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
),
|
||||||
|
'filename' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => true,
|
||||||
|
'size' => 100,
|
||||||
|
'verbose' => __('file name'),
|
||||||
|
),
|
||||||
|
'attachment' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_File',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('the file'),
|
||||||
|
),
|
||||||
|
'filesize' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('file size'),
|
||||||
|
'help_text' => 'Size in bytes.',
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 10,
|
||||||
|
'verbose' => __('type'),
|
||||||
|
'choices' => array(
|
||||||
|
__('Image') => 'img',
|
||||||
|
__('Other') => 'other',
|
||||||
|
),
|
||||||
|
'default' => 'other',
|
||||||
|
'help_text' => 'The type is to display a thumbnail of the image.',
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
),
|
||||||
|
'modif_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('modification date'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($this->id == '') {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
$file = Pluf::f('upload_issue_path').'/'.$this->attachment;
|
||||||
|
$this->filesize = filesize($file);
|
||||||
|
// remove .dummy
|
||||||
|
$this->filename = substr(basename($file), 0, -6);
|
||||||
|
$img_extensions = array('jpeg', 'jpg', 'png', 'gif');
|
||||||
|
$info = pathinfo($this->filename);
|
||||||
|
if (!isset($info['extension'])) $info['extension'] = '';
|
||||||
|
if (in_array(strtolower($info['extension']), $img_extensions)) {
|
||||||
|
$this->type = 'img';
|
||||||
|
} else {
|
||||||
|
$this->type = 'other';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->modif_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
@unlink(Pluf::f('upload_issue_path').'/'.$this->attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isText()
|
||||||
|
{
|
||||||
|
$info = IDF_FileUtil::getMimeType($this->filename);
|
||||||
|
return IDF_FileUtil::isText($info);
|
||||||
|
}
|
||||||
|
}
|
100
indefero/src/IDF/IssueRelation.php
Normal file
100
indefero/src/IDF/IssueRelation.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A relation of one issue to another
|
||||||
|
*/
|
||||||
|
class IDF_IssueRelation extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_issuerelations';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'issue' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Issue',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('issue'),
|
||||||
|
'relate_name' => 'related_issues',
|
||||||
|
),
|
||||||
|
'verb' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('verb'),
|
||||||
|
),
|
||||||
|
'other_issue' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Issue',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('other issue'),
|
||||||
|
'relate_name' => 'related_other_issues',
|
||||||
|
),
|
||||||
|
'submitter' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->_a['idx'] = array(
|
||||||
|
'creation_dtime_idx' =>
|
||||||
|
array(
|
||||||
|
'col' => 'creation_dtime',
|
||||||
|
'type' => 'normal',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$issuetbl = $this->_con->pfx.'idf_issues';
|
||||||
|
$this->_a['views'] = array(
|
||||||
|
'with_other_issue' => array(
|
||||||
|
'join' => 'INNER JOIN '.$issuetbl.' ON other_issue='.$issuetbl.'.id',
|
||||||
|
'select' => $this->getSelect().', summary',
|
||||||
|
'props' => array('summary' => 'other_summary'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($this->id == '') {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
185
indefero/src/IDF/Key.php
Normal file
185
indefero/src/IDF/Key.php
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage of the public keys (ssh or monotone).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Key extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_keys';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
//It is automatically added.
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'user' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('user'),
|
||||||
|
),
|
||||||
|
'content' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('public key'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// WARNING: Not using getSqlTable on the Pluf_User object to
|
||||||
|
// avoid recursion.
|
||||||
|
$t_users = $this->_con->pfx.'users';
|
||||||
|
$this->_a['views'] = array(
|
||||||
|
'join_user' =>
|
||||||
|
array(
|
||||||
|
'join' => 'LEFT JOIN '.$t_users
|
||||||
|
.' ON '.$t_users.'.id='.$this->_con->qn('user'),
|
||||||
|
'select' => $this->getSelect().', '
|
||||||
|
.$t_users.'.login AS login',
|
||||||
|
'props' => array('login' => 'login'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCompact()
|
||||||
|
{
|
||||||
|
return Pluf_Template::markSafe(Pluf_esc(substr($this->content, 0, 25)).' [...] '.Pluf_esc(substr($this->content, -55)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseContent()
|
||||||
|
{
|
||||||
|
if (preg_match('#^\[pubkey ([^\]]+)\]\s*(\S+)\s*\[end\]$#', $this->content, $m)) {
|
||||||
|
return array('mtn', $m[1], $m[2]);
|
||||||
|
}
|
||||||
|
else if (preg_match('#^ssh\-(?:dss|rsa)\s(\S+)(?:\s(.*))?$#', $this->content, $m)) {
|
||||||
|
if (!isset($m[2])) {
|
||||||
|
$m[2] = "";
|
||||||
|
}
|
||||||
|
return array('ssh', $m[2], $m[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception(__('Invalid or unknown key data detected.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type of the public key
|
||||||
|
*
|
||||||
|
* @return string 'ssh' or 'mtn'
|
||||||
|
*/
|
||||||
|
function getType()
|
||||||
|
{
|
||||||
|
list($type, , ) = $this->parseContent();
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the key name of the key
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getName()
|
||||||
|
{
|
||||||
|
list(, $keyName, ) = $this->parseContent();
|
||||||
|
return $keyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function should be used to calculate the key id from the
|
||||||
|
* public key hash for authentication purposes. This avoids clashes
|
||||||
|
* in case the key name is not unique across the project
|
||||||
|
*
|
||||||
|
* And yes, this is actually how monotone itself calculates the key
|
||||||
|
* id...
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getMtnId()
|
||||||
|
{
|
||||||
|
list($type, $keyName, $keyData) = $this->parseContent();
|
||||||
|
if ($type != 'mtn')
|
||||||
|
throw new Exception('key is not a monotone public key');
|
||||||
|
return sha1($keyName.":".$keyData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Key::postSave
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Key
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform special
|
||||||
|
* operations after the saving of a public Key.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('key' => $key,
|
||||||
|
* 'created' => true/false)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('key' => $this, 'created' => $create);
|
||||||
|
Pluf_Signal::send('IDF_Key::postSave',
|
||||||
|
'IDF_Key', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Key::preDelete
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Key
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform special
|
||||||
|
* operations before a key is deleted.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('key' => $key)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('key' => $this);
|
||||||
|
Pluf_Signal::send('IDF_Key::preDelete',
|
||||||
|
'IDF_Key', $params);
|
||||||
|
}
|
||||||
|
}
|
123
indefero/src/IDF/Middleware.php
Normal file
123
indefero/src/IDF/Middleware.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project middleware.
|
||||||
|
*
|
||||||
|
* It must be after the session middleware.
|
||||||
|
*/
|
||||||
|
class IDF_Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Process the request.
|
||||||
|
*
|
||||||
|
* When processing the request, check if matching a project. If
|
||||||
|
* so, directly set $request->project to the project.
|
||||||
|
*
|
||||||
|
* The url to match a project is in the format /p/(\w+)/whatever
|
||||||
|
* or /api/p/(\w+)/whatever. This means that it will not try to
|
||||||
|
* match on /login/ or /logout/.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request The request
|
||||||
|
* @return bool false or redirect.
|
||||||
|
*/
|
||||||
|
function process_request(&$request)
|
||||||
|
{
|
||||||
|
$match = array();
|
||||||
|
if (preg_match('#^/(?:api/p|p)/([\-\w]+)/?#', $request->query, $match)) {
|
||||||
|
try {
|
||||||
|
$request->project = IDF_Project::getOr404($match[1]);
|
||||||
|
} catch (Pluf_HTTP_Error404 $e) {
|
||||||
|
return new Pluf_HTTP_Response_NotFound($request);
|
||||||
|
}
|
||||||
|
$request->conf = new IDF_Conf();
|
||||||
|
$request->conf->setProject($request->project);
|
||||||
|
self::setRights($request);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setRights(&$request)
|
||||||
|
{
|
||||||
|
$ak = array('downloads_access_rights' => 'hasDownloadsAccess',
|
||||||
|
'wiki_access_rights' => 'hasWikiAccess',
|
||||||
|
'review_access_rights' => 'hasReviewAccess',
|
||||||
|
'source_access_rights' => 'hasSourceAccess',
|
||||||
|
'issues_access_rights' => 'hasIssuesAccess');
|
||||||
|
$request->rights = array();
|
||||||
|
foreach ($ak as $key=>$val) {
|
||||||
|
$request->rights[$val] = (true === IDF_Precondition::accessTabGeneric($request, $key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the template tags and modifiers to not have them in the config.
|
||||||
|
*
|
||||||
|
* This is here at the moment because we do not want to put that
|
||||||
|
* in a IDF_Template class just for one method.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function updateTemplateTagsModifiers($sender, &$params)
|
||||||
|
{
|
||||||
|
$params['tags'] = array_merge($params['tags'],
|
||||||
|
array(
|
||||||
|
'hotkey' => 'IDF_Template_HotKey',
|
||||||
|
'issuetext' => 'IDF_Template_IssueComment',
|
||||||
|
'timeline' => 'IDF_Template_TimelineFragment',
|
||||||
|
'markdown' => 'IDF_Template_Markdown',
|
||||||
|
'markdown_forge' => 'IDF_Template_MarkdownForge',
|
||||||
|
'showuser' => 'IDF_Template_ShowUser',
|
||||||
|
'ashowuser' => 'IDF_Template_AssignShowUser',
|
||||||
|
'appversion' => 'IDF_Template_AppVersion',
|
||||||
|
'upload' => 'IDF_Template_Tag_UploadUrl',
|
||||||
|
));
|
||||||
|
$params['modifiers'] = array_merge($params['modifiers'],
|
||||||
|
array(
|
||||||
|
'size' => 'IDF_Views_Source_PrettySize',
|
||||||
|
'ssize' => 'IDF_Views_Source_PrettySizeSimple',
|
||||||
|
'shorten' => 'IDF_Views_Source_ShortenString',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function IDF_Middleware_ContextPreProcessor($request)
|
||||||
|
{
|
||||||
|
$forge = IDF_Forge::instance();
|
||||||
|
$c = array();
|
||||||
|
$c['request'] = $request;
|
||||||
|
$c['isAdmin'] = ($request->user->administrator or $request->user->staff);
|
||||||
|
if (isset($request->project)) {
|
||||||
|
$c['project'] = $request->project;
|
||||||
|
$c['isOwner'] = $request->user->hasPerm('IDF.project-owner',
|
||||||
|
$request->project);
|
||||||
|
$c['isMember'] = $request->user->hasPerm('IDF.project-member',
|
||||||
|
$request->project);
|
||||||
|
$c = array_merge($c, $request->rights);
|
||||||
|
}
|
||||||
|
$c['usherConfigured'] = Pluf::f("mtn_usher_conf", null) !== null;
|
||||||
|
$c['allProjects'] = IDF_Views::getProjects($request->user);
|
||||||
|
$c['customForgePageEnabled'] = $forge->isCustomForgePageEnabled();
|
||||||
|
return $c;
|
||||||
|
}
|
||||||
|
|
52
indefero/src/IDF/Migrations/10SshKey.php
Normal file
52
indefero/src/IDF/Migrations/10SshKey.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the SSH key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_10SshKey_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Key',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_10SshKey_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Key',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
52
indefero/src/IDF/Migrations/11GitCache.php
Normal file
52
indefero/src/IDF/Migrations/11GitCache.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the DB based Git cache.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_11GitCache_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Scm_Cache_Git',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_11GitCache_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Scm_Cache_Git',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
55
indefero/src/IDF/Migrations/12DownloadDesc.php
Normal file
55
indefero/src/IDF/Migrations/12DownloadDesc.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the private column for the project.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_12DownloadDesc_up($params=null)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "changelog" TEXT DEFAULT \'\'';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `changelog` LONGTEXT DEFAULT \'\'';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_12DownloadDesc_down($params=null)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "changelog"';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' DROP COLUMN `changelog`';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
|
||||||
|
}
|
60
indefero/src/IDF/Migrations/13NewReview.php
Normal file
60
indefero/src/IDF/Migrations/13NewReview.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the old review and add the new one.
|
||||||
|
*
|
||||||
|
* This is a destructive operation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_13NewReview_up($params=null)
|
||||||
|
{
|
||||||
|
$extra = (Pluf::f('db_engine') == 'PostgreSQL') ? ' CASCADE' : '';
|
||||||
|
$pfx = Pluf::f('db_table_prefix');
|
||||||
|
$tables = array('idf_review_filecomments',
|
||||||
|
'idf_review_patches',
|
||||||
|
'idf_review_pluf_user_assoc',
|
||||||
|
'idf_review_idf_tag_assoc',
|
||||||
|
'idf_reviews');
|
||||||
|
$db = Pluf::db();
|
||||||
|
foreach ($tables as $table) {
|
||||||
|
$db->execute('DROP TABLE IF EXISTS '.$pfx.$table.$extra);
|
||||||
|
}
|
||||||
|
$models = array(
|
||||||
|
'IDF_Review',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review_Comment',
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_13NewReview_down($params=null)
|
||||||
|
{
|
||||||
|
// We do nothing as we cannot go back to the old reviews
|
||||||
|
}
|
53
indefero/src/IDF/Migrations/14Queue.php
Normal file
53
indefero/src/IDF/Migrations/14Queue.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the new IDF_Queue model.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_14Queue_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Queue',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_14Queue_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Queue',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
53
indefero/src/IDF/Migrations/15AddGconf.php
Normal file
53
indefero/src/IDF/Migrations/15AddGconf.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the new IDF_Gconf model.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_15AddGconf_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Gconf',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_15AddGconf_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Gconf',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
43
indefero/src/IDF/Migrations/16AddUserMail.php
Normal file
43
indefero/src/IDF/Migrations/16AddUserMail.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the new IDF_Gconf model.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_16AddUserMail_up($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
$schema->model = new IDF_EmailAddress();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_16AddUserMail_down($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
$schema->model = new IDF_EmailAddress();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
90
indefero/src/IDF/Migrations/17AddIssueRelations.php
Normal file
90
indefero/src/IDF/Migrations/17AddIssueRelations.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the new IDF_IssueRelation model.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_17AddIssueRelations_up($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
$schema->model = new IDF_IssueRelation();
|
||||||
|
$schema->createTables();
|
||||||
|
|
||||||
|
// change the serialization format for added / removed labels in IDF_IssueComment
|
||||||
|
$comments = Pluf::factory('IDF_IssueComment')->getList();
|
||||||
|
foreach ($comments as $comment) {
|
||||||
|
if (!isset($comment->changes['lb'])) continue;
|
||||||
|
$changes = $comment->changes;
|
||||||
|
$adds = $removals = array();
|
||||||
|
foreach ($comment->changes['lb'] as $lb) {
|
||||||
|
if (substr($lb, 0, 1) == '-')
|
||||||
|
$removals[] = substr($lb, 1);
|
||||||
|
else
|
||||||
|
$adds[] = $lb;
|
||||||
|
}
|
||||||
|
$changes['lb'] = array();
|
||||||
|
if (count($adds) > 0)
|
||||||
|
$changes['lb']['add'] = $adds;
|
||||||
|
if (count($removals) > 0)
|
||||||
|
$changes['lb']['rem'] = $removals;
|
||||||
|
$comment->changes = $changes;
|
||||||
|
$comment->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_17AddIssueRelations_down($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
$schema->model = new IDF_IssueRelation();
|
||||||
|
$schema->dropTables();
|
||||||
|
|
||||||
|
// change the serialization format for added / removed labels in IDF_IssueComment
|
||||||
|
$comments = Pluf::factory('IDF_IssueComment')->getList();
|
||||||
|
foreach ($comments as $comment) {
|
||||||
|
$changes = $comment->changes;
|
||||||
|
if (empty($changes))
|
||||||
|
continue;
|
||||||
|
if (isset($changes['lb'])) {
|
||||||
|
$labels = array();
|
||||||
|
foreach ($changes['lb'] as $type => $lbs) {
|
||||||
|
if (!is_array($lbs)) {
|
||||||
|
$labels[] = $lbs;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($lbs as $lb) {
|
||||||
|
$labels[] = ($type == 'rem' ? '-' : '') . $lb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$changes['lb'] = $labels;
|
||||||
|
}
|
||||||
|
// while we're at it, remove any 'rel' changes
|
||||||
|
unset($changes['rel']);
|
||||||
|
$comment->changes = $changes;
|
||||||
|
$comment->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
63
indefero/src/IDF/Migrations/18DownloadMD5.php
Normal file
63
indefero/src/IDF/Migrations/18DownloadMD5.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the md5 column for the download model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_18DownloadMD5_up($params=null)
|
||||||
|
{
|
||||||
|
// Add the row
|
||||||
|
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "md5" VARCHAR(32) DEFAULT \'\'';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `md5` VARCHAR(32) DEFAULT \'\'';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
|
||||||
|
// Process md5 of already uploaded file
|
||||||
|
$files = Pluf::factory('IDF_Upload')->getList();
|
||||||
|
foreach ($files as $f) {
|
||||||
|
$f->md5 = md5_file (Pluf::f('upload_path') . '/' . $f->get_project()->shortname . '/files/' . $f->file);
|
||||||
|
$f->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_18DownloadMD5_down($params=null)
|
||||||
|
{
|
||||||
|
// Remove the row
|
||||||
|
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "md5"';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' DROP COLUMN `md5`';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
}
|
74
indefero/src/IDF/Migrations/19WikiPageAssocs.php
Normal file
74
indefero/src/IDF/Migrations/19WikiPageAssocs.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
function IDF_Migrations_19WikiPageAssocs_up($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!in_array($engine, array('MySQL', 'PostgreSQL'))) {
|
||||||
|
throw new Exception('unsupported engine '.$engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Pluf::db();
|
||||||
|
$intro = new Pluf_DB_Introspect($db);
|
||||||
|
if (in_array($db->pfx.'idf_tag_idf_wiki_page_assoc', $intro->listTables())) {
|
||||||
|
echo '19 skipping up migration - relation table has correct name already'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tag_idf_wikipage_assoc RENAME TO '.$db->pfx.'idf_tag_idf_wiki_page_assoc');
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wikipage_pluf_user_assoc RENAME TO '.$db->pfx.'idf_wiki_page_pluf_user_assoc');
|
||||||
|
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tag_idf_wiki_page_assoc RENAME COLUMN idf_wikipage_id TO idf_wiki_page_id');
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wiki_page_pluf_user_assoc RENAME COLUMN idf_wikipage_id TO idf_wiki_page_id');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tag_idf_wiki_page_assoc CHANGE idf_wikipage_id idf_wiki_page_id MEDIUMINT NOT NULL');
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wiki_page_pluf_user_assoc CHANGE idf_wikipage_id idf_wiki_page_id MEDIUMINT NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_19WikiPageAssocs_down($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!in_array($engine, array('MySQL', 'PostgreSQL'))) {
|
||||||
|
throw new Exception('unsupported engine '.$engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Pluf::db();
|
||||||
|
$intro = new Pluf_DB_Introspect($db);
|
||||||
|
if (in_array($db->pfx.'idf_tag_idf_wikipage_assoc', $intro->listTables())) {
|
||||||
|
echo '19 skipping down migration - relation table has correct name already'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tag_idf_wiki_page_assoc RENAME TO '.$db->pfx.'idf_tag_idf_wikipage_assoc');
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wiki_page_pluf_user_assoc RENAME TO '.$db->pfx.'idf_wikipage_pluf_user_assoc');
|
||||||
|
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tag_idf_wikipage_assoc RENAME COLUMN idf_wiki_page_id TO idf_wikipage_id');
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wikipage_pluf_user_assoc RENAME COLUMN idf_wiki_page_id TO idf_wikipage_id');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tag_idf_wikipage_assoc CHANGE idf_wiki_page_id idf_wikipage_id MEDIUMINT NOT NULL');
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wikipage_pluf_user_assoc CHANGE idf_wiki_page_id idf_wikipage_id MEDIUMINT NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
52
indefero/src/IDF/Migrations/1Download.php
Normal file
52
indefero/src/IDF/Migrations/1Download.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the download of files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_1Download_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Upload',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_1Download_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Upload',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
51
indefero/src/IDF/Migrations/20AddWikiResources.php
Normal file
51
indefero/src/IDF/Migrations/20AddWikiResources.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the new IDF_Wiki_Resource and IDF_Wiki_ResourceRevision models.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_20AddWikiResources_up($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
|
||||||
|
$schema->model = new IDF_Wiki_Resource();
|
||||||
|
$schema->createTables();
|
||||||
|
|
||||||
|
$schema->model = new IDF_Wiki_ResourceRevision();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_20AddWikiResources_down($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
|
||||||
|
$schema->model = new IDF_Wiki_ResourceRevision();
|
||||||
|
$schema->dropTables();
|
||||||
|
|
||||||
|
$schema->model = new IDF_Wiki_Resource();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
68
indefero/src/IDF/Migrations/21WikiPageRevisionName.php
Normal file
68
indefero/src/IDF/Migrations/21WikiPageRevisionName.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
function IDF_Migrations_21WikiPageRevisionName_up($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!in_array($engine, array('MySQL', 'PostgreSQL'))) {
|
||||||
|
throw new Exception('unsupported engine '.$engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Pluf::db();
|
||||||
|
$intro = new Pluf_DB_Introspect($db);
|
||||||
|
if (in_array($db->pfx.'idf_wikipagerevs', $intro->listTables())) {
|
||||||
|
echo '21 skipping up migration - table has correct name already'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wikirevisions RENAME TO '.$db->pfx.'idf_wikipagerevs');
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_timeline SET model_class='IDF_Wiki_Page' WHERE model_class LIKE 'IDF_WikiPage'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_timeline SET model_class='IDF_Wiki_PageRevision' WHERE model_class LIKE 'IDF_WikiRevision'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_search_occs SET model_class='IDF_Wiki_Page' WHERE model_class LIKE 'IDF_WikiPage'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_search_occs SET model_class='IDF_Wiki_PageRevision' WHERE model_class LIKE 'IDF_WikiRevision'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."pluf_search_stats SET model_class='IDF_Wiki_Page' WHERE model_class LIKE 'IDF_WikiPage'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."pluf_search_stats SET model_class='IDF_Wiki_PageRevision' WHERE model_class LIKE 'IDF_WikiRevision'");
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_21WikiPageRevisionName_down($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!in_array($engine, array('MySQL', 'PostgreSQL'))) {
|
||||||
|
throw new Exception('unsupported engine '.$engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Pluf::db();
|
||||||
|
$intro = new Pluf_DB_Introspect($db);
|
||||||
|
if (in_array($db->pfx.'idf_wikirevisions', $intro->listTables())) {
|
||||||
|
echo '21 skipping down migration - table has correct name already'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_wikipagerevs RENAME TO '.$db->pfx.'idf_wikirevisions');
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_timeline SET model_class='IDF_WikiPage' WHERE model_class LIKE 'IDF_Wiki_Page'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_timeline SET model_class='IDF_WikiRevision' WHERE model_class LIKE 'IDF_Wiki_PageRevision'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_search_occs SET model_class='IDF_WikiPage' WHERE model_class LIKE 'IDF_Wiki_Page'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."idf_search_occs SET model_class='IDF_WikiRevision' WHERE model_class LIKE 'IDF_Wiki_PageRevision'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."pluf_search_stats SET model_class='IDF_WikiPage' WHERE model_class LIKE 'IDF_Wiki_Page'");
|
||||||
|
$db->execute("UPDATE ".$db->pfx."pluf_search_stats SET model_class='IDF_WikiRevision' WHERE model_class LIKE 'IDF_Wiki_PageRevision'");
|
||||||
|
}
|
60
indefero/src/IDF/Migrations/22ProjectTagRelationTable.php
Normal file
60
indefero/src/IDF/Migrations/22ProjectTagRelationTable.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
function IDF_Migrations_22ProjectTagRelationTable_up($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$table = $db->pfx.'idf_project_idf_tag_assoc';
|
||||||
|
if (!in_array($db->engine, array('MySQL', 'PostgreSQL'))) {
|
||||||
|
throw new Exception('unsupported engine '.$engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
$intro = new Pluf_DB_Introspect($db);
|
||||||
|
if (in_array($table, $intro->listTables())) {
|
||||||
|
echo '21 skipping up migration - table already exists'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$schema = Pluf::factory('Pluf_DB_Schema_'.$db->engine, $db);
|
||||||
|
$sql = $schema->getSqlCreate(new IDF_Project());
|
||||||
|
$db->execute($sql[$table]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_22ProjectTagRelationTable_down($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$table = $db->pfx.'idf_project_idf_tag_assoc';
|
||||||
|
if (!in_array($db->engine, array('MySQL', 'PostgreSQL'))) {
|
||||||
|
throw new Exception('unsupported engine '.$engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
$intro = new Pluf_DB_Introspect($db);
|
||||||
|
if (!in_array($table, $intro->listTables())) {
|
||||||
|
echo '22 skipping down migration - table does not exist'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$schema = Pluf::factory('Pluf_DB_Schema_'.$db->engine, $db);
|
||||||
|
$sql = $schema->getSqlDelete(new IDF_Project());
|
||||||
|
$db->execute($sql[$table]);
|
||||||
|
}
|
42
indefero/src/IDF/Migrations/23ProjectActivity.php
Normal file
42
indefero/src/IDF/Migrations/23ProjectActivity.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the new IDF_ProjectActivity model.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function IDF_Migrations_23ProjectActivity_up($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
$schema->model = new IDF_ProjectActivity();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_23ProjectActivity_down($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
$schema->model = new IDF_ProjectActivity();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
40
indefero/src/IDF/Migrations/24CurrentProjectActivity.php
Normal file
40
indefero/src/IDF/Migrations/24CurrentProjectActivity.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
function IDF_Migrations_24CurrentProjectActivity_up($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
$db = Pluf::db();
|
||||||
|
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects ADD COLUMN current_activity INTEGER');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects ADD COLUMN current_activity MEDIUMINT');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_24CurrentProjectActivity_down($params=null)
|
||||||
|
{
|
||||||
|
$db = Pluf::db();
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects DROP COLUMN current_activity');
|
||||||
|
}
|
47
indefero/src/IDF/Migrations/25NullableProjectInTag.php
Normal file
47
indefero/src/IDF/Migrations/25NullableProjectInTag.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
function IDF_Migrations_25NullableProjectInTag_up($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
$db = Pluf::db();
|
||||||
|
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tags ALTER COLUMN project DROP NOT NULL');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tags MODIFY project MEDIUMINT NULL');
|
||||||
|
// this is only needed for non-transactional setups where MySQL set 0 as default value
|
||||||
|
$db->execute('UPDATE '.$db->pfx.'idf_tags SET project=NULL WHERE project=0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_25NullableProjectInTag_down($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
$db = Pluf::db();
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tags ALTER COLUMN project SET NOT NULL');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_tags MODIFY project MEDIUMINT NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
46
indefero/src/IDF/Migrations/26NullableActivityInProject.php
Normal file
46
indefero/src/IDF/Migrations/26NullableActivityInProject.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2012 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
function IDF_Migrations_26NullableActivityInProject_up($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
$db = Pluf::db();
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects ALTER COLUMN current_activity DROP NOT NULL');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects MODIFY current_activity MEDIUMINT NULL');
|
||||||
|
// this is only needed for non-transactional setups where MySQL set 0 as default value
|
||||||
|
$db->execute('UPDATE '.$db->pfx.'idf_projects SET current_activity=NULL WHERE current_activity=0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_26NullableActivityInProject_down($params=null)
|
||||||
|
{
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
$db = Pluf::db();
|
||||||
|
if ($engine === 'PostgreSQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects ALTER COLUMN current_activity SET NOT NULL');
|
||||||
|
} else if ($engine === 'MySQL') {
|
||||||
|
$db->execute('ALTER TABLE '.$db->pfx.'idf_projects MODIFY current_activity MEDIUMINT NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
55
indefero/src/IDF/Migrations/2Search.php
Normal file
55
indefero/src/IDF/Migrations/2Search.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the download of files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_2Search_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Search_Occ',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
foreach (Pluf::factory('IDF_Issue')->getList() as $i) {
|
||||||
|
IDF_Search::index($i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_2Search_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Search_Occ',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
52
indefero/src/IDF/Migrations/3Attachments.php
Normal file
52
indefero/src/IDF/Migrations/3Attachments.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the download of files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_3Attachments_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_IssueFile',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_3Attachments_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_IssueFile',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
54
indefero/src/IDF/Migrations/4Timeline.php
Normal file
54
indefero/src/IDF/Migrations/4Timeline.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the download of files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_4Timeline_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Commit',
|
||||||
|
'IDF_Timeline',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_4Timeline_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Timeline',
|
||||||
|
'IDF_Commit',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
47
indefero/src/IDF/Migrations/5DescToText.php
Normal file
47
indefero/src/IDF/Migrations/5DescToText.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the download of files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_5DescToText_up($params=null)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory('IDF_Conf')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ALTER vdesc TYPE text';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' CHANGE vdesc TYPE text';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
echo 'Skip SQLite upgrade as not needed.'."\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_5DescToText_down($params=null)
|
||||||
|
{
|
||||||
|
// lazy, do not care
|
||||||
|
return;
|
||||||
|
}
|
63
indefero/src/IDF/Migrations/6PrivateProject.php
Normal file
63
indefero/src/IDF/Migrations/6PrivateProject.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the private column for the project.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_6PrivateProject_up($params=null)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory('IDF_Project')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "private" INTEGER DEFAULT 0';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `private` INTEGER DEFAULT 0';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
$perm = new Pluf_Permission();
|
||||||
|
$perm->name = 'Project authorized users';
|
||||||
|
$perm->code_name = 'project-authorized-user';
|
||||||
|
$perm->description = 'Permission given to users allowed to access a project.';
|
||||||
|
$perm->application = 'IDF';
|
||||||
|
$perm->create();
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_6PrivateProject_down($params=null)
|
||||||
|
{
|
||||||
|
$perm = Pluf_Permission::getFromString('IDF.project-authorized-user');
|
||||||
|
if ($perm) $perm->delete();
|
||||||
|
$table = Pluf::factory('IDF_Project')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "private"';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' DROP COLUMN `private`';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
|
||||||
|
}
|
54
indefero/src/IDF/Migrations/7Wiki.php
Normal file
54
indefero/src/IDF/Migrations/7Wiki.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add wiki functionality.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_7Wiki_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Wiki_Page',
|
||||||
|
'IDF_Wiki_PageRevision',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_7Wiki_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Wiki_PageRevision',
|
||||||
|
'IDF_Wiki_Page',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
56
indefero/src/IDF/Migrations/8CodeReview.php
Normal file
56
indefero/src/IDF/Migrations/8CodeReview.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the code review.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_8CodeReview_up($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Review',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_8CodeReview_down($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
55
indefero/src/IDF/Migrations/9ShortDescription.php
Normal file
55
indefero/src/IDF/Migrations/9ShortDescription.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the private column for the project.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_9ShortDescription_up($params=null)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory('IDF_Project')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "shortdesc" VARCHAR(255) DEFAULT \'\'';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `shortdesc` VARCHAR(255) DEFAULT \'\'';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_9ShortDescription_down($params=null)
|
||||||
|
{
|
||||||
|
$table = Pluf::factory('IDF_Project')->getSqlTable();
|
||||||
|
$sql = array();
|
||||||
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "shortdesc"';
|
||||||
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' DROP COLUMN `shortdesc`';
|
||||||
|
$db = Pluf::db();
|
||||||
|
$engine = Pluf::f('db_engine');
|
||||||
|
if (!isset($sql[$engine])) {
|
||||||
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
|
}
|
||||||
|
$db->execute($sql[$engine]);
|
||||||
|
|
||||||
|
}
|
127
indefero/src/IDF/Migrations/Backup.php
Normal file
127
indefero/src/IDF/Migrations/Backup.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup of InDefero.
|
||||||
|
*
|
||||||
|
* !! You need also to backup Pluf if you want the full backup. !!
|
||||||
|
*
|
||||||
|
* @param string Path to the folder where to store the backup
|
||||||
|
* @param string Name of the backup (null)
|
||||||
|
* @return int The backup was correctly written
|
||||||
|
*/
|
||||||
|
function IDF_Migrations_Backup_run($folder, $name=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Project',
|
||||||
|
'IDF_ProjectActivity',
|
||||||
|
'IDF_Tag',
|
||||||
|
'IDF_Issue',
|
||||||
|
'IDF_IssueComment',
|
||||||
|
'IDF_Conf',
|
||||||
|
'IDF_Upload',
|
||||||
|
'IDF_Search_Occ',
|
||||||
|
'IDF_IssueFile',
|
||||||
|
'IDF_Commit',
|
||||||
|
'IDF_Timeline',
|
||||||
|
'IDF_Wiki_Page',
|
||||||
|
'IDF_Wiki_PageRevision',
|
||||||
|
'IDF_Wiki_Resource',
|
||||||
|
'IDF_Wiki_ResourceRevision',
|
||||||
|
'IDF_Review',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review_Comment',
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
'IDF_Key',
|
||||||
|
'IDF_Scm_Cache_Git',
|
||||||
|
'IDF_Queue',
|
||||||
|
'IDF_Gconf',
|
||||||
|
'IDF_EmailAddress',
|
||||||
|
'IDF_IssueRelation',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
// Now, for each table, we dump the content in json, this is a
|
||||||
|
// memory intensive operation
|
||||||
|
$to_json = array();
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$to_json[$model] = Pluf_Test_Fixture::dump($model, false);
|
||||||
|
}
|
||||||
|
if (null == $name) {
|
||||||
|
$name = date('Y-m-d');
|
||||||
|
}
|
||||||
|
return file_put_contents(sprintf('%s/%s-IDF.json', $folder, $name),
|
||||||
|
json_encode($to_json), LOCK_EX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore IDF from a backup.
|
||||||
|
*
|
||||||
|
* @param string Path to the backup folder
|
||||||
|
* @param string Backup name
|
||||||
|
* @return bool Success
|
||||||
|
*/
|
||||||
|
function IDF_Migrations_Backup_restore($folder, $name)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Project',
|
||||||
|
'IDF_ProjectActivity',
|
||||||
|
'IDF_Tag',
|
||||||
|
'IDF_Issue',
|
||||||
|
'IDF_IssueComment',
|
||||||
|
'IDF_Conf',
|
||||||
|
'IDF_Upload',
|
||||||
|
'IDF_Search_Occ',
|
||||||
|
'IDF_IssueFile',
|
||||||
|
'IDF_Commit',
|
||||||
|
'IDF_Timeline',
|
||||||
|
'IDF_Wiki_Resource',
|
||||||
|
'IDF_Wiki_ResourceRevision',
|
||||||
|
'IDF_Wiki_Page',
|
||||||
|
'IDF_Wiki_PageRevision',
|
||||||
|
'IDF_Review',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review_Comment',
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
'IDF_Key',
|
||||||
|
'IDF_Scm_Cache_Git',
|
||||||
|
'IDF_Queue',
|
||||||
|
'IDF_Gconf',
|
||||||
|
'IDF_EmailAddress',
|
||||||
|
'IDF_IssueRelation',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
$full_data = json_decode(file_get_contents(sprintf('%s/%s-IDF.json', $folder, $name)), true);
|
||||||
|
foreach ($full_data as $model => $data) {
|
||||||
|
Pluf_Test_Fixture::load($data, false);
|
||||||
|
}
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createConstraints();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
135
indefero/src/IDF/Migrations/Install.php
Normal file
135
indefero/src/IDF/Migrations/Install.php
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup of a clean InDefero.
|
||||||
|
*
|
||||||
|
* It creates all the tables for the application.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function IDF_Migrations_Install_setup($params=null)
|
||||||
|
{
|
||||||
|
$models = array(
|
||||||
|
'IDF_Project',
|
||||||
|
'IDF_ProjectActivity',
|
||||||
|
'IDF_Tag',
|
||||||
|
'IDF_Issue',
|
||||||
|
'IDF_IssueComment',
|
||||||
|
'IDF_Conf',
|
||||||
|
'IDF_Upload',
|
||||||
|
'IDF_Search_Occ',
|
||||||
|
'IDF_IssueFile',
|
||||||
|
'IDF_Commit',
|
||||||
|
'IDF_Timeline',
|
||||||
|
'IDF_Wiki_Resource',
|
||||||
|
'IDF_Wiki_ResourceRevision',
|
||||||
|
'IDF_Wiki_Page',
|
||||||
|
'IDF_Wiki_PageRevision',
|
||||||
|
'IDF_Review',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review_Comment',
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
'IDF_Key',
|
||||||
|
'IDF_Scm_Cache_Git',
|
||||||
|
'IDF_Queue',
|
||||||
|
'IDF_Gconf',
|
||||||
|
'IDF_EmailAddress',
|
||||||
|
'IDF_IssueRelation',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createTables();
|
||||||
|
}
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->createConstraints();
|
||||||
|
}
|
||||||
|
// Install the permissions
|
||||||
|
$perm = new Pluf_Permission();
|
||||||
|
$perm->name = 'Project membership';
|
||||||
|
$perm->code_name = 'project-member';
|
||||||
|
$perm->description = 'Permission given to project members.';
|
||||||
|
$perm->application = 'IDF';
|
||||||
|
$perm->create();
|
||||||
|
$perm = new Pluf_Permission();
|
||||||
|
$perm->name = 'Project ownership';
|
||||||
|
$perm->code_name = 'project-owner';
|
||||||
|
$perm->description = 'Permission given to project owners.';
|
||||||
|
$perm->application = 'IDF';
|
||||||
|
$perm->create();
|
||||||
|
$perm = new Pluf_Permission();
|
||||||
|
$perm->name = 'Project authorized users';
|
||||||
|
$perm->code_name = 'project-authorized-user';
|
||||||
|
$perm->description = 'Permission given to users allowed to access a project.';
|
||||||
|
$perm->application = 'IDF';
|
||||||
|
$perm->create();
|
||||||
|
}
|
||||||
|
|
||||||
|
function IDF_Migrations_Install_teardown($params=null)
|
||||||
|
{
|
||||||
|
$perm = Pluf_Permission::getFromString('IDF.project-member');
|
||||||
|
if ($perm) $perm->delete();
|
||||||
|
$perm = Pluf_Permission::getFromString('IDF.project-owner');
|
||||||
|
if ($perm) $perm->delete();
|
||||||
|
$perm = Pluf_Permission::getFromString('IDF.project-authorized-user');
|
||||||
|
if ($perm) $perm->delete();
|
||||||
|
$models = array(
|
||||||
|
'IDF_Gconf',
|
||||||
|
'IDF_Queue',
|
||||||
|
'IDF_Scm_Cache_Git',
|
||||||
|
'IDF_Key',
|
||||||
|
'IDF_Review_FileComment',
|
||||||
|
'IDF_Review_Comment',
|
||||||
|
'IDF_Review_Patch',
|
||||||
|
'IDF_Review',
|
||||||
|
'IDF_Wiki_PageRevision',
|
||||||
|
'IDF_Wiki_Page',
|
||||||
|
'IDF_Wiki_ResourceRevision',
|
||||||
|
'IDF_Wiki_Resource',
|
||||||
|
'IDF_Timeline',
|
||||||
|
'IDF_IssueFile',
|
||||||
|
'IDF_Search_Occ',
|
||||||
|
'IDF_Upload',
|
||||||
|
'IDF_Conf',
|
||||||
|
'IDF_IssueComment',
|
||||||
|
'IDF_Issue',
|
||||||
|
'IDF_Tag',
|
||||||
|
'IDF_Commit',
|
||||||
|
'IDF_ProjectActivity',
|
||||||
|
'IDF_Project',
|
||||||
|
'IDF_EmailAddress',
|
||||||
|
'IDF_IssueRelation',
|
||||||
|
);
|
||||||
|
$db = Pluf::db();
|
||||||
|
$schema = new Pluf_DB_Schema($db);
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropConstraints();
|
||||||
|
}
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$schema->model = new $model();
|
||||||
|
$schema->dropTables();
|
||||||
|
}
|
||||||
|
}
|
81
indefero/src/IDF/Plugin/SyncGit.php
Normal file
81
indefero/src/IDF/Plugin/SyncGit.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a plugin which allows to synchronise access riths
|
||||||
|
* between InDefero and a common restricted SSH account for git
|
||||||
|
* access.
|
||||||
|
*
|
||||||
|
* As the authentication is directly performed by accessing the
|
||||||
|
* InDefero database, we only need to synchronize the SSH keys. This
|
||||||
|
* synchronization process can only be performed by a process running
|
||||||
|
* under the git user as we need to write in
|
||||||
|
* /home/git/.ssh/authorized_keys
|
||||||
|
*
|
||||||
|
* So, here, we are just creating a file informing that a sync needs
|
||||||
|
* to be done. We connect this plugin to the IDF_Key::postSave signal.
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncGit
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Entry point of the plugin.
|
||||||
|
*/
|
||||||
|
static public function entry($signal, &$params)
|
||||||
|
{
|
||||||
|
// First check for the single mandatory config variable.
|
||||||
|
if (!Pluf::f('idf_plugin_syncgit_sync_file', false)) {
|
||||||
|
Pluf_Log::debug('IDF_Plugin_SyncGit plugin not configured.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($signal != 'gitpostupdate.php::run') {
|
||||||
|
Pluf_Log::event('IDF_Plugin_SyncGit', 'create',
|
||||||
|
Pluf::f('idf_plugin_syncgit_sync_file'));
|
||||||
|
@touch(Pluf::f('idf_plugin_syncgit_sync_file'));
|
||||||
|
@chmod(Pluf::f('idf_plugin_syncgit_sync_file'), 0777);
|
||||||
|
} else {
|
||||||
|
self::postUpdate($signal, $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point for the post-update signal.
|
||||||
|
*
|
||||||
|
* It tries to find the name of the project, when found it runs an
|
||||||
|
* update of the timeline.
|
||||||
|
*/
|
||||||
|
static public function postUpdate($signal, &$params)
|
||||||
|
{
|
||||||
|
// Chop the ".git" and get what is left
|
||||||
|
$pname = basename($params['git_dir'], '.git');
|
||||||
|
try {
|
||||||
|
$project = IDF_Project::getOr404($pname);
|
||||||
|
} catch (Pluf_HTTP_Error404 $e) {
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'Project not found.', array($pname, $params)));
|
||||||
|
return false; // Project not found
|
||||||
|
}
|
||||||
|
// Now we have the project and can update the timeline
|
||||||
|
Pluf_Log::debug(array('IDF_Plugin_SyncGit::postUpdate', 'Project found', $pname, $project->id));
|
||||||
|
IDF_Scm::syncTimeline($project, true);
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'sync', array($pname, $project->id)));
|
||||||
|
}
|
||||||
|
}
|
141
indefero/src/IDF/Plugin/SyncGit/Cron.php
Normal file
141
indefero/src/IDF/Plugin/SyncGit/Cron.php
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronize the SSH keys with InDefero.
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncGit_Cron
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Template for the SSH key.
|
||||||
|
*/
|
||||||
|
public $template = 'command="python %s %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronize.
|
||||||
|
*/
|
||||||
|
public static function sync()
|
||||||
|
{
|
||||||
|
$template = Pluf::factory(__CLASS__)->template;
|
||||||
|
$cmd = Pluf::f('idf_plugin_syncgit_path_gitserve', '/dev/null');
|
||||||
|
$authorized_keys = Pluf::f('idf_plugin_syncgit_path_authorized_keys', false);
|
||||||
|
if (false == $authorized_keys) {
|
||||||
|
throw new Pluf_Exception_SettingError('Setting idf_plugin_syncgit_path_authorized_keys not set.');
|
||||||
|
}
|
||||||
|
if (!is_writable($authorized_keys)) {
|
||||||
|
throw new Exception('Cannot create file: '.$authorized_keys);
|
||||||
|
}
|
||||||
|
$out = '';
|
||||||
|
$keys = Pluf::factory('IDF_Key')->getList(array('view'=>'join_user'));
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
try {
|
||||||
|
$key_type = $key->getType();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// The key is a bad key, skip it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($key_type == 'ssh' and preg_match('/^[a-zA-Z][a-zA-Z0-9_.-]*(@[a-zA-Z][a-zA-Z0-9.-]*)?$/', $key->login)) {
|
||||||
|
$content = trim(str_replace(array("\n", "\r"), '', $key->content));
|
||||||
|
$out .= sprintf($template, $cmd, $key->login, $content)."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$out = "# indefero start" . PHP_EOL . $out . "# indefero end" . PHP_EOL;
|
||||||
|
|
||||||
|
// We update only the part of the file between IDF_START / IDF_END comment
|
||||||
|
$original_keys = file_get_contents($authorized_keys);
|
||||||
|
if (strstr($original_keys, "# indefero start") && strstr($original_keys, "# indefero end")) {
|
||||||
|
$out = preg_replace('%(#\sindefero\sstart).+(#\sindefero\send\s\s?)%isU',
|
||||||
|
$out, $original_keys);
|
||||||
|
} else {
|
||||||
|
$out .= $original_keys;
|
||||||
|
}
|
||||||
|
file_put_contents($authorized_keys, $out, LOCK_EX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark export of git repositories for the daemon.
|
||||||
|
*/
|
||||||
|
public static function markExport()
|
||||||
|
{
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList() as $project) {
|
||||||
|
$rep = sprintf(Pluf::f('git_repositories'), $project->shortname);
|
||||||
|
$serve = new IDF_Plugin_SyncGit_Serve();
|
||||||
|
$serve->setGitExport($project->shortname, $rep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove orphan repositories.
|
||||||
|
*/
|
||||||
|
public static function removeOrphanRepositories()
|
||||||
|
{
|
||||||
|
$path = Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories');
|
||||||
|
if (!is_dir($path) || is_link($path)) {
|
||||||
|
throw new Pluf_Exception_SettingError(sprintf(
|
||||||
|
'Directory %s does not exist! Setting "idf_plugin_syncgit_base_repositories not set.',
|
||||||
|
$path));
|
||||||
|
}
|
||||||
|
if (!is_writable($path)) {
|
||||||
|
throw new Exception(sprintf('Repository %s is not writable.', $path));
|
||||||
|
}
|
||||||
|
$projects = array();
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList() as $project) {
|
||||||
|
$projects[] = $project->shortname;
|
||||||
|
}
|
||||||
|
unset($project);
|
||||||
|
$it = new DirectoryIterator($path);
|
||||||
|
$orphans = array();
|
||||||
|
while ($it->valid()) {
|
||||||
|
if (!$it->isDot() && $it->isDir() && !in_array(basename($it->getFileName(), '.git'), $projects)) {
|
||||||
|
$orphans[] = $it->getPathName();
|
||||||
|
}
|
||||||
|
$it->next();
|
||||||
|
}
|
||||||
|
if (count($orphans)) {
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').'rm -rf '.implode(' ', $orphans);
|
||||||
|
exec($cmd);
|
||||||
|
clearstatcache();
|
||||||
|
while (list(, $project) = each($orphans)) {
|
||||||
|
if (is_dir($project)) {
|
||||||
|
throw new Exception(sprintf('Cannot remove %s directory.', $project));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a sync is needed.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function main()
|
||||||
|
{
|
||||||
|
if (file_exists(Pluf::f('idf_plugin_syncgit_sync_file'))) {
|
||||||
|
@unlink(Pluf::f('idf_plugin_syncgit_sync_file'));
|
||||||
|
self::sync();
|
||||||
|
self::markExport();
|
||||||
|
if (Pluf::f('idf_plugin_syncgit_remove_orphans', false)) {
|
||||||
|
self::removeOrphanRepositories();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
317
indefero/src/IDF/Plugin/SyncGit/Serve.php
Normal file
317
indefero/src/IDF/Plugin/SyncGit/Serve.php
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main application to serve git repositories through a restricted SSH
|
||||||
|
* access.
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncGit_Serve
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Regular expression to match the path in the git command.
|
||||||
|
*/
|
||||||
|
public $preg = '#^\'/*(?P<path>[a-zA-Z0-9][a-zA-Z0-9@._-]*(/[a-zA-Z0-9][a-zA-Z0-9@._-]*)*)\'$#';
|
||||||
|
|
||||||
|
public $commands_readonly = array('git-upload-pack', 'git upload-pack');
|
||||||
|
public $commands_write = array('git-receive-pack', 'git receive-pack');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serve a git request.
|
||||||
|
*
|
||||||
|
* @param string Username.
|
||||||
|
* @param string Command to be run.
|
||||||
|
*/
|
||||||
|
public function serve($username, $cmd)
|
||||||
|
{
|
||||||
|
if (false !== strpos($cmd, "\n")) {
|
||||||
|
throw new Exception('Command may not contain newline.');
|
||||||
|
}
|
||||||
|
$splitted = preg_split('/\s/', $cmd, 2);
|
||||||
|
if (count($splitted) != 2) {
|
||||||
|
throw new Exception('Unknown command denied.');
|
||||||
|
}
|
||||||
|
if ($splitted[0] == 'git') {
|
||||||
|
$sub_splitted = preg_split('/\s/', $splitted[1], 2);
|
||||||
|
if (count($sub_splitted) != 2) {
|
||||||
|
throw new Exception('Unknown command denied.');
|
||||||
|
}
|
||||||
|
$verb = sprintf('%s %s', $splitted[0], $sub_splitted[0]);
|
||||||
|
$args = $sub_splitted[1];
|
||||||
|
} else {
|
||||||
|
$verb = $splitted[0];
|
||||||
|
$args = $splitted[1];
|
||||||
|
}
|
||||||
|
if (!in_array($verb, $this->commands_write)
|
||||||
|
and !in_array($verb, $this->commands_readonly)) {
|
||||||
|
throw new Exception('Unknown command denied.');
|
||||||
|
}
|
||||||
|
if (!preg_match($this->preg, $args, $matches)) {
|
||||||
|
throw new Exception('Arguments to command look dangerous.');
|
||||||
|
}
|
||||||
|
$path = $matches['path'];
|
||||||
|
// Check read/write rights
|
||||||
|
$new_path = $this->haveAccess($username, $path, 'writable');
|
||||||
|
if ($new_path == false) {
|
||||||
|
$new_path = $this->haveAccess($username, $path, 'readonly');
|
||||||
|
if ($new_path == false) {
|
||||||
|
throw new Exception('Repository read access denied.');
|
||||||
|
}
|
||||||
|
if (in_array($verb, $this->commands_write)) {
|
||||||
|
throw new Exception('Repository write access denied.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list($topdir, $relpath) = $new_path;
|
||||||
|
$repopath = sprintf('%s.git', $relpath);
|
||||||
|
$fullpath = $topdir.DIRECTORY_SEPARATOR.$repopath;
|
||||||
|
if (!file_exists($fullpath)
|
||||||
|
and in_array($verb, $this->commands_write)) {
|
||||||
|
// it doesn't exist on the filesystem, but the
|
||||||
|
// configuration refers to it, we're serving a write
|
||||||
|
// request, and the user is authorized to do that: create
|
||||||
|
// the repository on the fly
|
||||||
|
$p = explode(DIRECTORY_SEPARATOR, $fullpath);
|
||||||
|
$mpath = implode(DIRECTORY_SEPARATOR, array_slice($p, 0, -1));
|
||||||
|
if (!file_exists($mpath)) {
|
||||||
|
mkdir($mpath, 0750, true);
|
||||||
|
}
|
||||||
|
$this->initRepository($fullpath);
|
||||||
|
$this->setGitExport($relpath, $fullpath);
|
||||||
|
}
|
||||||
|
$new_cmd = sprintf("%s '%s'", $verb, $fullpath);
|
||||||
|
Pluf_Log::info(array('IDF_Plugin_Git_Serve::serve', $username, $cmd, $new_cmd));
|
||||||
|
return $new_cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main function called by the serve script.
|
||||||
|
*/
|
||||||
|
public static function main($argv, $env)
|
||||||
|
{
|
||||||
|
if (count($argv) != 2) {
|
||||||
|
self::fatalError('Missing argument USER.');
|
||||||
|
}
|
||||||
|
$username = $argv[1];
|
||||||
|
umask(0022);
|
||||||
|
if (!isset($env['SSH_ORIGINAL_COMMAND'])) {
|
||||||
|
self::fatalError('Need SSH_ORIGINAL_COMMAND in environment.');
|
||||||
|
}
|
||||||
|
$cmd = $env['SSH_ORIGINAL_COMMAND'];
|
||||||
|
chdir(Pluf::f('idf_plugin_syncgit_git_home_dir', '/home/git'));
|
||||||
|
$serve = new IDF_Plugin_SyncGit_Serve();
|
||||||
|
try {
|
||||||
|
$new_cmd = $serve->serve($username, $cmd);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
self::fatalError($e->getMessage());
|
||||||
|
}
|
||||||
|
print $new_cmd;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control the access rights to the repository.
|
||||||
|
*
|
||||||
|
* @param string Username
|
||||||
|
* @param string Path including the possible .git
|
||||||
|
* @param string Type of access. 'readonly' or ('writable')
|
||||||
|
* @return mixed False or array(base_git_reps, relative path to repo)
|
||||||
|
*/
|
||||||
|
public function haveAccess($username, $path, $mode='writable')
|
||||||
|
{
|
||||||
|
if ('.git' == substr($path, -4)) {
|
||||||
|
$path = substr($path, 0, -4);
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('shortname=%s', array($path));
|
||||||
|
$projects = Pluf::factory('IDF_Project')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($projects->count() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$project = $projects[0];
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
$scm = $conf->getVal('scm', 'git');
|
||||||
|
if ($scm != 'git') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('login=%s', array($username));
|
||||||
|
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() != 1 or !$users[0]->active) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$user = $users[0];
|
||||||
|
$request = new StdClass();
|
||||||
|
$request->user = $user;
|
||||||
|
$request->conf = $conf;
|
||||||
|
$request->project = $project;
|
||||||
|
if (true === IDF_Precondition::accessSource($request)) {
|
||||||
|
if ($mode == 'readonly') {
|
||||||
|
return array(Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories'),
|
||||||
|
$project->shortname);
|
||||||
|
}
|
||||||
|
if (true === IDF_Precondition::projectMemberOrOwner($request)) {
|
||||||
|
return array(Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories'),
|
||||||
|
$project->shortname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die on a message on stderr.
|
||||||
|
*
|
||||||
|
* @param string Message
|
||||||
|
*/
|
||||||
|
public static function fatalError($mess)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, $mess."\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init a new empty bare repository.
|
||||||
|
*
|
||||||
|
* @param string Full path to the repository
|
||||||
|
*/
|
||||||
|
public function initRepository($fullpath)
|
||||||
|
{
|
||||||
|
if (!file_exists($fullpath)) {
|
||||||
|
mkdir($fullpath, 0750, true);
|
||||||
|
}
|
||||||
|
$out = array();
|
||||||
|
$res = 0;
|
||||||
|
exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').
|
||||||
|
Pluf::f('git_path', 'git').' --git-dir=%s init', escapeshellarg($fullpath)),
|
||||||
|
$out, $res);
|
||||||
|
if ($res != 0) {
|
||||||
|
Pluf_Log::error(array('IDF_Plugin_Git_Serve::initRepository', $res, $fullpath));
|
||||||
|
throw new Exception(sprintf('Init repository error, exit status %d.', $res));
|
||||||
|
}
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_Git_Serve::initRepository', 'success', $fullpath));
|
||||||
|
// Add the post-update hook by removing the original one and add the
|
||||||
|
// Indefero's one.
|
||||||
|
$p = realpath(dirname(__FILE__).'/../../../../scripts/git-post-update');
|
||||||
|
$p = Pluf::f('idf_plugin_syncgit_post_update', $p);
|
||||||
|
$post_update_hook = $fullpath.'/hooks/post-update';
|
||||||
|
if (file_exists($post_update_hook) && !@unlink($post_update_hook)) {
|
||||||
|
Pluf_Log::warn(array('IDF_Plugin_Git_Serve::initRepository',
|
||||||
|
'post-update hook removal error.',
|
||||||
|
$post_update_hook));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$out = array();
|
||||||
|
$res = 0;
|
||||||
|
exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').'ln -s %s %s',
|
||||||
|
escapeshellarg($p),
|
||||||
|
escapeshellarg($post_update_hook)),
|
||||||
|
$out, $res);
|
||||||
|
if ($res != 0) {
|
||||||
|
Pluf_Log::warn(array('IDF_Plugin_Git_Serve::initRepository',
|
||||||
|
'post-update hook creation error.',
|
||||||
|
$post_update_hook));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pluf_Log::debug(array('IDF_Plugin_Git_Serve::initRepository',
|
||||||
|
'Added post-update hook.', $fullpath));
|
||||||
|
// Configure the core.quotepath option
|
||||||
|
$quotepath = (Pluf::f('git_core_quotepath', true) == true) ? 'true' : 'false';
|
||||||
|
$out = array();
|
||||||
|
$res = 0;
|
||||||
|
exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').
|
||||||
|
Pluf::f('git_path', 'git').' config -f %s/config --add core.quotepath %s',
|
||||||
|
escapeshellarg($fullpath),
|
||||||
|
escapeshellarg($quotepath)
|
||||||
|
),
|
||||||
|
$out, $res);
|
||||||
|
if ($res != 0) {
|
||||||
|
Pluf_Log::warn(array('IDF_Plugin_Git_Serve::initRepository',
|
||||||
|
'core.quotepath configuration error.',
|
||||||
|
$quotepath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pluf_Log::debug(array('IDF_Plugin_Git_Serve::initRepository',
|
||||||
|
'core.quotepath configured.', $quotepath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the git export value.
|
||||||
|
*
|
||||||
|
* @param string Relative path of the repository (not .git)
|
||||||
|
* @param string Full path of the repository with .git
|
||||||
|
*/
|
||||||
|
public function setGitExport($relpath, $fullpath)
|
||||||
|
{
|
||||||
|
$sql = new Pluf_SQL('shortname=%s', array($relpath));
|
||||||
|
$projects = Pluf::factory('IDF_Project')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($projects->count() != 1 and file_exists($fullpath)) {
|
||||||
|
return $this->gitExportDeny($fullpath);
|
||||||
|
}
|
||||||
|
$project = $projects[0];
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
$scm = $conf->getVal('scm', 'git');
|
||||||
|
if ($scm == 'git' and !file_exists($fullpath)) {
|
||||||
|
// No repository yet, just skip
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($scm != 'git' or $project->private) {
|
||||||
|
return $this->gitExportDeny($fullpath);
|
||||||
|
}
|
||||||
|
if ('all' == $conf->getVal('source_access_rights', 'all')) {
|
||||||
|
return $this->gitExportAllow($fullpath);
|
||||||
|
}
|
||||||
|
return $this->gitExportDeny($fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the export flag.
|
||||||
|
*
|
||||||
|
* @param string Full path to the repository
|
||||||
|
*/
|
||||||
|
public function gitExportDeny($fullpath)
|
||||||
|
{
|
||||||
|
if (!file_exists($fullpath)) {
|
||||||
|
return; // Not created yet.
|
||||||
|
}
|
||||||
|
@unlink($fullpath.DIRECTORY_SEPARATOR.'git-daemon-export-ok');
|
||||||
|
if (file_exists($fullpath.DIRECTORY_SEPARATOR.'git-daemon-export-ok')) {
|
||||||
|
throw new Exception('Cannot remove git-daemon-export-ok file.');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the export flag.
|
||||||
|
*
|
||||||
|
* @param string Full path to the repository
|
||||||
|
*/
|
||||||
|
public function gitExportAllow($fullpath)
|
||||||
|
{
|
||||||
|
if (!file_exists($fullpath)) {
|
||||||
|
return; // Not created yet.
|
||||||
|
}
|
||||||
|
touch($fullpath.DIRECTORY_SEPARATOR.'git-daemon-export-ok');
|
||||||
|
if (!file_exists($fullpath.DIRECTORY_SEPARATOR.'git-daemon-export-ok')) {
|
||||||
|
throw new Exception('Cannot create git-daemon-export-ok file.');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
264
indefero/src/IDF/Plugin/SyncMercurial.php
Normal file
264
indefero/src/IDF/Plugin/SyncMercurial.php
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This classes is a plugin which allows to synchronise access rights
|
||||||
|
* between indefero and mercurial web-published repositories.
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncMercurial
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point of the plugin.
|
||||||
|
*/
|
||||||
|
static public function entry($signal, &$params)
|
||||||
|
{
|
||||||
|
// First check for the 3 mandatory config variables.
|
||||||
|
if (!Pluf::f('idf_plugin_syncmercurial_passwd_file', false) or
|
||||||
|
!Pluf::f('idf_plugin_syncmercurial_path', false) or
|
||||||
|
!Pluf::f('idf_plugin_syncmercurial_hgrc', false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
include_once 'File/Passwd/Authdigest.php';
|
||||||
|
$plug = new IDF_Plugin_SyncMercurial();
|
||||||
|
switch ($signal) {
|
||||||
|
case 'IDF_Project::created':
|
||||||
|
$plug->processMercurialCreate($params['project']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Project::membershipsUpdated':
|
||||||
|
$plug->processSyncAuthz($params['project']);
|
||||||
|
break;
|
||||||
|
case 'Pluf_User::passwordUpdated':
|
||||||
|
$plug->processSyncPasswd($params['user']);
|
||||||
|
break;
|
||||||
|
case 'hgchangegroup.php::run':
|
||||||
|
$plug->processSyncTimeline($params);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run hg init command to create the corresponding Mercurial
|
||||||
|
* repository.
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
* @return bool Success
|
||||||
|
*/
|
||||||
|
function processMercurialCreate($project)
|
||||||
|
{
|
||||||
|
if ($project->getConf()->getVal('scm') != 'mercurial') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$shortname = $project->shortname;
|
||||||
|
if (false===($mercurial_path=Pluf::f('idf_plugin_syncmercurial_path',false))) {
|
||||||
|
throw new Pluf_Exception_SettingError("'idf_plugin_syncmercurial_path' must be defined in your configuration file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($mercurial_path.'/'.$shortname)) {
|
||||||
|
throw new Exception(sprintf(__('The repository %s already exists.'),
|
||||||
|
$mercurial_path.'/'.$shortname));
|
||||||
|
}
|
||||||
|
$return = 0;
|
||||||
|
$output = array();
|
||||||
|
$cmd = sprintf(Pluf::f('hg_path', 'hg').' init %s',
|
||||||
|
escapeshellarg($mercurial_path.'/'.$shortname));
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
|
||||||
|
$ll = exec($cmd, $output, $return);
|
||||||
|
return ($return == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronise an user's password.
|
||||||
|
*
|
||||||
|
* @param Pluf_User
|
||||||
|
*/
|
||||||
|
function processSyncPasswd($user)
|
||||||
|
{
|
||||||
|
$passwd_file = Pluf::f('idf_plugin_syncmercurial_passwd_file');
|
||||||
|
if (!file_exists($passwd_file) or !is_writable($passwd_file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$ht = new File_Passwd_Authbasic($passwd_file);
|
||||||
|
$ht->load();
|
||||||
|
//$ht->setMode(Pluf::f('idf_plugin_syncmercurial_passwd_mode',
|
||||||
|
// FILE_PASSWD_SHA));
|
||||||
|
$ht->setMode("plain");
|
||||||
|
if ($ht->userExists($user->login)) {
|
||||||
|
$ht->changePasswd($user->login, "{SHA}" . $this->getMercurialPass($user));
|
||||||
|
} else {
|
||||||
|
$ht->addUser($user->login, "{SHA}" . $this->getMercurialPass($user));
|
||||||
|
}
|
||||||
|
$ht->save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronize the hgrc file and the passwd file for the project.
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
*/
|
||||||
|
function processSyncAuthz($project)
|
||||||
|
{
|
||||||
|
if ($project->getConf()->getVal('scm') != 'mercurial') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->SyncAccess($project);
|
||||||
|
$this->generateProjectPasswd($project);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the repository password for the user
|
||||||
|
*/
|
||||||
|
function getMercurialPass($user){
|
||||||
|
//echo $user->password.Pluf::f('secret_key');
|
||||||
|
# return base64_encode(sha1($_POST["password"], true));
|
||||||
|
#file_put_contents("/tmp/test3", "test");
|
||||||
|
//return sha1($_POST["password"], true);
|
||||||
|
//if (isset($_POST["password"])) return $_POST["password"];
|
||||||
|
//return $_POST["password"];
|
||||||
|
//file_put_contents("/tmp/test", $user->password.Pluf::f('secret_key'));
|
||||||
|
//file_put_contents("/tmp/test", $user->password);
|
||||||
|
//return substr(sha1($user->password.Pluf::f('secret_key')), 0, 8);
|
||||||
|
return $user->password;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For a particular project: update all passwd information
|
||||||
|
*/
|
||||||
|
function generateProjectPasswd($project)
|
||||||
|
{
|
||||||
|
$passwd_file = Pluf::f('idf_plugin_syncmercurial_passwd_file');
|
||||||
|
if (!file_exists($passwd_file) or !is_writable($passwd_file)) {
|
||||||
|
throw new Exception (sprintf(__('%s does not exist or is not writable.'), $passwd_file));
|
||||||
|
}
|
||||||
|
$ht = new File_Passwd_Authbasic($passwd_file);
|
||||||
|
//$ht->setMode(Pluf::f('idf_plugin_syncmercurial_passwd_mode',
|
||||||
|
// FILE_PASSWD_SHA));
|
||||||
|
$ht->setMode("plain");
|
||||||
|
$ht->load();
|
||||||
|
$mem = $project->getMembershipData();
|
||||||
|
$members = array_merge((array)$mem['members'], (array)$mem['owners'],
|
||||||
|
(array)$mem['authorized']);
|
||||||
|
foreach($members as $user) {
|
||||||
|
//file_put_contents("/tmp/test", $this->getMercurialPass($user));
|
||||||
|
if ($ht->userExists($user->login)) {
|
||||||
|
$ht->changePasswd($user->login, "{SHA}" . $this->getMercurialPass($user));
|
||||||
|
} else {
|
||||||
|
$ht->addUser($user->login, "{SHA}" . $this->getMercurialPass($user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ht->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the hgrc file
|
||||||
|
*/
|
||||||
|
function SyncAccess($project)
|
||||||
|
{
|
||||||
|
$shortname = $project->shortname;
|
||||||
|
$hgrc_file = Pluf::f('idf_plugin_syncmercurial_path').sprintf('/%s/.hg/hgrc', $shortname);
|
||||||
|
|
||||||
|
// Get allow_push list
|
||||||
|
$allow_push = '';
|
||||||
|
$mem = $project->getMembershipData();
|
||||||
|
foreach ($mem['owners'] as $v) {
|
||||||
|
$allow_push .= $v->login.' ';
|
||||||
|
}
|
||||||
|
foreach ($mem['members'] as $v) {
|
||||||
|
$allow_push .= $v->login.' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate hgrc content
|
||||||
|
if (is_file($hgrc_file)) {
|
||||||
|
$tmp_content = @parse_ini_file($hgrc_file, true, INI_SCANNER_RAW);
|
||||||
|
if ($tmp_content === false) {
|
||||||
|
throw new Exception('could not parse "'.$hgrc_file.'" because of syntax problems');
|
||||||
|
}
|
||||||
|
$tmp_content['web']['allow_push'] = $allow_push;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$tmp_content = Pluf::f('idf_plugin_syncmercurial_hgrc');
|
||||||
|
$tmp_content['web']['allow_push'] = $allow_push;
|
||||||
|
}
|
||||||
|
$fcontent = '';
|
||||||
|
foreach ($tmp_content as $key => $elem){
|
||||||
|
$fcontent .= '['.$key."]\n";
|
||||||
|
foreach ($elem as $key2 => $elem2){
|
||||||
|
$fcontent .= $key2.' = '.$elem2."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_put_contents($hgrc_file, $fcontent, LOCK_EX);
|
||||||
|
|
||||||
|
// Generate private repository config file
|
||||||
|
$private_file = Pluf::f('idf_plugin_syncmercurial_private_include');
|
||||||
|
$notify_file = Pluf::f('idf_plugin_syncmercurial_private_notify');
|
||||||
|
$fcontent = '';
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList() as $project) {
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
if ($project->private == true){
|
||||||
|
$mem = $project->getMembershipData();
|
||||||
|
$user = '';
|
||||||
|
foreach ($mem['owners'] as $v) {
|
||||||
|
$user .= $v->login.' ';
|
||||||
|
}
|
||||||
|
foreach ($mem['members'] as $v) {
|
||||||
|
$user .= $v->login.' ';
|
||||||
|
}
|
||||||
|
foreach ($mem['authorized'] as $v) {
|
||||||
|
$user .= $v->login.' ';
|
||||||
|
}
|
||||||
|
$fcontent .= '<Location '. sprintf(Pluf::f('idf_plugin_syncmercurial_private_url'), $project->shortname).'>'."\n";
|
||||||
|
$fcontent .= 'AuthType Basic'."\n";
|
||||||
|
$fcontent .= 'AuthName "Restricted"'."\n";
|
||||||
|
$fcontent .= sprintf('AuthUserFile %s', Pluf::f('idf_plugin_syncmercurial_passwd_file'))."\n";
|
||||||
|
$fcontent .= sprintf('Require user %s', $user)."\n";
|
||||||
|
$fcontent .= '</Location>'."\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_put_contents($private_file, $fcontent, LOCK_EX);
|
||||||
|
file_put_contents($notify_file, ' ', LOCK_EX);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the timeline in post commit.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function processSyncTimeline($params)
|
||||||
|
{
|
||||||
|
$pname = basename($params['rel_dir']);
|
||||||
|
try {
|
||||||
|
$project = IDF_Project::getOr404($pname);
|
||||||
|
} catch (Pluf_HTTP_Error404 $e) {
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'Project not found.', array($pname, $params)));
|
||||||
|
return false; // Project not found
|
||||||
|
}
|
||||||
|
// Now we have the project and can update the timeline
|
||||||
|
Pluf_Log::debug(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'Project found', $pname, $project->id));
|
||||||
|
IDF_Scm::syncTimeline($project, true);
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'sync', array($pname, $project->id)));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
911
indefero/src/IDF/Plugin/SyncMonotone.php
Normal file
911
indefero/src/IDF/Plugin/SyncMonotone.php
Normal file
@ -0,0 +1,911 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This classes is a plugin which allows to synchronise access rights
|
||||||
|
* between indefero and monotone usher setups.
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncMonotone
|
||||||
|
{
|
||||||
|
private $old_err_rep = 0;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->old_err_rep = error_reporting(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
error_reporting($this->old_err_rep);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point of the plugin.
|
||||||
|
*/
|
||||||
|
static public function entry($signal, &$params)
|
||||||
|
{
|
||||||
|
$plug = new IDF_Plugin_SyncMonotone();
|
||||||
|
switch ($signal) {
|
||||||
|
case 'IDF_Project::created':
|
||||||
|
$plug->processProjectCreate($params['project']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Project::membershipsUpdated':
|
||||||
|
$plug->processMembershipsUpdated($params['project']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Project::preDelete':
|
||||||
|
$plug->processProjectDelete($params['project']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Key::postSave':
|
||||||
|
$plug->processKeyCreate($params['key']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Key::preDelete':
|
||||||
|
$plug->processKeyDelete($params['key']);
|
||||||
|
break;
|
||||||
|
case 'mtnpostpush.php::run':
|
||||||
|
$plug->processSyncTimeline($params['project']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial steps to setup a new monotone project:
|
||||||
|
*
|
||||||
|
* 1) run mtn db init to initialize a new database underknees
|
||||||
|
* 'mtn_repositories'
|
||||||
|
* 2) create a new server key in the same directory
|
||||||
|
* 3) create a new client key for IDF and store it in the project conf
|
||||||
|
* 4) setup the configuration
|
||||||
|
* 5) add the database as new local server in the usher configuration
|
||||||
|
* 6) reload the running usher instance so it acknowledges the new server
|
||||||
|
*
|
||||||
|
* The initial right setup happens in processMembershipsUpdated()
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
*/
|
||||||
|
function processProjectCreate($project)
|
||||||
|
{
|
||||||
|
if ($project->getConf()->getVal('scm') != 'mtn') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Pluf::f('mtn_db_access', 'local') == 'local') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This guard cleans up on any kind of error, and here is how it works:
|
||||||
|
// As long as the guard is not committed, it keeps a reference to
|
||||||
|
// the given project. When the guard is destroyed and the reference
|
||||||
|
// is still present, it deletes the object. The deletion indirectly
|
||||||
|
// also calls into this plugin again, as the project delete hook
|
||||||
|
// will be called, that removes any changes we've made during the
|
||||||
|
// process.
|
||||||
|
$projectGuard = new IDF_Plugin_SyncMonotone_ModelGuard($project);
|
||||||
|
|
||||||
|
$projecttempl = Pluf::f('mtn_repositories', false);
|
||||||
|
if ($projecttempl === false) {
|
||||||
|
$this->_diagnoseProblem(
|
||||||
|
__('"mtn_repositories" must be defined in your configuration file')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$usher_config = Pluf::f('mtn_usher_conf', false);
|
||||||
|
if (!$usher_config || !is_writable($usher_config)) {
|
||||||
|
$this->_diagnoseProblem(
|
||||||
|
__('"mtn_usher_conf" does not exist or is not writable')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mtnpostpush = realpath(dirname(__FILE__) . '/../../../scripts/mtn-post-push');
|
||||||
|
if (!file_exists($mtnpostpush)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not find mtn-post-push script "%s"'), $mtnpostpush
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// check some static configuration files
|
||||||
|
$confdir = Pluf::f('mtn_confdir', false);
|
||||||
|
if ($confdir === false) {
|
||||||
|
$confdir = dirname(__FILE__).'/SyncMonotone/';
|
||||||
|
}
|
||||||
|
$confdir_contents = array(
|
||||||
|
'monotonerc.in',
|
||||||
|
'remote-automate-permissions.in',
|
||||||
|
'hooks.d/',
|
||||||
|
'hooks.d/indefero_authorize_remote_automate.lua',
|
||||||
|
'hooks.d/indefero_post_push.conf.in',
|
||||||
|
'hooks.d/indefero_post_push.lua',
|
||||||
|
);
|
||||||
|
// enable remote command execution of read-only commands
|
||||||
|
// only for public projects
|
||||||
|
if (!$project->private) {
|
||||||
|
// this is linked and not copied to be able to update
|
||||||
|
// the list of read-only commands on upgrades
|
||||||
|
$confdir_contents[] = 'hooks.d/indefero_authorize_remote_automate.conf';
|
||||||
|
}
|
||||||
|
|
||||||
|
// check whether we should handle additional files in the config directory
|
||||||
|
$confdir_extra_contents = Pluf::f('mtn_confdir_extra', false);
|
||||||
|
if ($confdir_extra_contents !== false) {
|
||||||
|
$confdir_contents =
|
||||||
|
array_merge($confdir_contents, $confdir_extra_contents);
|
||||||
|
}
|
||||||
|
foreach ($confdir_contents as $content) {
|
||||||
|
if (!file_exists($confdir.$content)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('The configuration file "%s" is missing'), $content
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$shortname = $project->shortname;
|
||||||
|
$projectpath = sprintf($projecttempl, $shortname);
|
||||||
|
if (file_exists($projectpath)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('The project path "%s" already exists'), $projectpath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!@mkdir($projectpath)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('The project path "%s" could not be created'),
|
||||||
|
$projectpath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// step 1) create a new database
|
||||||
|
//
|
||||||
|
$dbfile = $projectpath.'/database.mtn';
|
||||||
|
$cmd = sprintf('db init -d %s', escapeshellarg($dbfile));
|
||||||
|
$this->_mtn_exec($cmd);
|
||||||
|
|
||||||
|
//
|
||||||
|
// step 2) create a server key
|
||||||
|
//
|
||||||
|
// try to parse the key's domain part from the remote_url's host
|
||||||
|
// name, otherwise fall back to the configured Apache server name
|
||||||
|
$server = $_SERVER['SERVER_NAME'];
|
||||||
|
$remote_url = Pluf::f('mtn_remote_url');
|
||||||
|
if (($parsed = parse_url($remote_url)) !== false &&
|
||||||
|
!empty($parsed['host'])) {
|
||||||
|
$server = $parsed['host'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$serverkey = $shortname.'-server@'.$server;
|
||||||
|
$cmd = sprintf('au generate_key --confdir=%s %s ""',
|
||||||
|
escapeshellarg($projectpath),
|
||||||
|
escapeshellarg($serverkey)
|
||||||
|
);
|
||||||
|
$this->_mtn_exec($cmd);
|
||||||
|
|
||||||
|
//
|
||||||
|
// step 3) create a client key, and save it in IDF
|
||||||
|
//
|
||||||
|
$keydir = Pluf::f('tmp_folder').'/mtn-client-keys';
|
||||||
|
if (!file_exists($keydir)) {
|
||||||
|
if (!@mkdir($keydir)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('The key directory "%s" could not be created'),
|
||||||
|
$keydir
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientkey_name = $shortname.'-client@'.$server;
|
||||||
|
$cmd = sprintf('au generate_key --keydir=%s %s ""',
|
||||||
|
escapeshellarg($keydir),
|
||||||
|
escapeshellarg($clientkey_name)
|
||||||
|
);
|
||||||
|
$keyinfo = $this->_mtn_exec($cmd);
|
||||||
|
|
||||||
|
$parsed_keyinfo = array();
|
||||||
|
try {
|
||||||
|
$parsed_keyinfo = IDF_Scm_Monotone_BasicIO::parse($keyinfo);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not parse key information: %s'), $e->getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientkey_hash = $parsed_keyinfo[0][1]['hash'];
|
||||||
|
$clientkey_file = $keydir . '/' . $clientkey_name . '.' . $clientkey_hash;
|
||||||
|
$clientkey_data = file_get_contents($clientkey_file);
|
||||||
|
|
||||||
|
$project->getConf()->setVal('mtn_client_key_name', $clientkey_name);
|
||||||
|
$project->getConf()->setVal('mtn_client_key_hash', $clientkey_hash);
|
||||||
|
$project->getConf()->setVal('mtn_client_key_data', $clientkey_data);
|
||||||
|
|
||||||
|
// add the public client key to the server
|
||||||
|
$cmd = sprintf('au get_public_key --keydir=%s %s',
|
||||||
|
escapeshellarg($keydir),
|
||||||
|
escapeshellarg($clientkey_hash)
|
||||||
|
);
|
||||||
|
$clientkey_pubdata = $this->_mtn_exec($cmd);
|
||||||
|
|
||||||
|
$cmd = sprintf('au put_public_key --db=%s %s',
|
||||||
|
escapeshellarg($dbfile),
|
||||||
|
escapeshellarg($clientkey_pubdata)
|
||||||
|
);
|
||||||
|
$this->_mtn_exec($cmd);
|
||||||
|
|
||||||
|
//
|
||||||
|
// step 4) setup the configuration
|
||||||
|
//
|
||||||
|
|
||||||
|
// we assume that all confdir entries ending with a slash mean a
|
||||||
|
// directory that has to be created, that all files ending on ".in"
|
||||||
|
// have to be processed and copied in place and that all other files
|
||||||
|
// just need to be symlinked from the original location
|
||||||
|
foreach ($confdir_contents as $content) {
|
||||||
|
$filepath = $projectpath.'/'.$content;
|
||||||
|
if (substr($content, -1) == '/') {
|
||||||
|
if (!@mkdir($filepath)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not create configuration directory "%s"'),
|
||||||
|
$filepath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($content, -3) != '.in') {
|
||||||
|
if (!@symlink($confdir.$content, $filepath)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not create symlink for configuration file "%s"'),
|
||||||
|
$filepath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filecontents = file_get_contents($confdir.'/'.$content);
|
||||||
|
$filecontents = str_replace(
|
||||||
|
array('%%MTNPOSTPUSH%%', '%%PROJECT%%', '%%MTNCLIENTKEY%%'),
|
||||||
|
array($mtnpostpush, $shortname, $clientkey_hash),
|
||||||
|
$filecontents
|
||||||
|
);
|
||||||
|
|
||||||
|
// remove the .in
|
||||||
|
$filepath = substr($filepath, 0, -3);
|
||||||
|
if (@file_put_contents($filepath, $filecontents, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write configuration file "%s"'),
|
||||||
|
$filepath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// step 5) read in and append the usher config with the new server
|
||||||
|
//
|
||||||
|
$usher_rc = file_get_contents($usher_config);
|
||||||
|
$parsed_config = array();
|
||||||
|
try {
|
||||||
|
$parsed_config = IDF_Scm_Monotone_BasicIO::parse($usher_rc);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not parse usher configuration in "%1$s": %2$s'),
|
||||||
|
$usher_config, $e->getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure we haven't configured a server with this name already
|
||||||
|
foreach ($parsed_config as $stanzas) {
|
||||||
|
foreach ($stanzas as $stanza_line) {
|
||||||
|
if ($stanza_line['key'] == 'server' &&
|
||||||
|
$stanza_line['values'][0] == $shortname) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('usher configuration already contains a server '.
|
||||||
|
'entry named "%s"'),
|
||||||
|
$shortname
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_server = array(
|
||||||
|
array('key' => 'server', 'values' => array($shortname)),
|
||||||
|
array('key' => 'local', 'values' => array(
|
||||||
|
'--confdir', $projectpath,
|
||||||
|
'-d', $dbfile,
|
||||||
|
'--timestamps',
|
||||||
|
'--ticker=dot'
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
$parsed_config[] = $new_server;
|
||||||
|
$usher_rc = IDF_Scm_Monotone_BasicIO::compile($parsed_config);
|
||||||
|
|
||||||
|
// FIXME: more sanity - what happens on failing writes? we do not
|
||||||
|
// have a backup copy of usher.conf around...
|
||||||
|
if (@file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write usher configuration file "%s"'),
|
||||||
|
$usher_config
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// step 6) reload usher to pick up the new configuration
|
||||||
|
//
|
||||||
|
IDF_Scm_Monotone_Usher::reload();
|
||||||
|
|
||||||
|
// commit the guard, so the newly created project is not deleted
|
||||||
|
$projectGuard->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the read / write permissions for the monotone database
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
*/
|
||||||
|
public function processMembershipsUpdated($project)
|
||||||
|
{
|
||||||
|
if ($project->getConf()->getVal('scm') != 'mtn') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Pluf::f('mtn_db_access', 'local') == 'local') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mtn = IDF_Scm_Monotone::factory($project);
|
||||||
|
$stdio = $mtn->getStdio();
|
||||||
|
|
||||||
|
$projectpath = $this->_get_project_path($project);
|
||||||
|
$auth_ids = $this->_get_authorized_user_ids($project);
|
||||||
|
$key_ids = array();
|
||||||
|
foreach ($auth_ids as $auth_id) {
|
||||||
|
$sql = new Pluf_SQL('user=%s', array($auth_id));
|
||||||
|
$keys = Pluf::factory('IDF_Key')->getList(array('filter' => $sql->gen()));
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if ($key->getType() != 'mtn')
|
||||||
|
continue;
|
||||||
|
$stdio->exec(array('put_public_key', $key->content));
|
||||||
|
$key_ids[] = $key->getMtnId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$write_permissions = implode("\n", $key_ids);
|
||||||
|
$rcfile = $projectpath.'/write-permissions';
|
||||||
|
if (@file_put_contents($rcfile, $write_permissions, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write write-permissions file "%s"'),
|
||||||
|
$rcfile
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($project->private) {
|
||||||
|
$stanza = array(
|
||||||
|
array('key' => 'pattern', 'values' => array('*')),
|
||||||
|
);
|
||||||
|
foreach ($key_ids as $key_id)
|
||||||
|
{
|
||||||
|
$stanza[] = array('key' => 'allow', 'values' => array($key_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$stanza = array(
|
||||||
|
array('key' => 'pattern', 'values' => array('*')),
|
||||||
|
array('key' => 'allow', 'values' => array('*')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$read_permissions = IDF_Scm_Monotone_BasicIO::compile(array($stanza));
|
||||||
|
$rcfile = $projectpath.'/read-permissions';
|
||||||
|
if (@file_put_contents($rcfile, $read_permissions, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write read-permissions file "%s"'),
|
||||||
|
$rcfile
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// link / unlink the read-only automate permissions for the project
|
||||||
|
$confdir = Pluf::f('mtn_confdir', false);
|
||||||
|
if ($confdir === false) {
|
||||||
|
$confdir = dirname(__FILE__).'/SyncMonotone/';
|
||||||
|
}
|
||||||
|
$file = 'hooks.d/indefero_authorize_remote_automate.conf';
|
||||||
|
$projectfile = $projectpath.'/'.$file;
|
||||||
|
$templatefile = $confdir.'/'.$file;
|
||||||
|
|
||||||
|
$serverRestartRequired = false;
|
||||||
|
if ($project->private && file_exists($projectfile) && is_link($projectfile)) {
|
||||||
|
if (!@unlink($projectfile)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not remove symlink "%s"'), $projectfile
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$serverRestartRequired = true;
|
||||||
|
} else
|
||||||
|
if (!$project->private && !file_exists($projectfile)) {
|
||||||
|
if (!@symlink($templatefile, $projectfile)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not create symlink "%s"'), $projectfile
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$serverRestartRequired = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($serverRestartRequired) {
|
||||||
|
// FIXME: we should actually use stopServer() here, but this
|
||||||
|
// seems to be ignored when the server should be started
|
||||||
|
// again immediately afterwards
|
||||||
|
IDF_Scm_Monotone_Usher::killServer($project->shortname);
|
||||||
|
// give usher some time to cool down, otherwise it might hang
|
||||||
|
// (see https://code.monotone.ca/p/contrib/issues/175/)
|
||||||
|
sleep(2);
|
||||||
|
IDF_Scm_Monotone_Usher::startServer($project->shortname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up after a mtn project was deleted
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
*/
|
||||||
|
public function processProjectDelete($project)
|
||||||
|
{
|
||||||
|
if ($project->getConf()->getVal('scm') != 'mtn') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Pluf::f('mtn_db_access', 'local') == 'local') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$usher_config = Pluf::f('mtn_usher_conf', false);
|
||||||
|
if (!$usher_config || !is_writable($usher_config)) {
|
||||||
|
$this->_diagnoseProblem(
|
||||||
|
__('"mtn_usher_conf" does not exist or is not writable')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$shortname = $project->shortname;
|
||||||
|
IDF_Scm_Monotone_Usher::killServer($shortname);
|
||||||
|
|
||||||
|
$projecttempl = Pluf::f('mtn_repositories', false);
|
||||||
|
if ($projecttempl === false) {
|
||||||
|
$this->_diagnoseProblem(
|
||||||
|
__('"mtn_repositories" must be defined in your configuration file')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$projectpath = sprintf($projecttempl, $shortname);
|
||||||
|
if (file_exists($projectpath)) {
|
||||||
|
if (!$this->_delete_recursive($projectpath)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('One or more paths underneath %s could not be deleted'), $projectpath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$keydir = Pluf::f('tmp_folder').'/mtn-client-keys';
|
||||||
|
$keyname = $project->getConf()->getVal('mtn_client_key_name', false);
|
||||||
|
$keyhash = $project->getConf()->getVal('mtn_client_key_hash', false);
|
||||||
|
if ($keyname && $keyhash &&
|
||||||
|
file_exists($keydir .'/'. $keyname . '.' . $keyhash)) {
|
||||||
|
if (!@unlink($keydir .'/'. $keyname . '.' . $keyhash)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not delete client private key "%s"'),
|
||||||
|
$keyname
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$usher_rc = file_get_contents($usher_config);
|
||||||
|
$parsed_config = array();
|
||||||
|
try {
|
||||||
|
$parsed_config = IDF_Scm_Monotone_BasicIO::parse($usher_rc);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not parse usher configuration in "%1$s": %2$s'),
|
||||||
|
$usher_config, $e->getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($parsed_config as $idx => $stanzas) {
|
||||||
|
foreach ($stanzas as $stanza_line) {
|
||||||
|
if ($stanza_line['key'] == 'server' &&
|
||||||
|
$stanza_line['values'][0] == $shortname) {
|
||||||
|
unset($parsed_config[$idx]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$usher_rc = IDF_Scm_Monotone_BasicIO::compile($parsed_config);
|
||||||
|
|
||||||
|
// FIXME: more sanity - what happens on failing writes? we do not
|
||||||
|
// have a backup copy of usher.conf around...
|
||||||
|
if (@file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write usher configuration file "%s"'),
|
||||||
|
$usher_config
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
IDF_Scm_Monotone_Usher::reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the (monotone) key to all monotone projects of this forge
|
||||||
|
* where the user of the key has write access to
|
||||||
|
*/
|
||||||
|
public function processKeyCreate($key)
|
||||||
|
{
|
||||||
|
if ($key->getType() != 'mtn') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Pluf::f('mtn_db_access', 'local') == 'local') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keyGuard = new IDF_Plugin_SyncMonotone_ModelGuard($key);
|
||||||
|
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList() as $project) {
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
$scm = $conf->getVal('scm', 'mtn');
|
||||||
|
if ($scm != 'mtn')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$projectpath = $this->_get_project_path($project);
|
||||||
|
$auth_ids = $this->_get_authorized_user_ids($project);
|
||||||
|
if (!in_array($key->user, $auth_ids))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$mtn_key_id = $key->getMtnId();
|
||||||
|
|
||||||
|
// if the project is not defined as private, all people have
|
||||||
|
// read access already, so we don't need to write anything
|
||||||
|
// and we currently do not check if read-permissions really
|
||||||
|
// contains
|
||||||
|
// pattern "*"
|
||||||
|
// allow "*"
|
||||||
|
// which is the default for non-private projects
|
||||||
|
if ($project->private == true) {
|
||||||
|
$read_perms = file_get_contents($projectpath.'/read-permissions');
|
||||||
|
$parsed_read_perms = array();
|
||||||
|
try {
|
||||||
|
$parsed_read_perms = IDF_Scm_Monotone_BasicIO::parse($read_perms);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not parse read-permissions for project "%1$s": %2$s'),
|
||||||
|
$shortname, $e->getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$wildcard_section = null;
|
||||||
|
for ($i=0; $i<count($parsed_read_perms); ++$i) {
|
||||||
|
foreach ($parsed_read_perms[$i] as $stanza_line) {
|
||||||
|
if ($stanza_line['key'] == 'pattern' &&
|
||||||
|
$stanza_line['values'][0] == '*') {
|
||||||
|
$wildcard_section =& $parsed_read_perms[$i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($wildcard_section == null)
|
||||||
|
{
|
||||||
|
$wildcard_section = array(
|
||||||
|
array('key' => 'pattern', 'values' => array('*'))
|
||||||
|
);
|
||||||
|
$parsed_read_perms[] =& $wildcard_section;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key_found = false;
|
||||||
|
foreach ($wildcard_section as $line)
|
||||||
|
{
|
||||||
|
if ($line['key'] == 'allow' && $line['values'][0] == $mtn_key_id) {
|
||||||
|
$key_found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$key_found) {
|
||||||
|
$wildcard_section[] = array(
|
||||||
|
'key' => 'allow', 'values' => array($mtn_key_id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$read_perms = IDF_Scm_Monotone_BasicIO::compile($parsed_read_perms);
|
||||||
|
|
||||||
|
if (@file_put_contents($projectpath.'/read-permissions',
|
||||||
|
$read_perms, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write read-permissions for project "%s"'),
|
||||||
|
$shortname
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$write_perms = file_get_contents($projectpath.'/write-permissions');
|
||||||
|
$lines = preg_split("/(\n|\r\n)/", $write_perms, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
if (!in_array('*', $lines) && !in_array($mtn_key_id, $lines)) {
|
||||||
|
$lines[] = $mtn_key_id;
|
||||||
|
}
|
||||||
|
if (@file_put_contents($projectpath.'/write-permissions',
|
||||||
|
implode("\n", $lines) . "\n", LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write write-permissions file for project "%s"'),
|
||||||
|
$shortname
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$mtn = IDF_Scm_Monotone::factory($project);
|
||||||
|
$stdio = $mtn->getStdio();
|
||||||
|
$stdio->exec(array('put_public_key', $key->content));
|
||||||
|
}
|
||||||
|
|
||||||
|
$keyGuard->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the (monotone) key from all monotone projects of this forge
|
||||||
|
* where the user of the key has write access to
|
||||||
|
*/
|
||||||
|
public function processKeyDelete($key)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if ($key->getType() != 'mtn') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// bad key type, skip it.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Pluf::f('mtn_db_access', 'local') == 'local') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList() as $project) {
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
$scm = $conf->getVal('scm', 'mtn');
|
||||||
|
if ($scm != 'mtn')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$projectpath = $this->_get_project_path($project);
|
||||||
|
$auth_ids = $this->_get_authorized_user_ids($project);
|
||||||
|
if (!in_array($key->user, $auth_ids))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$mtn_key_id = $key->getMtnId();
|
||||||
|
|
||||||
|
// if the project is not defined as private, all people have
|
||||||
|
// read access already, so we don't need to write anything
|
||||||
|
// and we currently do not check if read-permissions really
|
||||||
|
// contains
|
||||||
|
// pattern "*"
|
||||||
|
// allow "*"
|
||||||
|
// which is the default for non-private projects
|
||||||
|
if ($project->private) {
|
||||||
|
$read_perms = file_get_contents($projectpath.'/read-permissions');
|
||||||
|
$parsed_read_perms = array();
|
||||||
|
try {
|
||||||
|
$parsed_read_perms = IDF_Scm_Monotone_BasicIO::parse($read_perms);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not parse read-permissions for project "%1$s": %2$s'),
|
||||||
|
$shortname, $e->getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// while we add new keys only to an existing wild-card entry
|
||||||
|
// we remove dropped keys from all sections since the key
|
||||||
|
// should be simply unavailable for all of them
|
||||||
|
for ($h=0; $h<count($parsed_read_perms); ++$h) {
|
||||||
|
for ($i=0; $i<count($parsed_read_perms[$h]); ++$i) {
|
||||||
|
if ($parsed_read_perms[$h][$i]['key'] == 'allow' &&
|
||||||
|
$parsed_read_perms[$h][$i]['values'][0] == $mtn_key_id) {
|
||||||
|
unset($parsed_read_perms[$h][$i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$read_perms = IDF_Scm_Monotone_BasicIO::compile($parsed_read_perms);
|
||||||
|
|
||||||
|
if (@file_put_contents($projectpath.'/read-permissions',
|
||||||
|
$read_perms, LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write read-permissions for project "%s"'),
|
||||||
|
$shortname
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$write_perms = file_get_contents($projectpath.'/write-permissions');
|
||||||
|
$lines = preg_split("/(\n|\r\n)/", $write_perms, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
for ($i=0; $i<count($lines); ++$i) {
|
||||||
|
if ($lines[$i] == $mtn_key_id) {
|
||||||
|
unset($lines[$i]);
|
||||||
|
// the key should actually only exist once in the
|
||||||
|
// file, but we're paranoid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (@file_put_contents($projectpath.'/write-permissions',
|
||||||
|
implode("\n", $lines) . "\n", LOCK_EX) === false) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('Could not write write-permissions file for project "%s"'),
|
||||||
|
$shortname
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$mtn = IDF_Scm_Monotone::factory($project);
|
||||||
|
$stdio = $mtn->getStdio();
|
||||||
|
// if the public key did not sign any revisions, drop it from
|
||||||
|
// the database as well
|
||||||
|
try {
|
||||||
|
if (strlen($stdio->exec(array('select', 'k:' . $mtn_key_id))) == 0) {
|
||||||
|
$stdio->exec(array('drop_public_key', $mtn_key_id));
|
||||||
|
}
|
||||||
|
} catch (IDF_Scm_Exception $e) {
|
||||||
|
if (strpos($e->getMessage(), 'there is no key named') === false)
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the timeline after a push
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function processSyncTimeline($project_name)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$project = IDF_Project::getOr404($project_name);
|
||||||
|
} catch (Pluf_HTTP_Error404 $e) {
|
||||||
|
Pluf_Log::event(array(
|
||||||
|
'IDF_Plugin_SyncMonotone::processSyncTimeline',
|
||||||
|
'Project not found.',
|
||||||
|
array($project_name, $params)
|
||||||
|
));
|
||||||
|
return false; // Project not found
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Log::debug(array(
|
||||||
|
'IDF_Plugin_SyncMonotone::processSyncTimeline',
|
||||||
|
'Project found', $project_name, $project->id
|
||||||
|
));
|
||||||
|
IDF_Scm::syncTimeline($project, true);
|
||||||
|
Pluf_Log::event(array(
|
||||||
|
'IDF_Plugin_SyncMonotone::processSyncTimeline',
|
||||||
|
'sync', array($project_name, $project->id)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _get_project_path($project)
|
||||||
|
{
|
||||||
|
$projecttempl = Pluf::f('mtn_repositories', false);
|
||||||
|
if ($projecttempl === false) {
|
||||||
|
$this->_diagnoseProblem(
|
||||||
|
__('"mtn_repositories" must be defined in your configuration file.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$projectpath = sprintf($projecttempl, $project->shortname);
|
||||||
|
if (!file_exists($projectpath)) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('The project path %s does not exists.'), $projectpath
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return $projectpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _mtn_exec($cmd)
|
||||||
|
{
|
||||||
|
$fullcmd = sprintf('%s %s %s',
|
||||||
|
Pluf::f('idf_exec_cmd_prefix', ''),
|
||||||
|
Pluf::f('mtn_path', 'mtn'),
|
||||||
|
$cmd
|
||||||
|
);
|
||||||
|
|
||||||
|
$output = $return = null;
|
||||||
|
exec($fullcmd, $output, $return);
|
||||||
|
if ($return != 0) {
|
||||||
|
$this->_diagnoseProblem(sprintf(
|
||||||
|
__('The command "%s" could not be executed.'), $cmd
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return implode("\n", $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _get_authorized_user_ids($project)
|
||||||
|
{
|
||||||
|
$mem = $project->getMembershipData();
|
||||||
|
$members = array_merge((array)$mem['members'],
|
||||||
|
(array)$mem['owners'],
|
||||||
|
(array)$mem['authorized']);
|
||||||
|
$userids = array();
|
||||||
|
foreach ($members as $member) {
|
||||||
|
$userids[] = $member->id;
|
||||||
|
}
|
||||||
|
return $userids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _delete_recursive($path)
|
||||||
|
{
|
||||||
|
if (is_file($path) || is_link($path)) {
|
||||||
|
return @unlink($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($path)) {
|
||||||
|
$scan = glob(rtrim($path, '/') . '/*');
|
||||||
|
$status = 0;
|
||||||
|
foreach ($scan as $subpath) {
|
||||||
|
$status |= $this->_delete_recursive($subpath);
|
||||||
|
}
|
||||||
|
$status |= @rmdir($path);
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _diagnoseProblem($msg)
|
||||||
|
{
|
||||||
|
$system_err = error_get_last();
|
||||||
|
if (!empty($system_err)) {
|
||||||
|
$msg .= ': '.$system_err['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
error_reporting($this->old_err_rep);
|
||||||
|
throw new IDF_Scm_Exception($msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple helper class that deletes the model instance if
|
||||||
|
* it is not committed
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncMonotone_ModelGuard
|
||||||
|
{
|
||||||
|
private $model;
|
||||||
|
|
||||||
|
public function __construct(Pluf_Model $m)
|
||||||
|
{
|
||||||
|
$this->model = $m;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
if ($this->model == null)
|
||||||
|
return;
|
||||||
|
$this->model->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function commit()
|
||||||
|
{
|
||||||
|
$this->model = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
ARA_safe_commands = {
|
||||||
|
"get_corresponding_path", "get_content_changed", "tags", "branches",
|
||||||
|
"common_ancestors", "packet_for_fdelta", "packet_for_fdata",
|
||||||
|
"packets_for_certs", "packet_for_rdata", "get_manifest_of",
|
||||||
|
"get_revision", "select", "graph", "children", "parents", "roots",
|
||||||
|
"leaves", "ancestry_difference", "toposort", "erase_ancestors",
|
||||||
|
"descendents", "ancestors", "heads", "get_file_of", "get_file",
|
||||||
|
"interface_version", "get_attributes", "content_diff",
|
||||||
|
"file_merge", "show_conflicts", "certs", "keys", "get_extended_manifest_of"
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
-- ***** BEGIN LICENSE BLOCK *****
|
||||||
|
-- This file is part of InDefero, an open source project management application.
|
||||||
|
-- Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
-- Copyright (C) 2010 Thomas Keller <me@thomaskeller.biz>
|
||||||
|
-- Richard Levitte <richard@levitte.org>
|
||||||
|
--
|
||||||
|
-- InDefero is free software; you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as published by
|
||||||
|
-- the Free Software Foundation; either version 2 of the License, or
|
||||||
|
-- (at your option) any later version.
|
||||||
|
--
|
||||||
|
-- InDefero is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU General Public License for more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License
|
||||||
|
-- along with this program; if not, write to the Free Software
|
||||||
|
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
--
|
||||||
|
-- ***** END LICENSE BLOCK *****
|
||||||
|
|
||||||
|
--
|
||||||
|
-- This script reads key identities from a file "remote-automate-permissions"
|
||||||
|
-- in the configuration directory and permits those authenticating with one
|
||||||
|
-- of those keys to perform dangerous (read/write) remote automate operations.
|
||||||
|
-- The format of the file is very simple, one key identity on every line.
|
||||||
|
-- Lines starting with # are ignore, as well as empty lines.
|
||||||
|
--
|
||||||
|
-- It's possible to configure this script to allow the performance of some
|
||||||
|
-- remote automate commands anonymously, through the variable
|
||||||
|
-- ARA_safe_commands, which has to be a table of commands as strings.
|
||||||
|
-- One example configuration, taken from the setup at code.monotone.ca, could
|
||||||
|
-- be this:
|
||||||
|
--
|
||||||
|
-- ARA_safe_commands = {
|
||||||
|
-- "get_corresponding_path", "get_content_changed", "tags", "branches",
|
||||||
|
-- "common_ancestors", "packet_for_fdelta", "packet_for_fdata",
|
||||||
|
-- "packets_for_certs", "packet_for_rdata", "get_manifest_of",
|
||||||
|
-- "get_revision", "select", "graph", "children", "parents", "roots",
|
||||||
|
-- "leaves", "ancestry_difference", "toposort", "erase_ancestors",
|
||||||
|
-- "descendents", "ancestors", "heads", "get_file_of", "get_file",
|
||||||
|
-- "interface_version", "get_attributes", "content_diff",
|
||||||
|
-- "file_merge", "show_conflicts", "certs", "keys", "get_extended_manifest_of"
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
do
|
||||||
|
local _safe_commands = {}
|
||||||
|
if ARA_safe_commands then
|
||||||
|
_safe_commands = ARA_safe_commands
|
||||||
|
end
|
||||||
|
|
||||||
|
local _save_get_remote_automate_permitted = get_remote_automate_permitted
|
||||||
|
function get_remote_automate_permitted(key_identity, command, options)
|
||||||
|
local permfile =
|
||||||
|
io.open(get_confdir() .. "/remote-automate-permissions", "r")
|
||||||
|
if (permfile == nil) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- See if the incoming key matches any of the key identities or
|
||||||
|
-- patterns found in the permissions file.
|
||||||
|
local matches = false
|
||||||
|
local line = permfile:read()
|
||||||
|
while (not matches and line ~= nil) do
|
||||||
|
if not globish_match("#*", line) then
|
||||||
|
local _, _, ln = string.find(line, "%s*([^%s]*)%s*")
|
||||||
|
if ln == "*" then matches = true end
|
||||||
|
if ln == key_identity.id then matches = true end
|
||||||
|
if globish_match(ln, key_identity.name) then matches = true end
|
||||||
|
line = permfile:read()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
io.close(permfile)
|
||||||
|
if matches then return true end
|
||||||
|
|
||||||
|
-- No matching key found, let's see if the command matches one the
|
||||||
|
-- admin allowed to be performed anonymously
|
||||||
|
for _,v in ipairs(_safe_commands) do
|
||||||
|
if (v == command[1]) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- No matches found anywhere, then don't permit this operation
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
IDF_project = "%%PROJECT%%"
|
||||||
|
IDF_push_script = "%%MTNPOSTPUSH%%"
|
@ -0,0 +1,58 @@
|
|||||||
|
-- ***** BEGIN LICENSE BLOCK *****
|
||||||
|
-- This file is part of InDefero, an open source project management application.
|
||||||
|
-- Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
--
|
||||||
|
-- InDefero is free software; you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as published by
|
||||||
|
-- the Free Software Foundation; either version 2 of the License, or
|
||||||
|
-- (at your option) any later version.
|
||||||
|
--
|
||||||
|
-- InDefero is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU General Public License for more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License
|
||||||
|
-- along with this program; if not, write to the Free Software
|
||||||
|
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
--
|
||||||
|
-- ***** END LICENSE BLOCK *****
|
||||||
|
|
||||||
|
--
|
||||||
|
-- let IDF know of new arriving revisions to fill its timeline
|
||||||
|
--
|
||||||
|
_idf_revs = {}
|
||||||
|
push_hook_functions(
|
||||||
|
{
|
||||||
|
start =
|
||||||
|
function (session_id)
|
||||||
|
_idf_revs[session_id] = {}
|
||||||
|
return "continue",nil
|
||||||
|
end,
|
||||||
|
revision_received =
|
||||||
|
function (new_id, revision, certs, session_id)
|
||||||
|
table.insert(_idf_revs[session_id], new_id)
|
||||||
|
return "continue",nil
|
||||||
|
end,
|
||||||
|
["end"] =
|
||||||
|
function (session_id, ...)
|
||||||
|
if table.getn(_idf_revs[session_id]) == 0 then
|
||||||
|
return "continue",nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local pin,pout,pid = spawn_pipe(IDF_push_script, IDF_project);
|
||||||
|
if pid == -1 then
|
||||||
|
print("could not execute " .. IDF_push_script)
|
||||||
|
return "continue",nil
|
||||||
|
end
|
||||||
|
|
||||||
|
for _,r in ipairs(_idf_revs[session_id]) do
|
||||||
|
pin:write(r .. "\n")
|
||||||
|
end
|
||||||
|
pin:close()
|
||||||
|
|
||||||
|
wait(pid)
|
||||||
|
return "continue",nil
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
30
indefero/src/IDF/Plugin/SyncMonotone/monotonerc.in
Normal file
30
indefero/src/IDF/Plugin/SyncMonotone/monotonerc.in
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
-- ***** BEGIN LICENSE BLOCK *****
|
||||||
|
-- This file is part of InDefero, an open source project management application.
|
||||||
|
-- Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
--
|
||||||
|
-- InDefero is free software; you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as published by
|
||||||
|
-- the Free Software Foundation; either version 2 of the License, or
|
||||||
|
-- (at your option) any later version.
|
||||||
|
--
|
||||||
|
-- InDefero is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU General Public License for more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License
|
||||||
|
-- along with this program; if not, write to the Free Software
|
||||||
|
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
--
|
||||||
|
-- ***** END LICENSE BLOCK *****
|
||||||
|
|
||||||
|
---- Load local hooks if they exist.
|
||||||
|
-- The way this is supposed to work is that hooks.d can contain symbolic
|
||||||
|
-- links to lua scripts. These links MUST have the extension .lua
|
||||||
|
-- If the script needs some configuration, a corresponding file with
|
||||||
|
-- the extension .conf is the right spot.
|
||||||
|
----
|
||||||
|
-- First load the configuration of the hooks, if applicable
|
||||||
|
includedirpattern(get_confdir() .. "/hooks.d/","*.conf")
|
||||||
|
-- Then load the hooks themselves
|
||||||
|
includedirpattern(get_confdir() .. "/hooks.d/","*.lua")
|
@ -0,0 +1 @@
|
|||||||
|
%%MTNCLIENTKEY%%
|
294
indefero/src/IDF/Plugin/SyncSvn.php
Normal file
294
indefero/src/IDF/Plugin/SyncSvn.php
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This classes is a plugin which allows to synchronise access rights
|
||||||
|
* between indefero and a DAV powered Subversion repository.
|
||||||
|
*/
|
||||||
|
class IDF_Plugin_SyncSvn
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point of the plugin.
|
||||||
|
*/
|
||||||
|
static public function entry($signal, &$params)
|
||||||
|
{
|
||||||
|
// First check for the 3 mandatory config variables.
|
||||||
|
if (!Pluf::f('idf_plugin_syncsvn_authz_file', false) or
|
||||||
|
!Pluf::f('idf_plugin_syncsvn_passwd_file', false) or
|
||||||
|
!Pluf::f('idf_plugin_syncsvn_svn_path', false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
include_once 'File/Passwd/Authdigest.php'; // $ pear install File_Passwd
|
||||||
|
$plug = new IDF_Plugin_SyncSvn();
|
||||||
|
switch ($signal) {
|
||||||
|
case 'IDF_Project::created':
|
||||||
|
$plug->processSvnCreate($params['project']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Project::membershipsUpdated':
|
||||||
|
$plug->processSyncAuthz($params['project']);
|
||||||
|
break;
|
||||||
|
case 'Pluf_User::passwordUpdated':
|
||||||
|
$plug->processSyncPasswd($params['user']);
|
||||||
|
break;
|
||||||
|
case 'IDF_Project::preDelete':
|
||||||
|
$plug->processSvnDelete($params['project']);
|
||||||
|
break;
|
||||||
|
case 'svnpostcommit.php::run':
|
||||||
|
$plug->processSvnUpdateTimeline($params);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run svnadmin command to create the corresponding Subversion
|
||||||
|
* repository.
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
* @return bool Success
|
||||||
|
*/
|
||||||
|
function processSvnCreate($project)
|
||||||
|
{
|
||||||
|
if ($project->getConf()->getVal('scm') != 'svn') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$shortname = $project->shortname;
|
||||||
|
if (false===($svn_path=Pluf::f('idf_plugin_syncsvn_svn_path',false))) {
|
||||||
|
throw new Pluf_Exception_SettingError("'idf_plugin_syncsvn_svn_path' must be defined in your configuration file.");
|
||||||
|
}
|
||||||
|
if (file_exists($svn_path.'/'.$shortname)) {
|
||||||
|
throw new Exception(sprintf(__('The repository %s already exists.'),
|
||||||
|
$svn_path.'/'.$shortname));
|
||||||
|
}
|
||||||
|
$return = 0;
|
||||||
|
$output = array();
|
||||||
|
$cmd = sprintf(Pluf::f('svnadmin_path', 'svnadmin').' create %s',
|
||||||
|
escapeshellarg($svn_path.'/'.$shortname));
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
|
||||||
|
$ll = exec($cmd, $output, $return);
|
||||||
|
if ($return != 0) {
|
||||||
|
Pluf_Log::error(array('IDF_Plugin_SyncSvn::processSvnCreate',
|
||||||
|
'Error',
|
||||||
|
array('path' => $svn_path.'/'.$shortname,
|
||||||
|
'output' => $output)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$p = realpath(dirname(__FILE__).'/../../../scripts/svn-post-commit');
|
||||||
|
exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').'ln -s %s %s',
|
||||||
|
escapeshellarg($p),
|
||||||
|
escapeshellarg($svn_path.'/'.$shortname.'/hooks/post-commit')),
|
||||||
|
$out, $res);
|
||||||
|
if ($res != 0) {
|
||||||
|
Pluf_Log::warn(array('IDF_Plugin_SyncSvn::processSvnCreate',
|
||||||
|
'post-commit hook creation error.',
|
||||||
|
$svn_path.'/'.$shortname.'/hooks/post-commit'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$p = realpath(dirname(__FILE__).'/../../../scripts/svn-post-revprop-change');
|
||||||
|
exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').'ln -s %s %s',
|
||||||
|
escapeshellarg($p),
|
||||||
|
escapeshellarg($svn_path.'/'.$shortname.'/hooks/post-revprop-change')),
|
||||||
|
$out, $res);
|
||||||
|
if ($res != 0) {
|
||||||
|
Pluf_Log::warn(array('IDF_Plugin_SyncSvn::processSvnCreate',
|
||||||
|
'post-revprop-change hook creation error.',
|
||||||
|
$svn_path.'/'.$shortname.'/hooks/post-revprop-change'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($return == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the project from the drive and update the access rights.
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
* @return bool Success
|
||||||
|
*/
|
||||||
|
function processSvnDelete($project)
|
||||||
|
{
|
||||||
|
if (!Pluf::f('idf_plugin_syncsvn_remove_orphans', false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($project->getConf()->getVal('scm') != 'svn') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->SyncAccess($project); // exclude $project
|
||||||
|
$shortname = $project->shortname;
|
||||||
|
if (false===($svn_path=Pluf::f('idf_plugin_syncsvn_svn_path',false))) {
|
||||||
|
throw new Pluf_Exception_SettingError("'idf_plugin_syncsvn_svn_path' must be defined in your configuration file.");
|
||||||
|
}
|
||||||
|
if (file_exists($svn_path.'/'.$shortname)) {
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').'rm -rf '.$svn_path.'/'.$shortname;
|
||||||
|
exec($cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronise an user's password.
|
||||||
|
*
|
||||||
|
* @param Pluf_User
|
||||||
|
*/
|
||||||
|
function processSyncPasswd($user)
|
||||||
|
{
|
||||||
|
$passwd_file = Pluf::f('idf_plugin_syncsvn_passwd_file');
|
||||||
|
if (!file_exists($passwd_file) or !is_writable($passwd_file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$ht = new File_Passwd_Authbasic($passwd_file);
|
||||||
|
$ht->load();
|
||||||
|
$ht->setMode('plain');
|
||||||
|
//$ht->setMode(FILE_PASSWD_SHA);
|
||||||
|
if ($ht->userExists($user->login)) {
|
||||||
|
$ht->changePasswd($user->login, '{SHA}' . $this->getSvnPass($user));
|
||||||
|
} else {
|
||||||
|
$ht->addUser($user->login, '{SHA}' . $this->getSvnPass($user));
|
||||||
|
}
|
||||||
|
$ht->save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronize the authz file and the passwd file for the project.
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
*/
|
||||||
|
function processSyncAuthz($project)
|
||||||
|
{
|
||||||
|
$this->SyncAccess();
|
||||||
|
$this->generateProjectPasswd($project);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the repository password for the user
|
||||||
|
*/
|
||||||
|
function getSvnPass($user){
|
||||||
|
//if (isset($_POST["password"])) return $_POST["password"];
|
||||||
|
//return $_POST["password"];
|
||||||
|
//return substr(sha1($user->password.Pluf::f('secret_key')), 0, 8);
|
||||||
|
return $user->password;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For a particular project: update all passwd information
|
||||||
|
*/
|
||||||
|
function generateProjectPasswd($project)
|
||||||
|
{
|
||||||
|
$passwd_file = Pluf::f('idf_plugin_syncsvn_passwd_file');
|
||||||
|
if (!file_exists($passwd_file) or !is_writable($passwd_file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$ht = new File_Passwd_Authbasic($passwd_file);
|
||||||
|
$ht->setMode('plain');
|
||||||
|
$ht->load();
|
||||||
|
$mem = $project->getMembershipData();
|
||||||
|
$members = array_merge((array)$mem['members'], (array)$mem['owners'],
|
||||||
|
(array)$mem['authorized']);
|
||||||
|
foreach($members as $user) {
|
||||||
|
if ($ht->userExists($user->login)) {
|
||||||
|
|
||||||
|
$ht->changePasswd($user->login, '{SHA}' . $this->getSvnPass($user));
|
||||||
|
} else {
|
||||||
|
$ht->addUser($user->login, '{SHA}' . $this->getSvnPass($user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ht->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the dav_svn.authz file
|
||||||
|
*
|
||||||
|
* We rebuild the complete file each time. This is just to be sure
|
||||||
|
* not to bork the rights when trying to just edit part of the
|
||||||
|
* file.
|
||||||
|
*
|
||||||
|
* @param IDF_Project Possibly exclude a project (null)
|
||||||
|
*/
|
||||||
|
function SyncAccess($exclude=null)
|
||||||
|
{
|
||||||
|
$authz_file = Pluf::f('idf_plugin_syncsvn_authz_file');
|
||||||
|
$access_owners = Pluf::f('idf_plugin_syncsvn_access_owners', 'rw');
|
||||||
|
$access_members = Pluf::f('idf_plugin_syncsvn_access_members', 'rw');
|
||||||
|
$access_extra = Pluf::f('idf_plugin_syncsvn_access_extra', 'r');
|
||||||
|
$access_public = Pluf::f('idf_plugin_syncsvn_access_public', 'r');
|
||||||
|
$access_public_priv = Pluf::f('idf_plugin_syncsvn_access_private', '');
|
||||||
|
if (!file_exists($authz_file) or !is_writable($authz_file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$fcontent = '';
|
||||||
|
foreach (Pluf::factory('IDF_Project')->getList() as $project) {
|
||||||
|
if ($exclude and $exclude->id == $project->id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$conf = new IDF_Conf();
|
||||||
|
$conf->setProject($project);
|
||||||
|
if ($conf->getVal('scm') != 'svn' or
|
||||||
|
strlen($conf->getVal('svn_remote_url')) > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$mem = $project->getMembershipData();
|
||||||
|
// [shortname:/]
|
||||||
|
$fcontent .= '['.$project->shortname.':/]'."\n";
|
||||||
|
foreach ($mem['owners'] as $v) {
|
||||||
|
$fcontent .= $v->login.' = '.$access_owners."\n";
|
||||||
|
}
|
||||||
|
foreach ($mem['members'] as $v) {
|
||||||
|
$fcontent .= $v->login.' = '.$access_members."\n";
|
||||||
|
}
|
||||||
|
// access for all users
|
||||||
|
if ($project->private == true) {
|
||||||
|
foreach ($mem['authorized'] as $v) {
|
||||||
|
$fcontent .= $v->login.' = '.$access_extra."\n";
|
||||||
|
}
|
||||||
|
$fcontent .= '* = '.$access_public_priv."\n";
|
||||||
|
} else {
|
||||||
|
$fcontent .= '* = '.$access_public."\n";
|
||||||
|
}
|
||||||
|
$fcontent .= "\n";
|
||||||
|
}
|
||||||
|
file_put_contents($authz_file, $fcontent, LOCK_EX);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the timeline in post commit.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function processSvnUpdateTimeline($params)
|
||||||
|
{
|
||||||
|
$pname = basename($params['repo_dir']);
|
||||||
|
try {
|
||||||
|
$project = IDF_Project::getOr404($pname);
|
||||||
|
} catch (Pluf_HTTP_Error404 $e) {
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_SyncSvn::processSvnUpdateTimeline', 'Project not found.', array($pname, $params)));
|
||||||
|
return false; // Project not found
|
||||||
|
}
|
||||||
|
// Now we have the project and can update the timeline
|
||||||
|
Pluf_Log::debug(array('IDF_Plugin_SyncGit::processSvnUpdateTimeline', 'Project found', $pname, $project->id));
|
||||||
|
IDF_Scm::syncTimeline($project, true);
|
||||||
|
Pluf_Log::event(array('IDF_Plugin_SyncGit::processSvnUpdateTimeline', 'sync', array($pname, $project->id)));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
264
indefero/src/IDF/Precondition.php
Normal file
264
indefero/src/IDF/Precondition.php
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
class IDF_Precondition
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Check if the user has a base authorization to access a given
|
||||||
|
* tab. This used in the case of private project. You need to
|
||||||
|
* further control with the accessSource, accessIssues,
|
||||||
|
* etc. preconditions.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
static public function baseAccess($request)
|
||||||
|
{
|
||||||
|
if (!$request->project->private) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($request->user->hasPerm('IDF.project-authorized-user', $request->project)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return self::projectMemberOrOwner($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user is project owner.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
static public function projectOwner($request)
|
||||||
|
{
|
||||||
|
$res = Pluf_Precondition::loginRequired($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
if ($request->user->hasPerm('IDF.project-owner', $request->project)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return new Pluf_HTTP_Response_Forbidden($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user is project owner or member.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
static public function projectMemberOrOwner($request)
|
||||||
|
{
|
||||||
|
$res = Pluf_Precondition::loginRequired($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
if ($request->user->hasPerm('IDF.project-owner', $request->project)
|
||||||
|
or
|
||||||
|
$request->user->hasPerm('IDF.project-member', $request->project)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return new Pluf_HTTP_Response_Forbidden($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user can access a given element.
|
||||||
|
*
|
||||||
|
* The rights are:
|
||||||
|
* - 'all' (default)
|
||||||
|
* - 'none'
|
||||||
|
* - 'login'
|
||||||
|
* - 'members'
|
||||||
|
* - 'owners'
|
||||||
|
*
|
||||||
|
* The order of the rights is such that a 'owner' is also a
|
||||||
|
* 'member' and of course a logged in person.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @param string Control key
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
static public function accessTabGeneric($request, $key)
|
||||||
|
{
|
||||||
|
switch ($request->conf->getVal($key, 'all')) {
|
||||||
|
case 'none':
|
||||||
|
return new Pluf_HTTP_Response_Forbidden($request);
|
||||||
|
case 'login':
|
||||||
|
return Pluf_Precondition::loginRequired($request);
|
||||||
|
case 'members':
|
||||||
|
return self::projectMemberOrOwner($request);
|
||||||
|
case 'owners':
|
||||||
|
return self::projectOwner($request);
|
||||||
|
case 'all':
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function accessSource($request)
|
||||||
|
{
|
||||||
|
$res = self::baseAccess($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
return self::accessTabGeneric($request, 'source_access_rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function accessIssues($request)
|
||||||
|
{
|
||||||
|
$res = self::baseAccess($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
return self::accessTabGeneric($request, 'issues_access_rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function accessDownloads($request)
|
||||||
|
{
|
||||||
|
$res = self::baseAccess($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
return self::accessTabGeneric($request, 'downloads_access_rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function accessWiki($request)
|
||||||
|
{
|
||||||
|
$res = self::baseAccess($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
return self::accessTabGeneric($request, 'wiki_access_rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function accessReview($request)
|
||||||
|
{
|
||||||
|
$res = self::baseAccess($request);
|
||||||
|
if (true !== $res) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
return self::accessTabGeneric($request, 'review_access_rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on the request, it is automatically setting the user.
|
||||||
|
*
|
||||||
|
* API calls are not translated.
|
||||||
|
*/
|
||||||
|
static public function apiSetUser($request)
|
||||||
|
{
|
||||||
|
// REQUEST is used to be used both for POST and GET requests.
|
||||||
|
if (!isset($request->REQUEST['_hash'])
|
||||||
|
or !isset($request->REQUEST['_login'])
|
||||||
|
or !isset($request->REQUEST['_salt'])) {
|
||||||
|
// equivalent to anonymous access.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$db =& Pluf::db();
|
||||||
|
$true = Pluf_DB_BooleanToDb(true, $db);
|
||||||
|
$sql = new Pluf_SQL('login=%s AND active='.$true,
|
||||||
|
$request->REQUEST['_login']);
|
||||||
|
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
|
||||||
|
if ($users->count() != 1 or !$users[0]->active) {
|
||||||
|
// Should return a special authentication error like user
|
||||||
|
// not found.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$hash = sha1($request->REQUEST['_salt'].sha1($users[0]->password));
|
||||||
|
if ($hash != $request->REQUEST['_hash']) {
|
||||||
|
return true; // Again need authentication error
|
||||||
|
}
|
||||||
|
$request->user = $users[0];
|
||||||
|
|
||||||
|
// Don't try to load projects rights access if we are not in one
|
||||||
|
if ($request->query !== "/api/") {
|
||||||
|
IDF_Middleware::setRights($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on the request, it is automatically setting the user.
|
||||||
|
*
|
||||||
|
* Authenticated feeds have a token set at the end of the url in
|
||||||
|
* the for of 'authenticated/url/token/234092384023woeiur/'. If
|
||||||
|
* you remove 'token/234092384023woeiur/' the url is not
|
||||||
|
* authenticated.
|
||||||
|
*
|
||||||
|
* If the user is already logged in and not anonymous and no token
|
||||||
|
* is given, then the user is unset and a non authenticated user
|
||||||
|
* is loaded. This is to avoid people to not understand why a
|
||||||
|
* normally not authenticated feed is providing authenticated
|
||||||
|
* data.
|
||||||
|
*/
|
||||||
|
static public function feedSetUser($request)
|
||||||
|
{
|
||||||
|
if (!isset($request->project)) {
|
||||||
|
return true; // we do not act on non project pages at the
|
||||||
|
// moment.
|
||||||
|
}
|
||||||
|
if (!$request->user->isAnonymous()) {
|
||||||
|
// by default anonymous
|
||||||
|
$request->user = new Pluf_User();
|
||||||
|
IDF_Middleware::setRights($request);
|
||||||
|
}
|
||||||
|
$match = array();
|
||||||
|
if (!preg_match('#/token/([^/]+)/$#', $request->query, $match)) {
|
||||||
|
return true; // anonymous
|
||||||
|
}
|
||||||
|
$token = $match[1];
|
||||||
|
$hash = substr($token, 0, 2);
|
||||||
|
$encrypted = substr($token, 2);
|
||||||
|
if ($hash != substr(md5(Pluf::f('secret_key').$encrypted), 0, 2)) {
|
||||||
|
return true; // no match in the hash, anonymous
|
||||||
|
}
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
list($userid, $projectid) = explode(':', $cr->decrypt($encrypted), 2);
|
||||||
|
if ($projectid != $request->project->id) {
|
||||||
|
return true; // anonymous
|
||||||
|
}
|
||||||
|
$user = new Pluf_User($userid);
|
||||||
|
if (!$user->active) {
|
||||||
|
return true; // anonymous
|
||||||
|
}
|
||||||
|
$request->user = $user;
|
||||||
|
IDF_Middleware::setRights($request);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the token for the feed.
|
||||||
|
*
|
||||||
|
* @param IDF_Project
|
||||||
|
* @param Pluf_User
|
||||||
|
* @return string Token
|
||||||
|
*/
|
||||||
|
static public function genFeedToken($project, $user)
|
||||||
|
{
|
||||||
|
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
|
||||||
|
$encrypted = trim($cr->encrypt($user->id.':'.$project->id), '~');
|
||||||
|
return substr(md5(Pluf::f('secret_key').$encrypted), 0, 2).$encrypted;
|
||||||
|
}
|
||||||
|
}
|
885
indefero/src/IDF/Project.php
Normal file
885
indefero/src/IDF/Project.php
Normal file
@ -0,0 +1,885 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base definition of a project.
|
||||||
|
*
|
||||||
|
* The issue management system can be used to manage several projects
|
||||||
|
* at the same time.
|
||||||
|
*/
|
||||||
|
class IDF_Project extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
public $_extra_cache = array();
|
||||||
|
protected $_pconf = null;
|
||||||
|
/**
|
||||||
|
* Check if the project as one restricted tab.
|
||||||
|
*
|
||||||
|
* This is the cached information.
|
||||||
|
*
|
||||||
|
* @see self::isRestricted
|
||||||
|
*/
|
||||||
|
protected $_isRestricted = null;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_pconf = null;
|
||||||
|
$this->_extra_cache = array();
|
||||||
|
$this->_a['table'] = 'idf_projects';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'name' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'verbose' => __('name'),
|
||||||
|
),
|
||||||
|
'shortname' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 50,
|
||||||
|
'verbose' => __('short name'),
|
||||||
|
'help_text' => __('Used in the URL to access the project, must be short with only letters and numbers.'),
|
||||||
|
'unique' => true,
|
||||||
|
),
|
||||||
|
'shortdesc' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 255,
|
||||||
|
'verbose' => __('short description'),
|
||||||
|
'help_text' => __('A one line description of the project.'),
|
||||||
|
),
|
||||||
|
'description' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'verbose' => __('description'),
|
||||||
|
'help_text' => __('The description can be extended using the Markdown syntax.'),
|
||||||
|
),
|
||||||
|
'tags' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Manytomany',
|
||||||
|
'blank' => true,
|
||||||
|
'model' => 'IDF_Tag',
|
||||||
|
'verbose' => __('labels'),
|
||||||
|
),
|
||||||
|
'private' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('private'),
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'current_activity' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_ProjectActivity',
|
||||||
|
'blank' => true,
|
||||||
|
'is_null' => true,
|
||||||
|
'default' => null,
|
||||||
|
'verbose' => __('current project activity'),
|
||||||
|
),
|
||||||
|
'enableads' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('enableads'),
|
||||||
|
'default' => 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$activityTable = $this->_con->pfx.'idf_projectactivities';
|
||||||
|
$tagTable = $this->_con->pfx.'idf_project_idf_tag_assoc';
|
||||||
|
$this->_a['views'] = array(
|
||||||
|
'join_activities_and_tags' =>
|
||||||
|
array(
|
||||||
|
'join' => 'LEFT JOIN '.$activityTable.' ON current_activity='.$activityTable.'.id '
|
||||||
|
.'LEFT JOIN '.$tagTable.' ON idf_project_id='.$this->getSqlTable().'.id',
|
||||||
|
'select' => 'DISTINCT '.$this->getSelect().', date, value',
|
||||||
|
'props' => array(
|
||||||
|
'date' => 'current_activity_date',
|
||||||
|
'value' => 'current_activity_value'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String representation of the abstract.
|
||||||
|
*/
|
||||||
|
function __toString()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String ready for indexation.
|
||||||
|
*/
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($this->id == '') {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
$this->modif_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOr404($shortname)
|
||||||
|
{
|
||||||
|
$sql = new Pluf_SQL('shortname=%s', array(trim($shortname)));
|
||||||
|
$projects = Pluf::factory(__CLASS__)->getList(array('filter' => $sql->gen()));
|
||||||
|
if ($projects->count() != 1) {
|
||||||
|
throw new Pluf_HTTP_Error404(sprintf(__('Project "%s" not found.'),
|
||||||
|
$shortname));
|
||||||
|
}
|
||||||
|
return $projects[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of open/closed issues.
|
||||||
|
*
|
||||||
|
* @param string Status ('open'), 'closed'
|
||||||
|
* @param IDF_Tag Subfilter with a label (null)
|
||||||
|
* @return int Count
|
||||||
|
*/
|
||||||
|
public function getIssueCountByOwner($status='open')
|
||||||
|
{
|
||||||
|
switch ($status) {
|
||||||
|
case 'open':
|
||||||
|
$tags = implode(',', $this->getTagIdsByStatus('open'));
|
||||||
|
break;
|
||||||
|
case 'closed':
|
||||||
|
default:
|
||||||
|
$tags = implode(',', $this->getTagIdsByStatus('closed'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$sqlIssueTable = Pluf::factory('IDF_Issue')->getSqlTable();
|
||||||
|
$query = "SELECT uid AS id,COUNT(uid) AS nb
|
||||||
|
FROM (
|
||||||
|
SELECT COALESCE(owner, -1) AS uid
|
||||||
|
FROM $sqlIssueTable
|
||||||
|
WHERE status IN ($tags)
|
||||||
|
) AS ff
|
||||||
|
GROUP BY uid";
|
||||||
|
|
||||||
|
$db = Pluf::db();
|
||||||
|
$dbData = $db->select($query);
|
||||||
|
$ownerStatistics = array();
|
||||||
|
foreach ($dbData as $k => $v) {
|
||||||
|
$key = ($v['id'] === '-1') ? null : $v['id'];
|
||||||
|
$ownerStatistics[$key] = (int)$v['nb'];
|
||||||
|
}
|
||||||
|
|
||||||
|
arsort($ownerStatistics);
|
||||||
|
|
||||||
|
return $ownerStatistics;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of open/closed issues.
|
||||||
|
*
|
||||||
|
* @param string Status ('open'), 'closed'
|
||||||
|
* @param IDF_Tag Subfilter with a label (null)
|
||||||
|
* @param array Restrict further to a list of ids
|
||||||
|
* @return int Count
|
||||||
|
*/
|
||||||
|
public function getIssueCountByStatus($status='open', $label=null, $ids=array())
|
||||||
|
{
|
||||||
|
switch ($status) {
|
||||||
|
case 'open':
|
||||||
|
$key = 'labels_issue_open';
|
||||||
|
$default = IDF_Form_IssueTrackingConf::init_open;
|
||||||
|
break;
|
||||||
|
case 'closed':
|
||||||
|
default:
|
||||||
|
$key = 'labels_issue_closed';
|
||||||
|
$default = IDF_Form_IssueTrackingConf::init_closed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$tags = array();
|
||||||
|
foreach ($this->getTagsFromConfig($key, $default, 'Status') as $tag) {
|
||||||
|
$tags[] = (int)$tag->id;
|
||||||
|
}
|
||||||
|
if (count($tags) == 0) return array();
|
||||||
|
$sql = new Pluf_SQL(sprintf('project=%%s AND status IN (%s)', implode(', ', $tags)), array($this->id));
|
||||||
|
if (!is_null($label)) {
|
||||||
|
$sql2 = new Pluf_SQL('idf_tag_id=%s', array($label->id));
|
||||||
|
$sql->SAnd($sql2);
|
||||||
|
}
|
||||||
|
if (count($ids) > 0) {
|
||||||
|
$sql2 = new Pluf_SQL(sprintf('id IN (%s)', implode(', ', $ids)));
|
||||||
|
$sql->SAnd($sql2);
|
||||||
|
}
|
||||||
|
$params = array('filter' => $sql->gen());
|
||||||
|
if (!is_null($label)) { $params['view'] = 'join_tags'; }
|
||||||
|
$gissue = new IDF_Issue();
|
||||||
|
return $gissue->getCount($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tags for a specific list of issues.
|
||||||
|
*
|
||||||
|
* @param string Status ('open') or 'closed'
|
||||||
|
* @param array A list of issue ids
|
||||||
|
* @return array An array of tag objects
|
||||||
|
*/
|
||||||
|
public function getTagsByIssues($issue_ids=array())
|
||||||
|
{
|
||||||
|
// make the below query always a valid one
|
||||||
|
if (count($issue_ids) == 0) $issue_ids[] = 0;
|
||||||
|
|
||||||
|
$assocTable = $this->_con->pfx.'idf_issue_idf_tag_assoc';
|
||||||
|
$query = sprintf(
|
||||||
|
'SELECT DISTINCT idf_tag_id FROM %s '.
|
||||||
|
'WHERE idf_issue_id IN (%s) '.
|
||||||
|
'GROUP BY idf_tag_id',
|
||||||
|
$assocTable, implode(',', $issue_ids)
|
||||||
|
);
|
||||||
|
|
||||||
|
$db = Pluf::db();
|
||||||
|
$dbData = $db->select($query);
|
||||||
|
$ids = array(0);
|
||||||
|
foreach ($dbData as $data) {
|
||||||
|
$ids[] = $data['idf_tag_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = new Pluf_SQL(sprintf('id IN (%s)', implode(', ', $ids)));
|
||||||
|
$model = new IDF_Tag();
|
||||||
|
return $model->getList(array('filter' => $sql->gen()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the open/closed tag ids as they are often used when doing
|
||||||
|
* listings.
|
||||||
|
*
|
||||||
|
* As this can be often used, the info are cached.
|
||||||
|
*
|
||||||
|
* @param string Status ('open') or 'closed'
|
||||||
|
* @param bool Force cache refresh (false)
|
||||||
|
* @return array Ids of the open/closed tags
|
||||||
|
*/
|
||||||
|
public function getTagIdsByStatus($status='open', $cache_refresh=false)
|
||||||
|
{
|
||||||
|
if (!$cache_refresh
|
||||||
|
and isset($this->_extra_cache['getTagIdsByStatus-'.$status])) {
|
||||||
|
return $this->_extra_cache['getTagIdsByStatus-'.$status];
|
||||||
|
}
|
||||||
|
switch ($status) {
|
||||||
|
case 'open':
|
||||||
|
$key = 'labels_issue_open';
|
||||||
|
$default = IDF_Form_IssueTrackingConf::init_open;
|
||||||
|
break;
|
||||||
|
case 'closed':
|
||||||
|
default:
|
||||||
|
$key = 'labels_issue_closed';
|
||||||
|
$default = IDF_Form_IssueTrackingConf::init_closed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$tags = array();
|
||||||
|
foreach ($this->getTagsFromConfig($key, $default, 'Status') as $tag) {
|
||||||
|
$tags[] = (int) $tag->id;
|
||||||
|
}
|
||||||
|
$this->_extra_cache['getTagIdsByStatus-'.$status] = $tags;
|
||||||
|
return $tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the definition of tags in the configuration into the
|
||||||
|
* corresponding list of tags.
|
||||||
|
*
|
||||||
|
* @param string Configuration key where the tag is.
|
||||||
|
* @param string Default config if nothing in the db.
|
||||||
|
* @param string Default class.
|
||||||
|
* @return array List of tags
|
||||||
|
*/
|
||||||
|
public function getTagsFromConfig($cfg_key, $default, $dclass='Other')
|
||||||
|
{
|
||||||
|
$conf = $this->getConf();
|
||||||
|
$tags = array();
|
||||||
|
foreach (preg_split("/\015\012|\015|\012/", $conf->getVal($cfg_key, $default), -1, PREG_SPLIT_NO_EMPTY) as $s) {
|
||||||
|
$_s = explode('=', $s, 2);
|
||||||
|
$v = trim($_s[0]);
|
||||||
|
$_v = explode(':', $v, 2);
|
||||||
|
if (count($_v) > 1) {
|
||||||
|
$class = trim($_v[0]);
|
||||||
|
$name = trim($_v[1]);
|
||||||
|
} else {
|
||||||
|
$name = trim($_s[0]);
|
||||||
|
$class = $dclass;
|
||||||
|
}
|
||||||
|
$tags[] = IDF_Tag::add($name, $this, $class);
|
||||||
|
}
|
||||||
|
return $tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of relations which are available in this project as
|
||||||
|
* associative array. Each key-value pair marks a set of orthogonal
|
||||||
|
* relations. To ease processing, each of these pairs is included twice
|
||||||
|
* in the array, once as key1 => key2 and once as key2 => key1.
|
||||||
|
*
|
||||||
|
* @return array List of relation names
|
||||||
|
*/
|
||||||
|
public function getRelationsFromConfig()
|
||||||
|
{
|
||||||
|
$conf = $this->getConf();
|
||||||
|
$rel = $conf->getVal('issue_relations', IDF_Form_IssueTrackingConf::init_relations);
|
||||||
|
$relations = array();
|
||||||
|
foreach (preg_split("/\015\012|\015|\012/", $rel, -1, PREG_SPLIT_NO_EMPTY) as $s) {
|
||||||
|
$verbs = preg_split("/\s*,\s*/", $s, 2);
|
||||||
|
if (count($verbs) == 1)
|
||||||
|
$relations += array($verbs[0] => $verbs[0]);
|
||||||
|
else
|
||||||
|
$relations += array($verbs[0] => $verbs[1], $verbs[1] => $verbs[0]);
|
||||||
|
}
|
||||||
|
return $relations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return membership data.
|
||||||
|
*
|
||||||
|
* The array has 3 keys: 'members', 'owners' and 'authorized'.
|
||||||
|
*
|
||||||
|
* The list of users is only taken using the row level permission
|
||||||
|
* table. That is, if you set a user as administrator, he will
|
||||||
|
* have the member and owner rights but will not appear in the
|
||||||
|
* lists.
|
||||||
|
*
|
||||||
|
* @param string Format ('objects'), 'string'.
|
||||||
|
* @return mixed Array of Pluf_User or newline separated list of logins.
|
||||||
|
*/
|
||||||
|
public function getMembershipData($fmt='objects')
|
||||||
|
{
|
||||||
|
$mperm = Pluf_Permission::getFromString('IDF.project-member');
|
||||||
|
$operm = Pluf_Permission::getFromString('IDF.project-owner');
|
||||||
|
$aperm = Pluf_Permission::getFromString('IDF.project-authorized-user');
|
||||||
|
$grow = new Pluf_RowPermission();
|
||||||
|
$db =& Pluf::db();
|
||||||
|
$false = Pluf_DB_BooleanToDb(false, $db);
|
||||||
|
$sql = new Pluf_SQL('model_class=%s AND model_id=%s AND owner_class=%s AND permission=%s AND negative='.$false,
|
||||||
|
array('IDF_Project', $this->id, 'Pluf_User', $operm->id));
|
||||||
|
$owners = new Pluf_Template_ContextVars(array());
|
||||||
|
foreach ($grow->getList(array('filter' => $sql->gen())) as $row) {
|
||||||
|
if ($fmt == 'objects') {
|
||||||
|
$owners[] = Pluf::factory('Pluf_User', $row->owner_id);
|
||||||
|
} else {
|
||||||
|
$owners[] = Pluf::factory('Pluf_User', $row->owner_id)->login;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sql = new Pluf_SQL('model_class=%s AND model_id=%s AND owner_class=%s AND permission=%s AND negative='.$false,
|
||||||
|
array('IDF_Project', $this->id, 'Pluf_User', $mperm->id));
|
||||||
|
$members = new Pluf_Template_ContextVars(array());
|
||||||
|
foreach ($grow->getList(array('filter' => $sql->gen())) as $row) {
|
||||||
|
if ($fmt == 'objects') {
|
||||||
|
$members[] = Pluf::factory('Pluf_User', $row->owner_id);
|
||||||
|
} else {
|
||||||
|
$members[] = Pluf::factory('Pluf_User', $row->owner_id)->login;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$authorized = new Pluf_Template_ContextVars(array());
|
||||||
|
if ($aperm != false) {
|
||||||
|
$sql = new Pluf_SQL('model_class=%s AND model_id=%s AND owner_class=%s AND permission=%s AND negative='.$false,
|
||||||
|
array('IDF_Project', $this->id, 'Pluf_User', $aperm->id));
|
||||||
|
foreach ($grow->getList(array('filter' => $sql->gen())) as $row) {
|
||||||
|
if ($fmt == 'objects') {
|
||||||
|
$authorized[] = Pluf::factory('Pluf_User', $row->owner_id);
|
||||||
|
} else {
|
||||||
|
$authorized[] = Pluf::factory('Pluf_User', $row->owner_id)->login;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($fmt == 'objects') {
|
||||||
|
return new Pluf_Template_ContextVars(array('members' => $members, 'owners' => $owners, 'authorized' => $authorized));
|
||||||
|
} else {
|
||||||
|
return array('members' => implode("\n", (array) $members),
|
||||||
|
'owners' => implode("\n", (array) $owners),
|
||||||
|
'authorized' => implode("\n", (array) $authorized),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the tag clouds.
|
||||||
|
*
|
||||||
|
* Return an array of tags sorted by class, then name. Each tag
|
||||||
|
* get the extra property 'nb_use' for the number of use in the
|
||||||
|
* project.
|
||||||
|
*
|
||||||
|
* @param string ('issues') 'closed_issues', 'wiki' or 'downloads'
|
||||||
|
* @return ArrayObject of IDF_Tag
|
||||||
|
*/
|
||||||
|
public function getTagCloud($what='issues')
|
||||||
|
{
|
||||||
|
$tag_t = Pluf::factory('IDF_Tag')->getSqlTable();
|
||||||
|
if ($what == 'issues' or $what == 'closed_issues') {
|
||||||
|
$what_t = Pluf::factory('IDF_Issue')->getSqlTable();
|
||||||
|
$asso_t = $this->_con->pfx.'idf_issue_idf_tag_assoc';
|
||||||
|
if ($what == 'issues') {
|
||||||
|
$ostatus = $this->getTagIdsByStatus('open');
|
||||||
|
} else {
|
||||||
|
$ostatus = $this->getTagIdsByStatus('closed');
|
||||||
|
}
|
||||||
|
if (count($ostatus) == 0) $ostatus[] = 0;
|
||||||
|
$sql = sprintf('SELECT '.$tag_t.'.id AS id, COUNT(*) AS nb_use FROM '.$tag_t.' '."\n".
|
||||||
|
'LEFT JOIN '.$asso_t.' ON idf_tag_id='.$tag_t.'.id '."\n".
|
||||||
|
'LEFT JOIN '.$what_t.' ON idf_issue_id='.$what_t.'.id '."\n".
|
||||||
|
'WHERE idf_tag_id IS NOT NULL AND '.$what_t.'.status IN (%s) AND '.$what_t.'.project='.$this->id.' GROUP BY '.$tag_t.'.id, '.$tag_t.'.class, '.$tag_t.'.name ORDER BY '.$tag_t.'.class ASC, '.$tag_t.'.name ASC',
|
||||||
|
implode(', ', $ostatus));
|
||||||
|
} elseif ($what == 'wiki') {
|
||||||
|
$dep_ids = IDF_Views_Wiki::getDeprecatedPagesIds($this);
|
||||||
|
$extra = '';
|
||||||
|
if (count($dep_ids)) {
|
||||||
|
$extra = ' AND idf_wiki_page_id NOT IN ('.implode(', ', $dep_ids).') ';
|
||||||
|
}
|
||||||
|
$what_t = Pluf::factory('IDF_Wiki_Page')->getSqlTable();
|
||||||
|
$asso_t = $this->_con->pfx.'idf_tag_idf_wiki_page_assoc';
|
||||||
|
$sql = 'SELECT '.$tag_t.'.id AS id, COUNT(*) AS nb_use FROM '.$tag_t.' '."\n".
|
||||||
|
'LEFT JOIN '.$asso_t.' ON idf_tag_id='.$tag_t.'.id '."\n".
|
||||||
|
'LEFT JOIN '.$what_t.' ON idf_wiki_page_id='.$what_t.'.id '."\n".
|
||||||
|
'WHERE idf_tag_id IS NOT NULL '.$extra.' AND '.$what_t.'.project='.$this->id.' GROUP BY '.$tag_t.'.id, '.$tag_t.'.class, '.$tag_t.'.name ORDER BY '.$tag_t.'.class ASC, '.$tag_t.'.name ASC';
|
||||||
|
} elseif ($what == 'downloads') {
|
||||||
|
$dep_ids = IDF_Views_Download::getDeprecatedFilesIds($this);
|
||||||
|
$extra = '';
|
||||||
|
if (count($dep_ids)) {
|
||||||
|
$extra = ' AND idf_upload_id NOT IN ('.implode(', ', $dep_ids).') ';
|
||||||
|
}
|
||||||
|
$what_t = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
|
$asso_t = $this->_con->pfx.'idf_tag_idf_upload_assoc';
|
||||||
|
$sql = 'SELECT '.$tag_t.'.id AS id, COUNT(*) AS nb_use FROM '.$tag_t.' '."\n".
|
||||||
|
'LEFT JOIN '.$asso_t.' ON idf_tag_id='.$tag_t.'.id '."\n".
|
||||||
|
'LEFT JOIN '.$what_t.' ON idf_upload_id='.$what_t.'.id '."\n".
|
||||||
|
'WHERE idf_tag_id IS NOT NULL '.$extra.' AND '.$what_t.'.project='.$this->id.' GROUP BY '.$tag_t.'.id, '.$tag_t.'.class, '.$tag_t.'.name ORDER BY '.$tag_t.'.class ASC, '.$tag_t.'.name ASC';
|
||||||
|
}
|
||||||
|
$tags = array();
|
||||||
|
foreach ($this->_con->select($sql) as $idc) {
|
||||||
|
$tag = new IDF_Tag($idc['id']);
|
||||||
|
$tag->nb_use = $idc['nb_use'];
|
||||||
|
// group by class
|
||||||
|
if (!array_key_exists($tag->class, $tags)) {
|
||||||
|
$tags[$tag->class] = array();
|
||||||
|
}
|
||||||
|
$tags[$tag->class][] = $tag;
|
||||||
|
}
|
||||||
|
return new Pluf_Template_ContextVars($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the repository size.
|
||||||
|
*
|
||||||
|
* @param bool Force to skip the cache (false)
|
||||||
|
* @return int Size in byte or -1 if not available
|
||||||
|
*/
|
||||||
|
public function getRepositorySize($force=false)
|
||||||
|
{
|
||||||
|
$last_eval = $this->getConf()->getVal('repository_size_check_date', 0);
|
||||||
|
if (Pluf::f('idf_no_size_check', false) or
|
||||||
|
(!$force and $last_eval > time()-172800)) {
|
||||||
|
return $this->getConf()->getVal('repository_size', -1);
|
||||||
|
}
|
||||||
|
$this->getConf()->setVal('repository_size_check_date', time());
|
||||||
|
$scm = IDF_Scm::get($this);
|
||||||
|
$this->getConf()->setVal('repository_size', $scm->getRepositorySize());
|
||||||
|
return $this->getConf()->getVal('repository_size', -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the access url to the repository.
|
||||||
|
*
|
||||||
|
* This will return the right url based on the user.
|
||||||
|
*
|
||||||
|
* @param Pluf_User The user (null)
|
||||||
|
* @param string A specific commit to access
|
||||||
|
*/
|
||||||
|
public function getSourceAccessUrl($user=null, $commit=null)
|
||||||
|
{
|
||||||
|
$right = $this->getConf()->getVal('source_access_rights', 'all');
|
||||||
|
if (($user == null or $user->isAnonymous())
|
||||||
|
and $right == 'all' and !$this->private) {
|
||||||
|
return $this->getRemoteAccessUrl($commit);
|
||||||
|
}
|
||||||
|
return $this->getWriteRemoteAccessUrl($user, $commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the remote access url to the repository.
|
||||||
|
*
|
||||||
|
* This will always return the anonymous access url.
|
||||||
|
*
|
||||||
|
* @param string A specific commit to access
|
||||||
|
*/
|
||||||
|
public function getRemoteAccessUrl($commit=null)
|
||||||
|
{
|
||||||
|
$conf = $this->getConf();
|
||||||
|
$scm = $conf->getVal('scm', 'git');
|
||||||
|
$scms = Pluf::f('allowed_scm');
|
||||||
|
Pluf::loadClass($scms[$scm]);
|
||||||
|
return call_user_func(array($scms[$scm], 'getAnonymousAccessUrl'),
|
||||||
|
$this, $commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the remote write access url to the repository.
|
||||||
|
*
|
||||||
|
* Some SCM have a remote access URL to write which is not the
|
||||||
|
* same as the one to read. For example, you do a checkout with
|
||||||
|
* git-daemon and push with SSH.
|
||||||
|
*
|
||||||
|
* @param string A specific commit to access
|
||||||
|
*/
|
||||||
|
public function getWriteRemoteAccessUrl($user,$commit=null)
|
||||||
|
{
|
||||||
|
$conf = $this->getConf();
|
||||||
|
$scm = $conf->getVal('scm', 'git');
|
||||||
|
$scms = Pluf::f('allowed_scm');
|
||||||
|
return call_user_func(array($scms[$scm], 'getAuthAccessUrl'),
|
||||||
|
$this, $user, $commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the web hook key.
|
||||||
|
*
|
||||||
|
* The goal is to get something predictable but from which one
|
||||||
|
* cannot reverse find the secret key.
|
||||||
|
*/
|
||||||
|
public function getWebHookKey()
|
||||||
|
{
|
||||||
|
return md5($this->id.sha1(Pluf::f('secret_key')).$this->shortname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the root name of the project scm
|
||||||
|
*
|
||||||
|
* @return string SCM root
|
||||||
|
*/
|
||||||
|
public function getScmRoot()
|
||||||
|
{
|
||||||
|
$conf = $this->getConf();
|
||||||
|
$roots = array(
|
||||||
|
'git' => 'master',
|
||||||
|
'svn' => 'HEAD',
|
||||||
|
'mercurial' => 'tip',
|
||||||
|
'mtn' => 'h:'.$conf->getVal('mtn_master_branch', '*'),
|
||||||
|
);
|
||||||
|
$scm = $conf->getVal('scm', 'git');
|
||||||
|
return $roots[$scm];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the object belongs to the project or rise a 404
|
||||||
|
* error.
|
||||||
|
*
|
||||||
|
* By convention, all the objects belonging to a project have the
|
||||||
|
* 'project' property set, so this is easy to check.
|
||||||
|
*
|
||||||
|
* @param Pluf_Model
|
||||||
|
*/
|
||||||
|
public function inOr404($obj)
|
||||||
|
{
|
||||||
|
if ($obj->project != $this->id) {
|
||||||
|
throw new Pluf_HTTP_Error404();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to get a configuration object.
|
||||||
|
*
|
||||||
|
* @return IDF_Conf
|
||||||
|
*/
|
||||||
|
public function getConf()
|
||||||
|
{
|
||||||
|
if ($this->_pconf == null) {
|
||||||
|
$this->_pconf = new IDF_Conf();
|
||||||
|
$this->_pconf->setProject($this);
|
||||||
|
}
|
||||||
|
return $this->_pconf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic overload that falls back to the values of the internal configuration
|
||||||
|
* if no getter / caller matched
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
*/
|
||||||
|
public function __get($key)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return parent::__get($key);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
return $this->getConf()->getVal($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get simple statistics about the project.
|
||||||
|
*
|
||||||
|
* This returns an associative array with number of tickets,
|
||||||
|
* number of downloads, etc.
|
||||||
|
*
|
||||||
|
* @return array Stats
|
||||||
|
*/
|
||||||
|
public function getStats()
|
||||||
|
{
|
||||||
|
$stats = array();
|
||||||
|
$stats['total'] = 0;
|
||||||
|
$what = array('downloads' => 'IDF_Upload',
|
||||||
|
'reviews' => 'IDF_Review',
|
||||||
|
'issues' => 'IDF_Issue',
|
||||||
|
'docpages' => 'IDF_Wiki_Page',
|
||||||
|
'commits' => 'IDF_Commit',
|
||||||
|
);
|
||||||
|
foreach ($what as $key=>$m) {
|
||||||
|
$i = Pluf::factory($m)->getCount(array('filter' => 'project='.(int)$this->id));
|
||||||
|
$stats[$key] = $i;
|
||||||
|
$stats['total'] += $i;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Project::getStats
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Project
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to update the statistics
|
||||||
|
* array of a project. For example to add the on disk size
|
||||||
|
* of the repository if available.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('project' => $project,
|
||||||
|
* 'stats' => $stats)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('project' => $this,
|
||||||
|
'stats' => $stats);
|
||||||
|
Pluf_Signal::send('IDF_Project::getStats',
|
||||||
|
'IDF_Project', $params);
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needs to be called when you update the memberships of a
|
||||||
|
* project.
|
||||||
|
*
|
||||||
|
* This will allow a plugin to, for example, update some access
|
||||||
|
* rights to a repository.
|
||||||
|
*/
|
||||||
|
public function membershipsUpdated()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Project::membershipsUpdated
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Project
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to update the some access
|
||||||
|
* rights to a repository when the project memberships is
|
||||||
|
* updated.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('project' => $project)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('project' => $this);
|
||||||
|
Pluf_Signal::send('IDF_Project::membershipsUpdated',
|
||||||
|
'IDF_Project', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needs to be called when you create a project.
|
||||||
|
*
|
||||||
|
* We cannot put it into the postSave call as the configuration of
|
||||||
|
* the project is not defined at that time.
|
||||||
|
*/
|
||||||
|
function created()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Project::created
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Project
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform special
|
||||||
|
* operations at the creation of a project.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('project' => $project)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('project' => $this);
|
||||||
|
Pluf_Signal::send('IDF_Project::created',
|
||||||
|
'IDF_Project', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The delete() call do not like circular references and the
|
||||||
|
* IDF_Tag is creating some. We predelete to solve these issues.
|
||||||
|
*/
|
||||||
|
public function preDelete()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Project::preDelete
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Project
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to perform special
|
||||||
|
* operations at the deletion of a project.
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('project' => $project)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('project' => $this);
|
||||||
|
Pluf_Signal::send('IDF_Project::preDelete',
|
||||||
|
'IDF_Project', $params);
|
||||||
|
$what = array('IDF_Upload', 'IDF_Review', 'IDF_Issue',
|
||||||
|
'IDF_Wiki_Page', 'IDF_Wiki_Resource',
|
||||||
|
'IDF_Commit', 'IDF_Tag',
|
||||||
|
);
|
||||||
|
foreach ($what as $m) {
|
||||||
|
foreach (Pluf::factory($m)->getList(array('filter' => 'project='.(int)$this->id)) as $item) {
|
||||||
|
$item->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the project has one restricted tab.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isRestricted()
|
||||||
|
{
|
||||||
|
if ($this->_isRestricted !== null) {
|
||||||
|
return $this->_isRestricted;
|
||||||
|
}
|
||||||
|
if ($this->private) {
|
||||||
|
$this->_isRestricted = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$tabs = array(
|
||||||
|
'source_access_rights',
|
||||||
|
'issues_access_rights',
|
||||||
|
'downloads_access_rights',
|
||||||
|
'wiki_access_rights',
|
||||||
|
'review_access_rights'
|
||||||
|
);
|
||||||
|
$conf = $this->getConf();
|
||||||
|
foreach ($tabs as $tab) {
|
||||||
|
if (!in_array($conf->getVal($tab, 'all'),
|
||||||
|
array('all', 'none'))) {
|
||||||
|
$this->_isRestricted = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->_isRestricted = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an associative array of email addresses to notify about changes
|
||||||
|
* in a certain tab like 'issues', 'source', and so on.
|
||||||
|
*
|
||||||
|
* @param string $tab
|
||||||
|
* @return array Key is the email address, value is the preferred language setting
|
||||||
|
*/
|
||||||
|
public function getNotificationRecipientsForTab($tab)
|
||||||
|
{
|
||||||
|
if (!in_array($tab, array('source', 'issues', 'downloads', 'wiki', 'review'))) {
|
||||||
|
throw new Exception(sprintf('unknown tab %s', $tab));
|
||||||
|
}
|
||||||
|
|
||||||
|
$conf = $this->getConf();
|
||||||
|
$recipients = array();
|
||||||
|
$membership_data = $this->getMembershipData();
|
||||||
|
|
||||||
|
if ($conf->getVal($tab.'_notification_owners_enabled', false)) {
|
||||||
|
foreach ($membership_data['owners'] as $owner) {
|
||||||
|
$recipients[$owner->email] = $owner->language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($conf->getVal($tab.'_notification_members_enabled', false)) {
|
||||||
|
foreach ($membership_data['members'] as $member) {
|
||||||
|
$recipients[$member->email] = $member->language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($conf->getVal($tab.'_notification_email_enabled', false)) {
|
||||||
|
$addresses = preg_split('/\s*,\s*/',
|
||||||
|
$conf->getVal($tab.'_notification_email', ''),
|
||||||
|
-1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
|
// we use a default language setting for this plain list of
|
||||||
|
// addresses, but we ensure that we do not overwrite an existing
|
||||||
|
// address which might come with a proper setting already
|
||||||
|
$languages = Pluf::f('languages', array('en'));
|
||||||
|
foreach ($addresses as $address) {
|
||||||
|
if (array_key_exists($address, $recipients))
|
||||||
|
continue;
|
||||||
|
$recipients[$address] = $languages[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $recipients;
|
||||||
|
}
|
||||||
|
}
|
78
indefero/src/IDF/ProjectActivity.php
Normal file
78
indefero/src/IDF/ProjectActivity.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models the activity value for a project and a given date
|
||||||
|
*
|
||||||
|
* @author tommyd
|
||||||
|
*/
|
||||||
|
class IDF_ProjectActivity extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_projectactivities';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'project' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Project',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('project'),
|
||||||
|
'relate_name' => 'activities',
|
||||||
|
),
|
||||||
|
'date' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('date'),
|
||||||
|
),
|
||||||
|
'value' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Float',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('value'),
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
$prj = $this->get_project();
|
||||||
|
$sql = new Pluf_SQL('project=%s', array($prj->id));
|
||||||
|
$list = Pluf::factory('IDF_ProjectActivity')->getList(array('filter' => $sql->gen(), 'order' => 'date desc'));
|
||||||
|
if (count($list) > 0 && $prj->current_activity != $list[0]->id) {
|
||||||
|
$prj->current_activity = $list[0];
|
||||||
|
$prj->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
222
indefero/src/IDF/Queue.php
Normal file
222
indefero/src/IDF/Queue.php
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
n# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue system for the management of asynchronous operations.
|
||||||
|
*
|
||||||
|
* Anybody can add an item to the queue and any application can
|
||||||
|
* register itself to process an item from the queue.
|
||||||
|
*
|
||||||
|
* An item in the queue is considered as fully processed when all the
|
||||||
|
* handlers have processed it successfully.
|
||||||
|
*
|
||||||
|
* To push a new item in the queue:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* $item = new IDF_Queue();
|
||||||
|
* $item->type = 'new_commit';
|
||||||
|
* $item->payload = array('what', 'ever', array('data'));
|
||||||
|
* $item->create();
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* To process one item from the queue, you first need to register an
|
||||||
|
* handler, by adding the following in your relations.php file before
|
||||||
|
* the return statement or in your config file.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* Pluf_Signal::connect('IDF_Queue::processItem',
|
||||||
|
* array('YourApp_Class', 'processItem'));
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* The processItem method will be called with two arguments, the first
|
||||||
|
* is the name of the signal ('IDF_Queue::processItem') and the second
|
||||||
|
* is an array with:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* array('item' => $item,
|
||||||
|
* 'res' => array('OtherApp_Class::handler' => false,
|
||||||
|
* 'FooApp_Class::processItem' => true));
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* When you process an item, you need first to check if the type is
|
||||||
|
* corresponding to what you want to work with, then you need to check
|
||||||
|
* in 'res' if you have not already processed successfully the item,
|
||||||
|
* that is the key 'YourApp_Class::processItem' must be set to true,
|
||||||
|
* and then you can process the item. At the end of your processing,
|
||||||
|
* you need to modify by reference the 'res' key to add your status.
|
||||||
|
*
|
||||||
|
* All the data except for the type is in the payload, this makes the
|
||||||
|
* queue flexible to manage many different kind of tasks.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Queue extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_queue';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'status' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'blank' => false,
|
||||||
|
'choices' => array(
|
||||||
|
'pending' => 0,
|
||||||
|
'in_progress' => 1,
|
||||||
|
'need_retry' => 2,
|
||||||
|
'done' => 3,
|
||||||
|
'error' => 4,
|
||||||
|
),
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'trials' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 50,
|
||||||
|
),
|
||||||
|
'payload' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Serialized',
|
||||||
|
'blank' => false,
|
||||||
|
),
|
||||||
|
'results' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Serialized',
|
||||||
|
'blank' => false,
|
||||||
|
),
|
||||||
|
'lasttry_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
$this->lasttry_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
$this->results = array();
|
||||||
|
$this->trials = 0;
|
||||||
|
$this->status = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current item is going to be processed.
|
||||||
|
*/
|
||||||
|
function processItem()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [signal]
|
||||||
|
*
|
||||||
|
* IDF_Queue::processItem
|
||||||
|
*
|
||||||
|
* [sender]
|
||||||
|
*
|
||||||
|
* IDF_Queue
|
||||||
|
*
|
||||||
|
* [description]
|
||||||
|
*
|
||||||
|
* This signal allows an application to run an asynchronous
|
||||||
|
* job. The handler gets the queue item and the results from
|
||||||
|
* the previous run. If the handler key is not set, then the
|
||||||
|
* job was not run. If set it can be either true (already done)
|
||||||
|
* or false (error at last run).
|
||||||
|
*
|
||||||
|
* [parameters]
|
||||||
|
*
|
||||||
|
* array('item' => $item, 'res' => $res)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$params = array('item' => $this, 'res' => $this->results);
|
||||||
|
Pluf_Signal::send('IDF_Queue::processItem',
|
||||||
|
'IDF_Queue', $params);
|
||||||
|
$this->status = 3; // Success
|
||||||
|
foreach ($params['res'] as $handler=>$ok) {
|
||||||
|
if (!$ok) {
|
||||||
|
$this->status = 2; // Set to need retry
|
||||||
|
$this->trials += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->results = $params['res'];
|
||||||
|
$this->lasttry_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
$this->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the queue.
|
||||||
|
*
|
||||||
|
* It is a signal handler to just hook itself at the right time in
|
||||||
|
* the cron job performing the maintainance work.
|
||||||
|
*
|
||||||
|
* The processing relies on the fact that no other processing jobs
|
||||||
|
* must run at the same time. That is, your cron job must use a
|
||||||
|
* lock file or something like to not run in parallel.
|
||||||
|
*
|
||||||
|
* The processing is simple, first get 500 queue items, mark them
|
||||||
|
* as being processed and for each of them call the processItem()
|
||||||
|
* method which will trigger another event for processing.
|
||||||
|
*
|
||||||
|
* If you are processing more than 500 items per batch, you need
|
||||||
|
* to switch to a different solution.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function process($sender, &$params)
|
||||||
|
{
|
||||||
|
$where = 'status=0 OR status=2';
|
||||||
|
$items = Pluf::factory('IDF_Queue')->getList(array('filter'=>$where,
|
||||||
|
'nb'=> 500));
|
||||||
|
Pluf_Log::event(array('IDF_Queue::process', $items->count()));
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$item->status = 1;
|
||||||
|
$item->update();
|
||||||
|
}
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$item->status = 1;
|
||||||
|
$item->processItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
198
indefero/src/IDF/Review.php
Normal file
198
indefero/src/IDF/Review.php
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
|
||||||
|
Pluf::loadFunction('Pluf_Template_dateAgo');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base definition of a code review.
|
||||||
|
*
|
||||||
|
* A code review has a status, submitter, summary, description and is
|
||||||
|
* associated to a project.
|
||||||
|
*
|
||||||
|
* The real content of the review is in the IDF_Review_Patch which
|
||||||
|
* contains a given patch and associated comments from reviewers.
|
||||||
|
*
|
||||||
|
* Basically the hierarchy of the models is:
|
||||||
|
* - Review > Patch > Comment > Comment on file
|
||||||
|
*
|
||||||
|
* For each review, one can have several patches. Each patch, is
|
||||||
|
* getting a series of comments. A comment is tracking the state
|
||||||
|
* change in the review (like the issue comments). For each comment,
|
||||||
|
* we have a series of file comments. The file comments are associated
|
||||||
|
* to the a given modified file in the patch.
|
||||||
|
*/
|
||||||
|
class IDF_Review extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_reviews';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'project' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Project',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('project'),
|
||||||
|
'relate_name' => 'reviews',
|
||||||
|
),
|
||||||
|
'summary' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'verbose' => __('summary'),
|
||||||
|
),
|
||||||
|
'submitter' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
'relate_name' => 'submitted_review',
|
||||||
|
),
|
||||||
|
'interested' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Manytomany',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => true,
|
||||||
|
'help_text' => 'Interested users will get an email notification when the review is changed.',
|
||||||
|
),
|
||||||
|
'tags' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Manytomany',
|
||||||
|
'blank' => true,
|
||||||
|
'model' => 'IDF_Tag',
|
||||||
|
'verbose' => __('labels'),
|
||||||
|
),
|
||||||
|
'status' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'blank' => false,
|
||||||
|
'model' => 'IDF_Tag',
|
||||||
|
'verbose' => __('status'),
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
),
|
||||||
|
'modif_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('modification date'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->_a['idx'] = array(
|
||||||
|
'modif_dtime_idx' =>
|
||||||
|
array(
|
||||||
|
'col' => 'modif_dtime',
|
||||||
|
'type' => 'normal',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$table = $this->_con->pfx.'idf_review_idf_tag_assoc';
|
||||||
|
$this->_a['views'] = array(
|
||||||
|
'join_tags' =>
|
||||||
|
array(
|
||||||
|
'join' => 'LEFT JOIN '.$table
|
||||||
|
.' ON idf_review_id=id',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate through the patches and comments to get the reviewers.
|
||||||
|
*/
|
||||||
|
function getReviewers()
|
||||||
|
{
|
||||||
|
$rev = new ArrayObject();
|
||||||
|
foreach ($this->get_patches_list() as $p) {
|
||||||
|
foreach ($p->get_comments_list() as $c) {
|
||||||
|
$rev[] = $c->get_submitter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Pluf_Model_RemoveDuplicates($rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __toString()
|
||||||
|
{
|
||||||
|
return $this->id.' - '.$this->summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
IDF_Timeline::remove($this);
|
||||||
|
IDF_Search::remove($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
$this->modif_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
// At creation, we index after saving the associated patch.
|
||||||
|
if (!$create) IDF_Search::index($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an HTML fragment used to display this review in the
|
||||||
|
* timeline.
|
||||||
|
*
|
||||||
|
* The request object is given to be able to check the rights and
|
||||||
|
* as such create links to other items etc. You can consider that
|
||||||
|
* if displayed, you can create a link to it.
|
||||||
|
*
|
||||||
|
* @param Pluf_HTTP_Request
|
||||||
|
* @return Pluf_Template_SafeString
|
||||||
|
*/
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
242
indefero/src/IDF/Review/Comment.php
Normal file
242
indefero/src/IDF/Review/Comment.php
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A comment set on a review.
|
||||||
|
*
|
||||||
|
* A comment is associated to a patch as a review can have many
|
||||||
|
* patches associated to it.
|
||||||
|
*
|
||||||
|
* A comment is also tracking the changes in the review in the same
|
||||||
|
* way the issue comment is tracking the changes in the issue.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Review_Comment extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_review_comments';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'patch' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Review_Patch',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('patch'),
|
||||||
|
'relate_name' => 'comments',
|
||||||
|
),
|
||||||
|
'content' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => true, // if only commented on lines
|
||||||
|
'verbose' => __('comment'),
|
||||||
|
),
|
||||||
|
'submitter' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'Pluf_User',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('submitter'),
|
||||||
|
),
|
||||||
|
'changes' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Serialized',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('changes'),
|
||||||
|
'help_text' => 'Serialized array of the changes in the review.',
|
||||||
|
),
|
||||||
|
'vote' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'default' => 0,
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('vote'),
|
||||||
|
'help_text' => '1, 0 or -1 for positive, neutral or negative vote.',
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
'index' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function changedReview()
|
||||||
|
{
|
||||||
|
return (is_array($this->changes) and count($this->changes) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
IDF_Timeline::remove($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
IDF_Timeline::insert($this,
|
||||||
|
$this->get_patch()->get_review()->get_project(),
|
||||||
|
$this->get_submitter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
$review = $this->get_patch()->get_review();
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$review->id));
|
||||||
|
$out = '<tr class="log"><td><a href="'.$url.'">'.
|
||||||
|
Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).
|
||||||
|
'</a></td><td>';
|
||||||
|
$stag = new IDF_Template_ShowUser();
|
||||||
|
$user = $stag->start($this->get_submitter(), $request, '', false);
|
||||||
|
$ic = (in_array($review->status, $request->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
|
||||||
|
$out .= sprintf(__('<a href="%1$s" class="%2$s" title="View review">Review %3$d</a>, %4$s'), $url, $ic, $review->id, Pluf_esc($review->summary)).'</td>';
|
||||||
|
$out .= "\n".'<tr class="extra"><td colspan="2">
|
||||||
|
<div class="helptext right">'.sprintf(__('Update of <a href="%1$s" class="%2$s">review %3$d</a>, by %4$s'), $url, $ic, $review->id, $user).'</div></td></tr>';
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
$review = $this->get_patch()->get_review();
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$review->id));
|
||||||
|
$title = sprintf(__('%1$s: Updated review %2$d - %3$s'),
|
||||||
|
Pluf_esc($request->project->name),
|
||||||
|
$review->id, Pluf_esc($review->summary));
|
||||||
|
$url .= '#ic'.$this->id;
|
||||||
|
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
|
||||||
|
$context = new Pluf_Template_Context_Request(
|
||||||
|
$request,
|
||||||
|
array('url' => $url,
|
||||||
|
'author' => $this->get_submitter(),
|
||||||
|
'title' => $title,
|
||||||
|
'c' => $this,
|
||||||
|
'review' => $review,
|
||||||
|
'date' => $date)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/review/feedfragment.xml');
|
||||||
|
return $tmpl->render($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify of the update of the review.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param IDF_Conf Current configuration
|
||||||
|
* @param bool Creation (true)
|
||||||
|
*/
|
||||||
|
public function notify($conf, $create=true)
|
||||||
|
{
|
||||||
|
$patch = $this->get_patch();
|
||||||
|
$review = $patch->get_review();
|
||||||
|
$prj = $review->get_project();
|
||||||
|
$reviewers = $review->getReviewers();
|
||||||
|
|
||||||
|
if (!Pluf_Model_InArray($review->get_submitter(), $reviewers)) {
|
||||||
|
$reviewers[] = $review->get_submitter();
|
||||||
|
}
|
||||||
|
|
||||||
|
$comments = $patch->getFileComments(array('order' => 'id DESC'));
|
||||||
|
$gcomments = $patch->get_comments_list(array('order' => 'id DESC'));
|
||||||
|
|
||||||
|
$recipients = $prj->getNotificationRecipientsForTab('review');
|
||||||
|
|
||||||
|
foreach ($reviewers as $user) {
|
||||||
|
if (array_key_exists($user->email, $recipients))
|
||||||
|
continue;
|
||||||
|
$recipients[$user->email] = $user->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current_locale = Pluf_Translation::getLocale();
|
||||||
|
|
||||||
|
$from_email = Pluf::f('from_email');
|
||||||
|
$messageId = '<'.md5('review'.$review->id.md5(Pluf::f('secret_key'))).'@'.Pluf::f('mail_host', 'localhost').'>';
|
||||||
|
|
||||||
|
foreach ($recipients as $address => $language) {
|
||||||
|
|
||||||
|
if ($this->get_submitter()->email === $address) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($language);
|
||||||
|
|
||||||
|
$context = new Pluf_Template_Context(array(
|
||||||
|
'review' => $review,
|
||||||
|
'patch' => $patch,
|
||||||
|
'comments' => $comments,
|
||||||
|
'gcomments' => $gcomments,
|
||||||
|
'project' => $prj,
|
||||||
|
'url_base' => Pluf::f('url_base'),
|
||||||
|
));
|
||||||
|
|
||||||
|
// reviews only updated through comments, see IDF_Review_Patch::notify()
|
||||||
|
$tplfile = 'idf/review/review-updated-email.txt';
|
||||||
|
$subject = __('Updated Code Review %1$s - %2$s (%3$s)');
|
||||||
|
$headers = array('References' => $messageId);
|
||||||
|
|
||||||
|
$tmpl = new Pluf_Template($tplfile);
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
|
||||||
|
$email = new Pluf_Mail($from_email, $address,
|
||||||
|
sprintf($subject, $review->id, $review->summary, $prj->shortname));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->addHeaders($headers);
|
||||||
|
$email->sendMail();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($current_locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_submitter_data()
|
||||||
|
{
|
||||||
|
return IDF_UserData::factory($this->get_submitter());
|
||||||
|
}
|
||||||
|
}
|
110
indefero/src/IDF/Review/FileComment.php
Normal file
110
indefero/src/IDF/Review/FileComment.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A comment to a file affected by a patch.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Review_FileComment extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_review_filecomments';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'comment' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Review_Comment',
|
||||||
|
'blank' => false,
|
||||||
|
'relate_name' => 'filecomments',
|
||||||
|
'verbose' => __('comment'),
|
||||||
|
),
|
||||||
|
'cfile' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'help_text' => 'The changed file, for example src/foo/bar.txt, this is the path to access it in the repository.',
|
||||||
|
),
|
||||||
|
'cline' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Integer',
|
||||||
|
'blank' => false,
|
||||||
|
'default' => 0,
|
||||||
|
'help_text' => 'The commented line, negative value is the old file, positive the new, 0 general comment.',
|
||||||
|
),
|
||||||
|
'content' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('comment'),
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
'index' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
return $this->cfile.' '.$this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
227
indefero/src/IDF/Review/Patch.php
Normal file
227
indefero/src/IDF/Review/Patch.php
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# This file is part of InDefero, an open source project management application.
|
||||||
|
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
|
||||||
|
#
|
||||||
|
# InDefero is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# InDefero is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A patch to be reviewed.
|
||||||
|
*
|
||||||
|
* A patch can be marked as being directly the commit, in that case
|
||||||
|
* the patch does not store the diff file as it can be retrieved from
|
||||||
|
* the backend.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IDF_Review_Patch extends Pluf_Model
|
||||||
|
{
|
||||||
|
public $_model = __CLASS__;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$this->_a['table'] = 'idf_review_patches';
|
||||||
|
$this->_a['model'] = __CLASS__;
|
||||||
|
$this->_a['cols'] = array(
|
||||||
|
// It is mandatory to have an "id" column.
|
||||||
|
'id' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Sequence',
|
||||||
|
'blank' => true,
|
||||||
|
),
|
||||||
|
'review' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Review',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('review'),
|
||||||
|
'relate_name' => 'patches',
|
||||||
|
),
|
||||||
|
'summary' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Varchar',
|
||||||
|
'blank' => false,
|
||||||
|
'size' => 250,
|
||||||
|
'verbose' => __('summary'),
|
||||||
|
),
|
||||||
|
'commit' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Foreignkey',
|
||||||
|
'model' => 'IDF_Commit',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('commit'),
|
||||||
|
'relate_name' => 'patches',
|
||||||
|
),
|
||||||
|
'description' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Text',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('description'),
|
||||||
|
),
|
||||||
|
'patch' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_File',
|
||||||
|
'blank' => false,
|
||||||
|
'verbose' => __('patch'),
|
||||||
|
'help_text' => 'The patch is stored at the same place as the issue attachments with the same approach for the name.',
|
||||||
|
),
|
||||||
|
'creation_dtime' =>
|
||||||
|
array(
|
||||||
|
'type' => 'Pluf_DB_Field_Datetime',
|
||||||
|
'blank' => true,
|
||||||
|
'verbose' => __('creation date'),
|
||||||
|
'index' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of file comments.
|
||||||
|
*
|
||||||
|
* It will go through the patch comments and find for each the
|
||||||
|
* file comments.
|
||||||
|
*
|
||||||
|
* @param array Filter to apply to the file comment list (array())
|
||||||
|
*/
|
||||||
|
function getFileComments($filter=array())
|
||||||
|
{
|
||||||
|
$files = new ArrayObject();
|
||||||
|
foreach ($this->get_comments_list(array('order'=>'creation_dtime ASC')) as $ct) {
|
||||||
|
foreach ($ct->get_filecomments_list($filter) as $fc) {
|
||||||
|
$files[] = $fc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toIndex()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function preDelete()
|
||||||
|
{
|
||||||
|
IDF_Timeline::remove($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
function preSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
$this->creation_dtime = gmdate('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function postSave($create=false)
|
||||||
|
{
|
||||||
|
if ($create) {
|
||||||
|
IDF_Timeline::insert($this,
|
||||||
|
$this->get_review()->get_project(),
|
||||||
|
$this->get_review()->get_submitter());
|
||||||
|
IDF_Search::index($this->get_review());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function timelineFragment($request)
|
||||||
|
{
|
||||||
|
$review = $this->get_review();
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$review->id));
|
||||||
|
$out = '<tr class="log"><td><a href="'.$url.'">'.
|
||||||
|
Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).
|
||||||
|
'</a></td><td>';
|
||||||
|
$stag = new IDF_Template_ShowUser();
|
||||||
|
$user = $stag->start($review->get_submitter(), $request, '', false);
|
||||||
|
$ic = (in_array($review->status, $request->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
|
||||||
|
$out .= sprintf(__('<a href="%1$s" class="%2$s" title="View review">Review %3$d</a>, %4$s'), $url, $ic, $review->id, Pluf_esc($review->summary)).'</td>';
|
||||||
|
$out .= "\n".'<tr class="extra"><td colspan="2">
|
||||||
|
<div class="helptext right">'.sprintf(__('Creation of <a href="%1$s" class="%2$s">review %3$d</a>, by %4$s'), $url, $ic, $review->id, $user).'</div></td></tr>';
|
||||||
|
return Pluf_Template::markSafe($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function feedFragment($request)
|
||||||
|
{
|
||||||
|
$review = $this->get_review();
|
||||||
|
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view',
|
||||||
|
array($request->project->shortname,
|
||||||
|
$review->id));
|
||||||
|
$title = sprintf(__('%1$s: Creation of Review %2$d - %3$s'),
|
||||||
|
Pluf_esc($request->project->name),
|
||||||
|
$review->id, Pluf_esc($review->summary));
|
||||||
|
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
|
||||||
|
$context = new Pluf_Template_Context_Request(
|
||||||
|
$request,
|
||||||
|
array('url' => $url,
|
||||||
|
'author' => $review->get_submitter(),
|
||||||
|
'title' => $title,
|
||||||
|
'p' => $this,
|
||||||
|
'review' => $review,
|
||||||
|
'date' => $date)
|
||||||
|
);
|
||||||
|
$tmpl = new Pluf_Template('idf/review/feedfragment.xml');
|
||||||
|
return $tmpl->render($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notify($conf, $create=true)
|
||||||
|
{
|
||||||
|
$review = $this->get_review();
|
||||||
|
$project = $review->get_project();
|
||||||
|
$current_locale = Pluf_Translation::getLocale();
|
||||||
|
|
||||||
|
$from_email = Pluf::f('from_email');
|
||||||
|
$messageId = '<'.md5('review'.$review->id.md5(Pluf::f('secret_key'))).'@'.Pluf::f('mail_host', 'localhost').'>';
|
||||||
|
$recipients = $project->getNotificationRecipientsForTab('review');
|
||||||
|
|
||||||
|
foreach ($recipients as $address => $language) {
|
||||||
|
|
||||||
|
if ($review->get_submitter()->email === $address) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($language);
|
||||||
|
|
||||||
|
$context = new Pluf_Template_Context(array(
|
||||||
|
'review' => $review,
|
||||||
|
'patch' => $this,
|
||||||
|
'comments' => array(),
|
||||||
|
'project' => $project,
|
||||||
|
'url_base' => Pluf::f('url_base'),
|
||||||
|
));
|
||||||
|
|
||||||
|
// reviews are updated through comments, see IDF_Review_Comment::notify()
|
||||||
|
$tplfile = 'idf/review/review-created-email.txt';
|
||||||
|
$subject = __('New Code Review %1$s - %2$s (%3$s)');
|
||||||
|
$headers = array('Message-ID' => $messageId);
|
||||||
|
|
||||||
|
$tmpl = new Pluf_Template($tplfile);
|
||||||
|
$text_email = $tmpl->render($context);
|
||||||
|
|
||||||
|
$email = new Pluf_Mail($from_email,
|
||||||
|
$address,
|
||||||
|
sprintf($subject,
|
||||||
|
$review->id,
|
||||||
|
$review->summary,
|
||||||
|
$project->shortname));
|
||||||
|
$email->addTextMessage($text_email);
|
||||||
|
$email->addHeaders($headers);
|
||||||
|
$email->sendMail();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pluf_Translation::loadSetLocale($current_locale);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user