Skip to content

Commit 91ef237

Browse files
author
epriestley
committedMar 2, 2017
Add a "subtype" field to EditEngine forms
Summary: Ref T12314. This adds storage so EditEngine forms can later be marked as edit fields for particular types of objects (like an "animal edit form" vs a "plant edit form"). We'll take you to the right edit form when you click "Edit" by selecting among forms with the same subtype as the task. This doesn't do anything very interesting on its own. Test Plan: - Ran `bin/storage upgrade`. - Verified database got the field with proper values. - Created a new form, checked the database. - Ran unit tests. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12314 Differential Revision: https://secure.phabricator.com/D17439
1 parent fcd8c9c commit 91ef237

7 files changed

+87
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_search.search_editengineconfiguration
2+
ADD subtype VARCHAR(64) COLLATE {$COLLATE_TEXT} NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPDATE {$NAMESPACE}_search.search_editengineconfiguration
2+
SET subtype = 'default' WHERE subtype = '';

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,8 @@
26242624
'PhabricatorEditEngineSelectCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineSelectCommentAction.php',
26252625
'PhabricatorEditEngineSettingsPanel' => 'applications/settings/panel/PhabricatorEditEngineSettingsPanel.php',
26262626
'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php',
2627+
'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php',
2628+
'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php',
26272629
'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php',
26282630
'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php',
26292631
'PhabricatorEditPage' => 'applications/transactions/editengine/PhabricatorEditPage.php',
@@ -7678,6 +7680,8 @@
76787680
'PhabricatorEditEngineSelectCommentAction' => 'PhabricatorEditEngineCommentAction',
76797681
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
76807682
'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction',
7683+
'PhabricatorEditEngineSubtype' => 'Phobject',
7684+
'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase',
76817685
'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction',
76827686
'PhabricatorEditField' => 'Phobject',
76837687
'PhabricatorEditPage' => 'Phobject',

‎src/applications/transactions/editengine/PhabricatorEditEngine.php

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ abstract class PhabricatorEditEngine
1818

1919
const EDITENGINECONFIG_DEFAULT = 'default';
2020

21+
const SUBTYPE_DEFAULT = 'default';
22+
2123
private $viewer;
2224
private $controller;
2325
private $isCreate;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
4+
final class PhabricatorEditEngineSubtype
5+
extends Phobject {
6+
7+
const SUBTYPE_DEFAULT = 'default';
8+
9+
public static function validateSubtypeKey($subtype) {
10+
if (strlen($subtype) > 64) {
11+
throw new Exception(
12+
pht(
13+
'Subtype "%s" is not valid: subtype keys must be no longer than '.
14+
'64 bytes.',
15+
$subtype));
16+
}
17+
18+
if (strlen($subtype) < 3) {
19+
throw new Exception(
20+
pht(
21+
'Subtype "%s" is not valid: subtype keys must have a minimum '.
22+
'length of 3 bytes.',
23+
$subtype));
24+
}
25+
26+
if (!preg_match('/^[a-z]+\z/', $subtype)) {
27+
throw new Exception(
28+
pht(
29+
'Subtype "%s" is not valid: subtype keys may only contain '.
30+
'lowercase latin letters ("a" through "z").',
31+
$subtype));
32+
}
33+
}
34+
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
final class PhabricatorEditEngineSubtypeTestCase
4+
extends PhabricatorTestCase {
5+
6+
public function testEditEngineSubtypeKeys() {
7+
$map = array(
8+
// Too short.
9+
'a' => false,
10+
'ab' => false,
11+
12+
// Too long.
13+
'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'.
14+
'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' => false,
15+
16+
// Junk.
17+
'!_(#(31 1~' => false,
18+
19+
// These are reasonable and valid.
20+
'default' => true,
21+
'bug' => true,
22+
'feature' => true,
23+
'risk' => true,
24+
'security' => true,
25+
);
26+
27+
foreach ($map as $input => $expect) {
28+
try {
29+
PhabricatorEditEngineSubtype::validateSubtypeKey($input);
30+
$actual = true;
31+
} catch (Exception $ex) {
32+
$actual = false;
33+
}
34+
35+
$this->assertEqual($expect, $actual, pht('Subtype Key "%s"', $input));
36+
}
37+
}
38+
}

‎src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class PhabricatorEditEngineConfiguration
1616
protected $isEdit = 0;
1717
protected $createOrder = 0;
1818
protected $editOrder = 0;
19+
protected $subtype;
1920

2021
private $engine = self::ATTACHABLE;
2122

@@ -32,6 +33,7 @@ public static function initializeNewConfiguration(
3233
PhabricatorEditEngine $engine) {
3334

3435
return id(new PhabricatorEditEngineConfiguration())
36+
->setSubtype(PhabricatorEditEngine::SUBTYPE_DEFAULT)
3537
->setEngineKey($engine->getEngineKey())
3638
->attachEngine($engine)
3739
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy());
@@ -84,6 +86,7 @@ protected function getConfiguration() {
8486
'isEdit' => 'bool',
8587
'createOrder' => 'uint32',
8688
'editOrder' => 'uint32',
89+
'subtype' => 'text64',
8790
),
8891
self::CONFIG_KEY_SCHEMA => array(
8992
'key_engine' => array(

0 commit comments

Comments
 (0)
Failed to load comments.