Indefero

Indefero Commit Details


Date:2008-11-27 04:10:23 (16 years 25 days ago)
Author:Loic d'Anterroches
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:0273e535e050ccb83915b1a649c4267eb2de1a9e
Parents: 566c90cf6a2d3ad70f9a38e58030b2ca7f3143aa
Message:Added multiple upload file in issue.

This fixes issue 54.
Changes:

File differences

src/IDF/Form/IssueCreate.php
7272
7373
7474
75
76
75
76
77
7778
7879
7980
......
8384
8485
8586
87
8688
8789
8890
......
195197
196198
197199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
198215
199216
200217
......
203220
204221
205222
206
207
208
209
210
211
212
213
214
215
216
217
218
219
223
224
225
226
227
228
229
230
231
232
233
234
235
236
220237
238
221239
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242240
243
244
245
246
247
248
249
250
251
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
252272
253
273
254274
255275
256276
257277
258
259278
260
279
261280
262281
263282
// 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['attachment'] = new Pluf_Form_Field_File(
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' =>
)
)
);
}
if ($this->show_full) {
$this->fields['status'] = new Pluf_Form_Field_Varchar(
}
/**
* 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
*/
function save($commit=true)
{
if ($this->isValid()) {
// 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);
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 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.
if ($this->cleaned_data['attachment']) {
} 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 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.
for ($i=1;$i<4;$i++) {
if ($this->cleaned_data['attachment'.$i]) {
$file = new IDF_IssueFile();
$file->attachment = $this->cleaned_data['attachment'];
$file->attachment = $this->cleaned_data['attachment'.$i];
$file->submitter = $this->user;
$file->comment = $comment;
$file->create();
}
return $issue;
}
throw new Exception(__('Cannot save the model from an invalid form.'));
return $issue;
}
/**
src/IDF/Form/IssueUpdate.php
6868
6969
7070
71
72
71
72
73
7374
7475
7576
......
7980
8081
8182
83
8284
8385
8486
......
124126
125127
126128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
127144
128145
129146
......
202219
203220
204221
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
222237
238
239
240
223241
224
225
226
227
228
229
230
231
232
233
234
242
243
244
245
246
247
248
249
250
251
252
235253
236254
237
238
239
240
241
242
243
244
255
256
257
258
259
260
261
262
245263
246264
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266265
267
268
269
270
271
272
273
274
275
276
277
278
266
267
268
269
279270
280
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
281301
282
302
283303
284304
285305
286306
287
288307
289
308
290309
291310
// 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['attachment'] = new Pluf_Form_Field_File(
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' =>
)
)
);
}
if ($this->show_full) {
$this->fields['status'] = new Pluf_Form_Field_Varchar(
}
/**
* 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]);
}
}
}
/**
* We check that something is really changed.
*/
public function clean()
*/
function save($commit=true)
{
if ($this->isValid()) {
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;
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 ($tag->class != 'Other') {
$changes['lb'][] = (string) $tag; //new tag
} else {
$changes['lb'][] = (string) $tag->name;
}
}
// 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 ($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;
}
}
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;
}
}
// 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;
}
// 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.
// 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 ($this->cleaned_data['attachment']) {
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;
}
// 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.
}
for ($i=1;$i<4;$i++) {
if ($this->cleaned_data['attachment'.$i]) {
$file = new IDF_IssueFile();
$file->attachment = $this->cleaned_data['attachment'];
$file->attachment = $this->cleaned_data['attachment'.$i];
$file->submitter = $this->user;
$file->comment = $comment;
$file->create();
}
return $this->issue;
}
throw new Exception(__('Cannot save the model from an invalid form.'));
return $this->issue;
}
}
src/IDF/IssueFile.php
114114
115115
116116
117
117118
118119
119120
$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 {
src/IDF/templates/idf/issues/create.html
2424
2525
2626
27
28
29
30
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
3143
3244
3345
......
7486
7587
7688
77
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
78115
116
117
79118
80119
{$form.f.content|unsafe}
</td>
</tr>
<tr>
<th>{$form.f.attachment.labelTag}:</th>
<td>{if $form.f.attachment.errors}{$form.f.attachment.fieldErrors}{/if}
{$form.f.attachment|unsafe}
<tr id="form-attachment-1">
<th>{$form.f.attachment1.labelTag}:</th>
<td>{if $form.f.attachment1.errors}{$form.f.attachment1.fieldErrors}{/if}
{$form.f.attachment1|unsafe}
</td>
</tr>
<tr id="form-attachment-2">
<th>{$form.f.attachment2.labelTag}:</th>
<td>{if $form.f.attachment2.errors}{$form.f.attachment2.fieldErrors}{/if}
{$form.f.attachment2|unsafe}
</td>
</tr>
<tr id="form-attachment-3">
<th>{$form.f.attachment3.labelTag}:</th>
<td>{if $form.f.attachment3.errors}{$form.f.attachment3.fieldErrors}{/if}
{$form.f.attachment3|unsafe}
</td>
</tr>{if $isOwner or $isMember}
<tr>
{/block}
{block javascript}
<script type="text/javascript">
document.getElementById('id_summary').focus()
document.getElementById('id_summary').focus();{literal}
$(document).ready(function(){
// Hide the upload forms, we insert before the first attach file
// row an "Attach File" little link.
// We hide all the rows.
$("#form-attachment-1").before("{/literal}<tr id=\"form-block-0\"><td>&nbsp;</td><td><img style=\"vertical-align: text-bottom;\" src=\"{media '/idf/img/attachment.png'}\" alt=\" \" align=\"bottom\" /><a id=\"form-show-0\" href=\"#\">{trans 'Attach file'}{literal}</a></td></tr>");
$("#form-show-0").click(function(){
$("#form-attachment-1").show();
$("#form-block-0").hide();
});
$("#form-attachment-1 td").append("<span id=\"form-block-1\"><a id=\"form-show-1\" href=\"#\">{/literal}{trans 'Attach another file'}{literal}</a></span>");
$("#form-show-1").click(function(){
$("#form-attachment-2").show();
$("#form-block-1").hide();
});
$("#form-attachment-2 td").append("<span id=\"form-block-2\"><a id=\"form-show-2\" href=\"#\">{/literal}{trans 'Attach another file'}{literal}</a></span>");
$("#form-show-2").click(function(){
$("#form-attachment-3").show();
$("#form-block-2").hide();
});
var j=0;
for (j=1;j<4;j=j+1) {
$("#form-attachment-"+j).hide();
}
});
</script>
{/literal}{/block}
{include 'idf/issues/js-autocomplete.html'}{/block}
src/IDF/templates/idf/issues/view.html
5959
6060
6161
62
63
64
65
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
6678
6779
6880
......
122134
123135
124136
125
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{$form.f.content|unsafe}
</td>
</tr>
<tr>
<th>{$form.f.attachment.labelTag}:</th>
<td>{if $form.f.attachment.errors}{$form.f.attachment.fieldErrors}{/if}
{$form.f.attachment|unsafe}
<tr id="form-attachment-1">
<th>{$form.f.attachment1.labelTag}:</th>
<td>{if $form.f.attachment1.errors}{$form.f.attachment1.fieldErrors}{/if}
{$form.f.attachment1|unsafe}
</td>
</tr>
<tr id="form-attachment-2">
<th>{$form.f.attachment2.labelTag}:</th>
<td>{if $form.f.attachment2.errors}{$form.f.attachment2.fieldErrors}{/if}
{$form.f.attachment2|unsafe}
</td>
</tr>
<tr id="form-attachment-3">
<th>{$form.f.attachment3.labelTag}:</th>
<td>{if $form.f.attachment3.errors}{$form.f.attachment3.fieldErrors}{/if}
{$form.f.attachment3|unsafe}
</td>
</tr>{if $isOwner or $isMember}
<tr>
</p>{/if}
</div>
{/block}
{block javascript}{if $form}{include 'idf/issues/js-autocomplete.html'}{/if}{/block}
{block javascript}{if $form}{include 'idf/issues/js-autocomplete.html'}
<script type="text/javascript">
{literal}
$(document).ready(function(){
// Hide the upload forms, we insert before the first attach file
// row an "Attach File" little link.
// We hide all the rows.
$("#form-attachment-1").before("{/literal}<tr id=\"form-block-0\"><td>&nbsp;</td><td><img style=\"vertical-align: text-bottom;\" src=\"{media '/idf/img/attachment.png'}\" alt=\" \" align=\"bottom\" /><a id=\"form-show-0\" href=\"#\">{trans 'Attach file'}{literal}</a></td></tr>");
$("#form-show-0").click(function(){
$("#form-attachment-1").show();
$("#form-block-0").hide();
});
$("#form-attachment-1 td").append("<span id=\"form-block-1\"><a id=\"form-show-1\" href=\"#\">{/literal}{trans 'Attach another file'}{literal}</a></span>");
$("#form-show-1").click(function(){
$("#form-attachment-2").show();
$("#form-block-1").hide();
});
$("#form-attachment-2 td").append("<span id=\"form-block-2\"><a id=\"form-show-2\" href=\"#\">{/literal}{trans 'Attach another file'}{literal}</a></span>");
$("#form-show-2").click(function(){
$("#form-attachment-3").show();
$("#form-block-2").hide();
});
var j=0;
for (j=1;j<4;j=j+1) {
$("#form-attachment-"+j).hide();
}
});{/literal}
</script>
{/if}{/block}

Archive Download the corresponding diff file

Page rendered in 0.09545s using 14 queries.