From 95dd9dbf437a4ec71e5ff6a68d84df769cd78e01 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 19 Apr 2017 15:49:19 -0700 Subject: [PATCH] Make Applications extend LiskDAO Summary: Ref T11476. This is a bit hacky, but makes `Application` extend `LiskDAO` so we can apply transactions to it with an `Editor` class. Also fixes schema stuff so builds should produce a clean bill of health again. This might only get you slightly further, yell if you run into more trouble. Test Plan: - Ran `bin/storage upgrade -f` and got no warnings. - Browsed around, nothing exploded? Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T11476 Differential Revision: https://secure.phabricator.com/D17738 --- .../sql/autopatches/20170419.app.01.table.sql | 7 +++++ src/__phutil_library_map__.php | 11 +++++++- .../base/PhabricatorApplication.php | 26 ++++++++++++++++++- .../PhabricatorConfigDatabaseSchema.php | 7 +++++ ...catorApplicationApplicationTransaction.php | 0 ...plicationApplicationTransactionComment.php | 10 ------- .../PhabricatorApplicationSchemaSpec.php | 10 +++++++ 7 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 resources/sql/autopatches/20170419.app.01.table.sql rename src/applications/meta/{xactions => storage}/PhabricatorApplicationApplicationTransaction.php (100%) delete mode 100644 src/applications/meta/storage/PhabricatorApplicationApplicationTransactionComment.php create mode 100644 src/applications/meta/storage/PhabricatorApplicationSchemaSpec.php diff --git a/resources/sql/autopatches/20170419.app.01.table.sql b/resources/sql/autopatches/20170419.app.01.table.sql new file mode 100644 index 0000000000..257e0b3eb8 --- /dev/null +++ b/resources/sql/autopatches/20170419.app.01.table.sql @@ -0,0 +1,7 @@ +CREATE TABLE {$NAMESPACE}_application.application_application ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + phid VARBINARY(64) NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + UNIQUE KEY `key_phid` (phid) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3b56e463b7..fccc38e5cf 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1838,6 +1838,8 @@ phutil_register_library_map(array( 'PhabricatorAppSearchEngine' => 'applications/meta/query/PhabricatorAppSearchEngine.php', 'PhabricatorApplication' => 'applications/base/PhabricatorApplication.php', 'PhabricatorApplicationApplicationPHIDType' => 'applications/meta/phid/PhabricatorApplicationApplicationPHIDType.php', + 'PhabricatorApplicationApplicationTransaction' => 'applications/meta/storage/PhabricatorApplicationApplicationTransaction.php', + 'PhabricatorApplicationApplicationTransactionQuery' => 'applications/meta/query/PhabricatorApplicationApplicationTransactionQuery.php', 'PhabricatorApplicationConfigOptions' => 'applications/config/option/PhabricatorApplicationConfigOptions.php', 'PhabricatorApplicationConfigurationPanel' => 'applications/meta/panel/PhabricatorApplicationConfigurationPanel.php', 'PhabricatorApplicationConfigurationPanelTestCase' => 'applications/meta/panel/__tests__/PhabricatorApplicationConfigurationPanelTestCase.php', @@ -1849,6 +1851,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php', 'PhabricatorApplicationProfileMenuItem' => 'applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php', 'PhabricatorApplicationQuery' => 'applications/meta/query/PhabricatorApplicationQuery.php', + 'PhabricatorApplicationSchemaSpec' => 'applications/meta/storage/PhabricatorApplicationSchemaSpec.php', 'PhabricatorApplicationSearchController' => 'applications/search/controller/PhabricatorApplicationSearchController.php', 'PhabricatorApplicationSearchEngine' => 'applications/search/engine/PhabricatorApplicationSearchEngine.php', 'PhabricatorApplicationSearchEngineTestCase' => 'applications/search/engine/__tests__/PhabricatorApplicationSearchEngineTestCase.php', @@ -1881,6 +1884,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionTemplatedCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php', 'PhabricatorApplicationTransactionTextDiffDetailView' => 'applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php', 'PhabricatorApplicationTransactionTransactionPHIDType' => 'applications/transactions/phid/PhabricatorApplicationTransactionTransactionPHIDType.php', + 'PhabricatorApplicationTransactionType' => 'applications/meta/xactions/PhabricatorApplicationTransactionType.php', 'PhabricatorApplicationTransactionValidationError' => 'applications/transactions/error/PhabricatorApplicationTransactionValidationError.php', 'PhabricatorApplicationTransactionValidationException' => 'applications/transactions/exception/PhabricatorApplicationTransactionValidationException.php', 'PhabricatorApplicationTransactionValidationResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionValidationResponse.php', @@ -6847,10 +6851,13 @@ phutil_register_library_map(array( 'PhabricatorAphrontViewTestCase' => 'PhabricatorTestCase', 'PhabricatorAppSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorApplication' => array( - 'Phobject', + 'PhabricatorLiskDAO', 'PhabricatorPolicyInterface', + 'PhabricatorApplicationTransactionInterface', ), 'PhabricatorApplicationApplicationPHIDType' => 'PhabricatorPHIDType', + 'PhabricatorApplicationApplicationTransaction' => 'PhabricatorModularTransaction', + 'PhabricatorApplicationApplicationTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorApplicationConfigOptions' => 'Phobject', 'PhabricatorApplicationConfigurationPanel' => 'Phobject', 'PhabricatorApplicationConfigurationPanelTestCase' => 'PhabricatorTestCase', @@ -6862,6 +6869,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorApplicationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorApplicationSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorApplicationSearchController' => 'PhabricatorSearchBaseController', 'PhabricatorApplicationSearchEngine' => 'Phobject', 'PhabricatorApplicationSearchEngineTestCase' => 'PhabricatorTestCase', @@ -6902,6 +6910,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionTemplatedCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery', 'PhabricatorApplicationTransactionTextDiffDetailView' => 'AphrontView', 'PhabricatorApplicationTransactionTransactionPHIDType' => 'PhabricatorPHIDType', + 'PhabricatorApplicationTransactionType' => 'PhabricatorModularTransactionType', 'PhabricatorApplicationTransactionValidationError' => 'Phobject', 'PhabricatorApplicationTransactionValidationException' => 'Exception', 'PhabricatorApplicationTransactionValidationResponse' => 'AphrontProxyResponse', diff --git a/src/applications/base/PhabricatorApplication.php b/src/applications/base/PhabricatorApplication.php index 8bf784fb1e..885cdad9cf 100644 --- a/src/applications/base/PhabricatorApplication.php +++ b/src/applications/base/PhabricatorApplication.php @@ -9,7 +9,7 @@ * @task meta Application Management */ abstract class PhabricatorApplication - extends Phobject + extends PhabricatorLiskDAO implements PhabricatorPolicyInterface, PhabricatorApplicationTransactionInterface { @@ -28,6 +28,30 @@ abstract class PhabricatorApplication ); } + final public function getApplicationName() { + return 'application'; + } + + final public function getTableName() { + return 'application_application'; + } + + final protected function getConfiguration() { + return array( + self::CONFIG_AUX_PHID => true, + ) + parent::getConfiguration(); + } + + final public function generatePHID() { + return $this->getPHID(); + } + + final public function save() { + // When "save()" is called on applications, we just return without + // actually writing anything to the database. + return $this; + } + /* -( Application Information )-------------------------------------------- */ diff --git a/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php b/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php index 216a778e56..b9b407ee70 100644 --- a/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php +++ b/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php @@ -11,6 +11,13 @@ final class PhabricatorConfigDatabaseSchema public function addTable(PhabricatorConfigTableSchema $table) { $key = $table->getName(); if (isset($this->tables[$key])) { + + if ($key == 'application_application') { + // NOTE: This is a terrible hack to allow Application subclasses to + // extend LiskDAO so we can apply transactions to them. + return $this; + } + throw new Exception( pht('Trying to add duplicate table "%s"!', $key)); } diff --git a/src/applications/meta/xactions/PhabricatorApplicationApplicationTransaction.php b/src/applications/meta/storage/PhabricatorApplicationApplicationTransaction.php similarity index 100% rename from src/applications/meta/xactions/PhabricatorApplicationApplicationTransaction.php rename to src/applications/meta/storage/PhabricatorApplicationApplicationTransaction.php diff --git a/src/applications/meta/storage/PhabricatorApplicationApplicationTransactionComment.php b/src/applications/meta/storage/PhabricatorApplicationApplicationTransactionComment.php deleted file mode 100644 index ed0e1dd55e..0000000000 --- a/src/applications/meta/storage/PhabricatorApplicationApplicationTransactionComment.php +++ /dev/null @@ -1,10 +0,0 @@ -buildEdgeSchemata(new PhabricatorApplicationsApplication()); + } + +}