forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhragmentUpdateController.php
80 lines (63 loc) · 2.29 KB
/
PhragmentUpdateController.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
final class PhragmentUpdateController extends PhragmentController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$dblob = $request->getURIData('dblob');
$parents = $this->loadParentFragments($dblob);
if ($parents === null) {
return new Aphront404Response();
}
$fragment = idx($parents, count($parents) - 1, null);
$error_view = null;
if ($request->isFormPost()) {
$errors = array();
$v_fileid = $request->getInt('fileID');
$file = id(new PhabricatorFile())->load($v_fileid);
if ($file === null) {
$errors[] = pht('The specified file doesn\'t exist.');
}
if (!count($errors)) {
// If the file is a ZIP archive (has application/zip mimetype)
// then we extract the zip and apply versions for each of the
// individual fragments, creating and deleting files as needed.
if ($file->getMimeType() === 'application/zip') {
$fragment->updateFromZIP($viewer, $file);
} else {
$fragment->updateFromFile($viewer, $file);
}
return id(new AphrontRedirectResponse())
->setURI('/phragment/browse/'.$fragment->getPath());
} else {
$error_view = id(new PHUIInfoView())
->setErrors($errors)
->setTitle(pht('Errors while updating fragment'));
}
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('File ID'))
->setName('fileID'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Update Fragment'))
->addCancelButton(
$this->getApplicationURI('browse/'.$fragment->getPath())));
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
$crumbs->addTextCrumb(pht('Update Fragment'));
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Update Fragment: %s', $fragment->getPath()))
->setValidationException(null)
->setForm($form);
$title = pht('Update Fragment');
$view = array(
$this->renderConfigurationWarningIfRequired(),
$box,
);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
}