@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Store Phriction max version on Document, improve editing rules for editing documents with drafts

Summary:
Ref T13077. We need to know the maximum version of a document in several cases, so denormalize it onto the Document object.

Then clean up some behaviors where we edit a document with, e.g., 7 versions but version 5 is currently published. For now, we: edit starting with version 7, save as version 8, and immediately publish the new version.

Test Plan:
- Ran migration.
- Edited a draft page without hitting any weird version errors.
- Checked database for sensible `maxVersion` values.

Reviewers: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13077

Differential Revision: https://secure.phabricator.com/D19625

+56 -17
+2
resources/sql/autopatches/20180830.phriction.01.maxversion.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phriction.phriction_document 2 + ADD maxVersion INT UNSIGNED NOT NULL;
+30
resources/sql/autopatches/20180830.phriction.02.maxes.php
··· 1 + <?php 2 + 3 + // Populate the "maxVersion" column by copying the maximum "version" from the 4 + // content table. 5 + 6 + $document_table = new PhrictionDocument(); 7 + $content_table = new PhrictionContent(); 8 + 9 + $conn = $document_table->establishConnection('w'); 10 + 11 + $iterator = new LiskRawMigrationIterator( 12 + $conn, 13 + $document_table->getTableName()); 14 + foreach ($iterator as $row) { 15 + $content = queryfx_one( 16 + $conn, 17 + 'SELECT MAX(version) max FROM %T WHERE documentPHID = %s', 18 + $content_table->getTableName(), 19 + $row['phid']); 20 + if (!$content) { 21 + continue; 22 + } 23 + 24 + queryfx( 25 + $conn, 26 + 'UPDATE %T SET maxVersion = %d WHERE id = %d', 27 + $document_table->getTableName(), 28 + $content['max'], 29 + $row['id']); 30 + }
+1 -6
src/applications/phriction/controller/PhrictionDocumentController.php
··· 66 66 ->addAction($create_button); 67 67 68 68 } else { 69 - $draft_content = id(new PhrictionContentQuery()) 70 - ->setViewer($viewer) 71 - ->withDocumentPHIDs(array($document->getPHID())) 72 - ->setLimit(1) 73 - ->executeOne(); 74 - $max_version = (int)$draft_content->getVersion(); 69 + $max_version = (int)$document->getMaxVersion(); 75 70 76 71 $version = $request->getInt('v'); 77 72 if ($version) {
+17 -9
src/applications/phriction/controller/PhrictionEditController.php
··· 7 7 $viewer = $request->getViewer(); 8 8 $id = $request->getURIData('id'); 9 9 10 - $current_version = null; 10 + $max_version = null; 11 11 if ($id) { 12 12 $is_new = false; 13 13 $document = id(new PhrictionDocumentQuery()) ··· 24 24 return new Aphront404Response(); 25 25 } 26 26 27 - $current_version = $document->getContent()->getVersion(); 27 + $max_version = $document->getMaxVersion(); 28 28 29 29 $revert = $request->getInt('revert'); 30 30 if ($revert) { ··· 37 37 return new Aphront404Response(); 38 38 } 39 39 } else { 40 - $content = $document->getContent(); 40 + $content = id(new PhrictionContentQuery()) 41 + ->setViewer($viewer) 42 + ->withDocumentPHIDs(array($document->getPHID())) 43 + ->setLimit(1) 44 + ->executeOne(); 41 45 } 42 - 43 46 } else { 44 47 $slug = $request->getStr('slug'); 45 48 $slug = PhabricatorSlug::normalize($slug); ··· 54 57 ->executeOne(); 55 58 56 59 if ($document) { 57 - $content = $document->getContent(); 58 - $current_version = $content->getVersion(); 60 + $content = id(new PhrictionContentQuery()) 61 + ->setViewer($viewer) 62 + ->withDocumentPHIDs(array($document->getPHID())) 63 + ->setLimit(1) 64 + ->executeOne(); 65 + 66 + $max_version = $document->getMaxVersion(); 59 67 $is_new = false; 60 68 } else { 61 69 $document = PhrictionDocument::initializeNewDocument($viewer, $slug); ··· 128 136 $title = $request->getStr('title'); 129 137 $content_text = $request->getStr('content'); 130 138 $notes = $request->getStr('description'); 131 - $current_version = $request->getInt('contentVersion'); 139 + $max_version = $request->getInt('contentVersion'); 132 140 $v_view = $request->getStr('viewPolicy'); 133 141 $v_edit = $request->getStr('editPolicy'); 134 142 $v_cc = $request->getArr('cc'); ··· 168 176 ->setContinueOnNoEffect(true) 169 177 ->setDescription($notes) 170 178 ->setProcessContentVersionError(!$request->getBool('overwrite')) 171 - ->setContentVersion($current_version); 179 + ->setContentVersion($max_version); 172 180 173 181 try { 174 182 $editor->applyTransactions($document, $xactions); ··· 232 240 ->setUser($viewer) 233 241 ->addHiddenInput('slug', $document->getSlug()) 234 242 ->addHiddenInput('nodraft', $request->getBool('nodraft')) 235 - ->addHiddenInput('contentVersion', $current_version) 243 + ->addHiddenInput('contentVersion', $max_version) 236 244 ->addHiddenInput('overwrite', $overwrite) 237 245 ->appendChild( 238 246 id(new AphrontFormTextControl())
+3 -2
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 468 468 469 469 $error = null; 470 470 if ($this->getContentVersion() && 471 - ($object->getContent()->getVersion() != $this->getContentVersion())) { 471 + ($object->getMaxVersion() != $this->getContentVersion())) { 472 472 $error = new PhabricatorApplicationTransactionValidationError( 473 473 $type, 474 474 pht('Edit Conflict'), ··· 519 519 $document->setContentPHID($content_phid); 520 520 $document->attachContent($content); 521 521 $document->setEditedEpoch(PhabricatorTime::getNow()); 522 + $document->setMaxVersion($content->getVersion()); 522 523 523 524 $this->newContent = $content; 524 525 } ··· 539 540 $content->setDescription($this->getDescription()); 540 541 } 541 542 542 - $content->setVersion($this->getOldContent()->getVersion() + 1); 543 + $content->setVersion($document->getMaxVersion() + 1); 543 544 544 545 return $content; 545 546 }
+3
src/applications/phriction/storage/PhrictionDocument.php
··· 23 23 protected $editPolicy; 24 24 protected $spacePHID; 25 25 protected $editedEpoch; 26 + protected $maxVersion; 26 27 27 28 private $contentObject = self::ATTACHABLE; 28 29 private $ancestors = array(); ··· 36 37 'depth' => 'uint32', 37 38 'status' => 'text32', 38 39 'editedEpoch' => 'epoch', 40 + 'maxVersion' => 'uint32', 39 41 ), 40 42 self::CONFIG_KEY_SCHEMA => array( 41 43 'slug' => array( ··· 89 91 } 90 92 91 93 $document->setEditedEpoch(PhabricatorTime::getNow()); 94 + $document->setMaxVersion(0); 92 95 93 96 return $document; 94 97 }