Indefero

Indefero Commit Details


Date:2011-12-06 01:13:06 (13 years 16 days ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:22dfab253babbd85e58b285749b78403fa597b96
Parents: a1c8a4943045765a2a317682be3192e9a6aa7c15
Message:Implement resource deletion.

Changes:

File differences

src/IDF/Form/WikiResourceDelete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;
}
}
src/IDF/Views/Wiki.php
570570
571571
572572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
573612
574613
575614
}
/**
* Delete a Wiki resource.
*/
public $deleteResource_precond = array('IDF_Precondition::accessWiki',
'IDF_Precondition::projectMemberOrOwner');
public function deleteResource($request, $match)
{
$prj = $request->project;
$resource = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_Resource', $match[2]);
$prj->inOr404($resource);
$params = array('resource' => $resource);
if ($request->method == 'POST') {
$form = new IDF_Form_WikiResourceDelete($request->POST, $params);
if ($form->isValid()) {
$form->save();
$request->user->setMessage(__('The documentation resource has been deleted.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listResources',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$form = new IDF_Form_WikiResourceDelete(null, $params);
}
$title = sprintf(__('Delete Resource %s'), $resource->title);
$revision = $resource->get_current_revision();
$false = Pluf_DB_BooleanToDb(false, $resource->getDbConnection());
$revs = $resource->get_revisions_list(array('order' => 'creation_dtime DESC',
'filter' => 'is_head='.$false));
return Pluf_Shortcuts_RenderToResponse('idf/wiki/deleteResource.html',
array(
'page_title' => $title,
'resource' => $resource,
'form' => $form,
'rev' => $revision,
'revs' => $revs,
),
$request);
}
/**
* Get the wiki tags.
*
* @param IDF_Project
src/IDF/Wiki/ResourceRevision.php
123123
124124
125125
126
127
126
128127
129128
130129
......
132131
133132
134133
135
136
137134
138135
139136
function preDelete()
{
// if we kill off a head revision, ensure that we either mark a previous
// revision as head or kill off the resource record as well
// if we kill off a head revision, ensure that we either mark a previous revision as head
if ($this->is_head) {
$sql = new Pluf_SQL('wikiresource=%s and id!=%s', array($this->wikiresource, $this->id));
$revs = Pluf::factory('IDF_Wiki_ResourceRevision')->getList(array('filter'=>$sql->gen(), 'order'=>'id DESC'));
$previous = $revs[0];
$previous->is_head = true;
$previous->update();
} else {
$this->get_wikiresource()->delete();
}
}
src/IDF/templates/idf/wiki/deleteResource.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{extends "idf/wiki/base.html"}
{block docclass}yui-t3{assign $inResourceView=true}{/block}
{block body}
<p>{blocktrans}If you delete this documentation resource, it will be removed from the database with all the associated revisions
and <strong>you will not be able to recover it</strong>. Any documentation pages that reference this resource,
will no longer be able to render it, but won't be deleted.{/blocktrans}</p>
<form method="post" action=".">
<table class="form" summary="">
<tr>
<td>&nbsp;</td>
<td>
{$form.f.confirm|unsafe} <strong>{$form.f.confirm.labelTag}</strong><br />
{if $form.f.confirm.errors}{$form.f.confirm.fieldErrors}{/if}
<input type="submit" value="{trans 'Delete Resource'}" name="submit" /> | <a href="{url 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title)}">{trans 'Cancel'}</a>
</td>
</tr>
</table>
</form>
<p class="desc">{$resource.summary}</p>
{assign $preview = $rev.renderRaw()}
{if $preview == ''}
{assign $preview = __('Unable to render preview for this MIME type.')}
{/if}
<p class="preview">{$preview|unsafe}</p>
<ul>
<li>{trans 'File size'}: {$rev.filesize|size}</li>
<li>{trans 'MIME type'}: {$resource.mime_type}</li>
<li><a href="{$rev.getRawURL(true)}">{trans 'Download this file'}</a></li>
</ul>
{/block}
{block context}
{assign $submitter = $resource.get_submitter()}
<p><strong>{trans 'Created:'}</strong> <span class="nobrk">{$resource.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>
{if $rev.creation_dtime != $resource.creation_dtime}<p>{assign $submitter = $rev.get_submitter()}
<strong>{trans 'Updated:'}</strong> <span class="nobrk">{$rev.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>{/if}
{if $revs.count() > 0}
<p><strong>{trans 'Old Revisions'}</strong></p>
<ul>{foreach $revs as $old}
<li><a href="{url 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title), array('rev'=>$old.id)}">{$old.summary}</a></li>
{/foreach}</ul>
{/if}
{/block}

Archive Download the corresponding diff file

Page rendered in 0.09608s using 13 queries.