forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 1
Add conduit methods to search legalpad documents and signatures #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
resources/sql/autopatches/20210802.legalpad_document_signature.01.phid.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ALTER TABLE {$NAMESPACE}_legalpad.legalpad_documentsignature | ||
| ADD phid VARBINARY(64) NOT NULL; |
79 changes: 79 additions & 0 deletions
79
resources/sql/autopatches/20210802.legalpad_document_signature.02.phid-populate.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| $phid_type = PhabricatorLegalpadDocumentSignaturePHIDType::TYPECONST; | ||
|
|
||
| $docsig_table = new LegalpadDocumentSignature(); | ||
|
|
||
| $conn = $docsig_table->establishConnection('w'); | ||
| $table_name = $docsig_table->getTableName(); | ||
|
|
||
| $chunk_size = 4096; | ||
|
|
||
| $temporary_table = 'tmp_20210802_docsig_id_map'; | ||
|
|
||
| try { | ||
| queryfx( | ||
| $conn, | ||
| 'CREATE TEMPORARY TABLE %T ( | ||
| document_signature_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
| document_signature_phid VARBINARY(64) NOT NULL)', | ||
| $temporary_table); | ||
| } catch (AphrontAccessDeniedQueryException $ex) { | ||
| throw new PhutilProxyException( | ||
| pht( | ||
| 'Failed to "CREATE TEMPORARY TABLE". You may need to "GRANT" the '. | ||
| 'current MySQL user this permission.'), | ||
| $ex); | ||
| } | ||
|
|
||
| $table_iterator = id(new LiskRawMigrationIterator($conn, $table_name)) | ||
| ->setPageSize($chunk_size); | ||
|
|
||
| $chunk_iterator = new PhutilChunkedIterator($table_iterator, $chunk_size); | ||
| foreach ($chunk_iterator as $chunk) { | ||
|
|
||
| $map = array(); | ||
| foreach ($chunk as $docsig_row) { | ||
| $phid = $docsig_row['phid']; | ||
|
|
||
| if (strlen($phid)) { | ||
| continue; | ||
| } | ||
|
|
||
| $phid = PhabricatorPHID::generateNewPHID($phid_type); | ||
| $id = $docsig_row['id']; | ||
|
|
||
| $map[(int)$id] = $phid; | ||
| } | ||
|
|
||
| if (!$map) { | ||
| continue; | ||
| } | ||
|
|
||
| $sql = array(); | ||
| foreach ($map as $docsig_id => $docsig_phid) { | ||
| $sql[] = qsprintf( | ||
| $conn, | ||
| '(%d, %s)', | ||
| $docsig_id, | ||
| $docsig_phid); | ||
| } | ||
|
|
||
| queryfx( | ||
| $conn, | ||
| 'TRUNCATE TABLE %T', | ||
| $temporary_table); | ||
|
|
||
| queryfx( | ||
| $conn, | ||
| 'INSERT INTO %T (document_signature_id, document_signature_phid) VALUES %LQ', | ||
| $temporary_table, | ||
| $sql); | ||
|
|
||
| queryfx( | ||
| $conn, | ||
| 'UPDATE %T c JOIN %T x ON c.id = x.document_signature_id | ||
| SET c.phid = x.document_signature_phid', | ||
| $table_name, | ||
| $temporary_table); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/applications/legalpad/conduit/LegalpadDocumentSearchConduitAPIMethod.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| final class LegalpadDocumentSearchConduitAPIMethod | ||
| extends PhabricatorSearchEngineAPIMethod { | ||
|
|
||
| public function getAPIMethodName() { | ||
| return 'legalpad.document.search'; | ||
| } | ||
|
|
||
| public function newSearchEngine() { | ||
| return new LegalpadDocumentSearchEngine(); | ||
| } | ||
|
|
||
| public function getMethodSummary() { | ||
| return pht('Read information about legalpad documents.'); | ||
| } | ||
|
|
||
| } | ||
| ?> |
19 changes: 19 additions & 0 deletions
19
src/applications/legalpad/conduit/LegalpadSignatureSearchConduitAPIMethod.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| final class LegalpadSignatureSearchConduitAPIMethod | ||
| extends PhabricatorSearchEngineAPIMethod { | ||
|
|
||
| public function getAPIMethodName() { | ||
| return 'legalpad.signature.search'; | ||
| } | ||
|
|
||
| public function newSearchEngine() { | ||
| return new LegalpadDocumentSignatureSearchEngine(); | ||
| } | ||
|
|
||
| public function getMethodSummary() { | ||
| return pht('Read information about legalpad document signatures.'); | ||
| } | ||
|
|
||
| } | ||
| ?> |
25 changes: 25 additions & 0 deletions
25
src/applications/legalpad/engineextension/PhabricatorLegalpadBodySearchEngineAttachment.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| final class PhabricatorLegalpadBodySearchEngineAttachment | ||
| extends PhabricatorSearchEngineAttachment { | ||
|
|
||
| public function getAttachmentName() { | ||
| return pht('Legalpad Document Body'); | ||
| } | ||
|
|
||
| public function getAttachmentDescription() { | ||
| return pht('Get the full content for each document.'); | ||
| } | ||
|
|
||
| public function willLoadAttachmentData($query, $spec) { | ||
| $query->needDocumentBodies(true); | ||
| } | ||
|
|
||
| public function getAttachmentForObject($object, $data, $spec) { | ||
| return array( | ||
| 'body' => $object->getDocumentBody()->getText(), | ||
| 'preamble' => $object->getPreamble(), | ||
| ); | ||
| } | ||
|
|
||
| } |
38 changes: 38 additions & 0 deletions
38
...ications/legalpad/engineextension/PhabricatorLegalpadSignaturesSearchEngineAttachment.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| final class PhabricatorLegalpadSignaturesSearchEngineAttachment | ||
| extends PhabricatorSearchEngineAttachment { | ||
|
|
||
| public function getAttachmentName() { | ||
| return pht('Document signers'); | ||
| } | ||
|
|
||
| public function getAttachmentDescription() { | ||
| return pht('Get the signer list for the project.'); | ||
| } | ||
|
|
||
| public function willLoadAttachmentData($query, $spec) { | ||
| $query->needSignatures(true); | ||
| } | ||
|
|
||
| public function getAttachmentForObject($object, $data, $spec) { | ||
| $signers = array(); | ||
| foreach ($object->getSignatures() as $signature) { | ||
| $signatures[] = array( | ||
| 'phid' => $signature->getPHID(), | ||
| 'signerPHID' => $signature->getSignerPHID(), | ||
| 'exemptionPHID' => $signature->getExemptionPHID(), | ||
| 'isExemption' => $signature->getIsExemption(), | ||
| 'signerName' => $signature->getSignerName(), | ||
| 'signerEmail' => $signature->getSignerEmail(), | ||
| 'documentVersion' => $signature->getDocumentVersion(), | ||
| 'dateCreated' => (int)$signature->getDateCreated(), | ||
| ); | ||
| } | ||
|
|
||
| return array( | ||
| 'signatures' => $signatures | ||
| ); | ||
| } | ||
|
|
||
| } | ||
46 changes: 46 additions & 0 deletions
46
src/applications/legalpad/phid/PhabricatorLegalpadDocumentSignaturePHIDType.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| final class PhabricatorLegalpadDocumentSignaturePHIDType extends PhabricatorPHIDType { | ||
|
|
||
| const TYPECONST = 'LEGS'; | ||
|
|
||
| public function getTypeName() { | ||
| return pht('Legalpad Signature'); | ||
| } | ||
|
|
||
| public function getTypeIcon() { | ||
| return 'fa-file-text-o'; | ||
| } | ||
|
|
||
| public function newObject() { | ||
| return new LegalpadDocumentSignature(); | ||
| } | ||
|
|
||
| public function getPHIDTypeApplicationClass() { | ||
| return 'PhabricatorLegalpadApplication'; | ||
| } | ||
|
|
||
| protected function buildQueryForObjects( | ||
| PhabricatorObjectQuery $query, | ||
| array $phids) { | ||
|
|
||
| return id(new LegalpadDocumentSignatureQuery()) | ||
| ->withPHIDs($phids); | ||
| } | ||
|
|
||
| public function loadHandles( | ||
| PhabricatorHandleQuery $query, | ||
| array $handles, | ||
| array $objects) { | ||
|
|
||
| foreach ($handles as $phid => $handle) { | ||
| $sig = $objects[$phid]; | ||
| $id = $sig->getID(); | ||
| $handle->setName("Signature ".$id); | ||
|
|
||
| $signerName = $sig->getSignerName(); | ||
| $handle->setFullName("Signature {$id} by {$signerName}"); | ||
| $handle->setURI("/legalpad/signature/{$id}"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.