Skip to content

Commit 4c143ad

Browse files
committedDec 7, 2013
Phragment v0
Summary: Ref T4205. This is an initial implementation of Phragment. You can create and browse fragments in the system (but you can't yet view a fragment's patches / history). Test Plan: Clicked around and created fragments. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T4205 Differential Revision: https://secure.phabricator.com/D7726
1 parent 9d47445 commit 4c143ad

16 files changed

+3047
-0
lines changed
 

‎externals/diff_match_patch/diff_match_patch.php

+2,117
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE {$NAMESPACE}_phragment.phragment_fragment (
2+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
phid VARCHAR(64) NOT NULL COLLATE utf8_bin,
4+
path VARCHAR(254) NOT NULL COLLATE utf8_bin,
5+
depth INT UNSIGNED NOT NULL,
6+
latestVersionPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
7+
viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin,
8+
editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin,
9+
dateCreated INT UNSIGNED NOT NULL,
10+
dateModified INT UNSIGNED NOT NULL,
11+
UNIQUE KEY `key_phid` (phid),
12+
UNIQUE KEY `key_path` (path)
13+
) ENGINE=InnoDB, COLLATE utf8_general_ci;
14+
15+
CREATE TABLE {$NAMESPACE}_phragment.phragment_fragmentversion (
16+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
17+
phid VARCHAR(64) NOT NULL COLLATE utf8_bin,
18+
sequence INT UNSIGNED NOT NULL,
19+
fragmentPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
20+
filePHID VARCHAR(64) NULL COLLATE utf8_bin,
21+
dateCreated INT UNSIGNED NOT NULL,
22+
dateModified INT UNSIGNED NOT NULL,
23+
UNIQUE KEY `key_version` (fragmentPHID, sequence)
24+
) ENGINE=InnoDB, COLLATE utf8_general_ci;

‎src/__phutil_library_map__.php

+32
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@
10531053
'PhabricatorApplicationPhlux' => 'applications/phlux/application/PhabricatorApplicationPhlux.php',
10541054
'PhabricatorApplicationPholio' => 'applications/pholio/application/PhabricatorApplicationPholio.php',
10551055
'PhabricatorApplicationPhortune' => 'applications/phortune/application/PhabricatorApplicationPhortune.php',
1056+
'PhabricatorApplicationPhragment' => 'applications/phragment/application/PhabricatorApplicationPhragment.php',
10561057
'PhabricatorApplicationPhrequent' => 'applications/phrequent/application/PhabricatorApplicationPhrequent.php',
10571058
'PhabricatorApplicationPhriction' => 'applications/phriction/application/PhabricatorApplicationPhriction.php',
10581059
'PhabricatorApplicationPolicy' => 'applications/policy/application/PhabricatorApplicationPolicy.php',
@@ -2173,6 +2174,17 @@
21732174
'PhortuneTestExtraPaymentProvider' => 'applications/phortune/provider/__tests__/PhortuneTestExtraPaymentProvider.php',
21742175
'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php',
21752176
'PhortuneWePayPaymentProvider' => 'applications/phortune/provider/PhortuneWePayPaymentProvider.php',
2177+
'PhragmentBrowseController' => 'applications/phragment/controller/PhragmentBrowseController.php',
2178+
'PhragmentController' => 'applications/phragment/controller/PhragmentController.php',
2179+
'PhragmentCreateController' => 'applications/phragment/controller/PhragmentCreateController.php',
2180+
'PhragmentDAO' => 'applications/phragment/storage/PhragmentDAO.php',
2181+
'PhragmentFragment' => 'applications/phragment/storage/PhragmentFragment.php',
2182+
'PhragmentFragmentQuery' => 'applications/phragment/query/PhragmentFragmentQuery.php',
2183+
'PhragmentFragmentVersion' => 'applications/phragment/storage/PhragmentFragmentVersion.php',
2184+
'PhragmentFragmentVersionQuery' => 'applications/phragment/query/PhragmentFragmentVersionQuery.php',
2185+
'PhragmentPHIDTypeFragment' => 'applications/phragment/phid/PhragmentPHIDTypeFragment.php',
2186+
'PhragmentPHIDTypeFragmentVersion' => 'applications/phragment/phid/PhragmentPHIDTypeFragmentVersion.php',
2187+
'PhragmentPatchUtil' => 'applications/phragment/util/PhragmentPatchUtil.php',
21762188
'PhrequentController' => 'applications/phrequent/controller/PhrequentController.php',
21772189
'PhrequentDAO' => 'applications/phrequent/storage/PhrequentDAO.php',
21782190
'PhrequentListController' => 'applications/phrequent/controller/PhrequentListController.php',
@@ -3488,6 +3500,7 @@
34883500
'PhabricatorApplicationPhlux' => 'PhabricatorApplication',
34893501
'PhabricatorApplicationPholio' => 'PhabricatorApplication',
34903502
'PhabricatorApplicationPhortune' => 'PhabricatorApplication',
3503+
'PhabricatorApplicationPhragment' => 'PhabricatorApplication',
34913504
'PhabricatorApplicationPhrequent' => 'PhabricatorApplication',
34923505
'PhabricatorApplicationPhriction' => 'PhabricatorApplication',
34933506
'PhabricatorApplicationPolicy' => 'PhabricatorApplication',
@@ -4749,6 +4762,25 @@
47494762
'PhortuneTestExtraPaymentProvider' => 'PhortunePaymentProvider',
47504763
'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider',
47514764
'PhortuneWePayPaymentProvider' => 'PhortunePaymentProvider',
4765+
'PhragmentBrowseController' => 'PhragmentController',
4766+
'PhragmentController' => 'PhabricatorController',
4767+
'PhragmentCreateController' => 'PhragmentController',
4768+
'PhragmentDAO' => 'PhabricatorLiskDAO',
4769+
'PhragmentFragment' =>
4770+
array(
4771+
0 => 'PhragmentDAO',
4772+
1 => 'PhabricatorPolicyInterface',
4773+
),
4774+
'PhragmentFragmentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
4775+
'PhragmentFragmentVersion' =>
4776+
array(
4777+
0 => 'PhragmentDAO',
4778+
1 => 'PhabricatorPolicyInterface',
4779+
),
4780+
'PhragmentFragmentVersionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
4781+
'PhragmentPHIDTypeFragment' => 'PhabricatorPHIDType',
4782+
'PhragmentPHIDTypeFragmentVersion' => 'PhabricatorPHIDType',
4783+
'PhragmentPatchUtil' => 'Phobject',
47524784
'PhrequentController' => 'PhabricatorController',
47534785
'PhrequentDAO' => 'PhabricatorLiskDAO',
47544786
'PhrequentListController' =>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
final class PhabricatorApplicationPhragment extends PhabricatorApplication {
4+
5+
public function getBaseURI() {
6+
return '/phragment/';
7+
}
8+
9+
public function getShortDescription() {
10+
return pht('Versioned Artifact Storage');
11+
}
12+
13+
public function getIconName() {
14+
return 'phragment';
15+
}
16+
17+
public function getTitleGlyph() {
18+
return "\xE2\x26\xB6";
19+
}
20+
21+
public function getApplicationGroup() {
22+
return self::GROUP_UTILITIES;
23+
}
24+
25+
public function isBeta() {
26+
return true;
27+
}
28+
29+
public function canUninstall() {
30+
return true;
31+
}
32+
33+
public function getRoutes() {
34+
return array(
35+
'/phragment/' => array(
36+
'' => 'PhragmentBrowseController',
37+
'browse/(?P<dblob>.*)' => 'PhragmentBrowseController',
38+
'create/(?P<dblob>.*)' => 'PhragmentCreateController',
39+
),
40+
);
41+
}
42+
43+
}
44+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
final class PhragmentBrowseController extends PhragmentController {
4+
5+
private $dblob;
6+
7+
public function willProcessRequest(array $data) {
8+
$this->dblob = idx($data, "dblob", "");
9+
}
10+
11+
public function processRequest() {
12+
$request = $this->getRequest();
13+
$viewer = $request->getUser();
14+
15+
$parents = $this->loadParentFragments($this->dblob);
16+
if ($parents === null) {
17+
return new Aphront404Response();
18+
}
19+
$current = nonempty(last($parents), null);
20+
21+
$path = '';
22+
if ($current !== null) {
23+
$path = $current->getPath();
24+
}
25+
26+
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
27+
$crumbs->addAction(
28+
id(new PHUIListItemView())
29+
->setName(pht('Create Fragment'))
30+
->setHref($this->getApplicationURI('/create/'.$path))
31+
->setIcon('create'));
32+
33+
$current_box = $this->createCurrentFragmentView($current);
34+
35+
$list = id(new PHUIObjectItemListView())
36+
->setUser($viewer);
37+
38+
$fragments = null;
39+
if ($current === null) {
40+
// Find all root fragments.
41+
$fragments = id(new PhragmentFragmentQuery())
42+
->setViewer($this->getRequest()->getUser())
43+
->needLatestVersion(true)
44+
->withDepths(array(1))
45+
->execute();
46+
} else {
47+
// Find all child fragments.
48+
$fragments = id(new PhragmentFragmentQuery())
49+
->setViewer($this->getRequest()->getUser())
50+
->needLatestVersion(true)
51+
->withLeadingPath($current->getPath().'/')
52+
->withDepths(array($current->getDepth() + 1))
53+
->execute();
54+
}
55+
56+
foreach ($fragments as $fragment) {
57+
$item = id(new PHUIObjectItemView());
58+
$item->setHeader($fragment->getName());
59+
$item->setHref($this->getApplicationURI('/browse/'.$fragment->getPath()));
60+
$item->addAttribute(pht(
61+
'Last Updated %s',
62+
phabricator_datetime(
63+
$fragment->getLatestVersion()->getDateCreated(),
64+
$viewer)));
65+
$item->addAttribute(pht(
66+
'Latest Version %s',
67+
$fragment->getLatestVersion()->getSequence()));
68+
$list->addItem($item);
69+
}
70+
71+
return $this->buildApplicationPage(
72+
array(
73+
$crumbs,
74+
$current_box,
75+
$list),
76+
array(
77+
'title' => pht('Browse Phragments'),
78+
'device' => true));
79+
}
80+
81+
private function createCurrentFragmentView($fragment) {
82+
if ($fragment === null) {
83+
return null;
84+
}
85+
86+
$viewer = $this->getRequest()->getUser();
87+
88+
$header = id(new PHUIHeaderView())
89+
->setHeader($fragment->getName())
90+
->setPolicyObject($fragment)
91+
->setUser($viewer);
92+
$properties = new PHUIPropertyListView();
93+
94+
$phids = array();
95+
$phids[] = $fragment->getLatestVersionPHID();
96+
97+
$this->loadHandles($phids);
98+
99+
$properties->addProperty(
100+
pht('Latest Version'),
101+
$this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID())));
102+
103+
return id(new PHUIObjectBoxView())
104+
->setHeader($header)
105+
->addPropertyList($properties);
106+
}
107+
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
abstract class PhragmentController extends PhabricatorController {
4+
5+
protected function loadParentFragments($path) {
6+
$components = explode('/', $path);
7+
8+
$combinations = array();
9+
$current = '';
10+
foreach ($components as $component) {
11+
$current .= '/'.$component;
12+
$current = trim($current, '/');
13+
if (trim($current) === '') {
14+
continue;
15+
}
16+
17+
$combinations[] = $current;
18+
}
19+
20+
$fragments = array();
21+
$results = id(new PhragmentFragmentQuery())
22+
->setViewer($this->getRequest()->getUser())
23+
->withPaths($combinations)
24+
->execute();
25+
foreach ($combinations as $combination) {
26+
$found = false;
27+
foreach ($results as $fragment) {
28+
if ($fragment->getPath() === $combination) {
29+
$fragments[] = $fragment;
30+
$found = true;
31+
break;
32+
}
33+
}
34+
if (!$found) {
35+
return null;
36+
}
37+
}
38+
return $fragments;
39+
}
40+
41+
protected function buildApplicationCrumbsWithPath(array $fragments) {
42+
$crumbs = $this->buildApplicationCrumbs();
43+
$crumbs->addCrumb(
44+
id(new PhabricatorCrumbView())
45+
->setName('/')
46+
->setHref('/phragment/'));
47+
foreach ($fragments as $parent) {
48+
$crumbs->addCrumb(
49+
id(new PhabricatorCrumbView())
50+
->setName($parent->getName())
51+
->setHref('/phragment/browse/'.$parent->getPath()));
52+
}
53+
return $crumbs;
54+
}
55+
56+
}

0 commit comments

Comments
 (0)
Failed to load comments.