@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+87
+2
resources/sql/autopatches/20170301.subtype.01.col.sql
··· 1 + ALTER TABLE {$NAMESPACE}_search.search_editengineconfiguration 2 + ADD subtype VARCHAR(64) COLLATE {$COLLATE_TEXT} NOT NULL;
+2
resources/sql/autopatches/20170301.subtype.02.default.sql
··· 1 + UPDATE {$NAMESPACE}_search.search_editengineconfiguration 2 + SET subtype = 'default' WHERE subtype = '';
+4
src/__phutil_library_map__.php
··· 2624 2624 'PhabricatorEditEngineSelectCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineSelectCommentAction.php', 2625 2625 'PhabricatorEditEngineSettingsPanel' => 'applications/settings/panel/PhabricatorEditEngineSettingsPanel.php', 2626 2626 'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php', 2627 + 'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php', 2628 + 'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php', 2627 2629 'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php', 2628 2630 'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php', 2629 2631 'PhabricatorEditPage' => 'applications/transactions/editengine/PhabricatorEditPage.php', ··· 7678 7680 'PhabricatorEditEngineSelectCommentAction' => 'PhabricatorEditEngineCommentAction', 7679 7681 'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel', 7680 7682 'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction', 7683 + 'PhabricatorEditEngineSubtype' => 'Phobject', 7684 + 'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase', 7681 7685 'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction', 7682 7686 'PhabricatorEditField' => 'Phobject', 7683 7687 'PhabricatorEditPage' => 'Phobject',
+2
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 18 18 19 19 const EDITENGINECONFIG_DEFAULT = 'default'; 20 20 21 + const SUBTYPE_DEFAULT = 'default'; 22 + 21 23 private $viewer; 22 24 private $controller; 23 25 private $isCreate;
+36
src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
··· 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 + }
+38
src/applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php
··· 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 + }
+3
src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php
··· 16 16 protected $isEdit = 0; 17 17 protected $createOrder = 0; 18 18 protected $editOrder = 0; 19 + protected $subtype; 19 20 20 21 private $engine = self::ATTACHABLE; 21 22 ··· 32 33 PhabricatorEditEngine $engine) { 33 34 34 35 return id(new PhabricatorEditEngineConfiguration()) 36 + ->setSubtype(PhabricatorEditEngine::SUBTYPE_DEFAULT) 35 37 ->setEngineKey($engine->getEngineKey()) 36 38 ->attachEngine($engine) 37 39 ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()); ··· 84 86 'isEdit' => 'bool', 85 87 'createOrder' => 'uint32', 86 88 'editOrder' => 'uint32', 89 + 'subtype' => 'text64', 87 90 ), 88 91 self::CONFIG_KEY_SCHEMA => array( 89 92 'key_engine' => array(