Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15425266
D19625.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D19625.diff
View Options
diff --git a/resources/sql/autopatches/20180830.phriction.01.maxversion.sql b/resources/sql/autopatches/20180830.phriction.01.maxversion.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20180830.phriction.01.maxversion.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_phriction.phriction_document
+ ADD maxVersion INT UNSIGNED NOT NULL;
diff --git a/resources/sql/autopatches/20180830.phriction.02.maxes.php b/resources/sql/autopatches/20180830.phriction.02.maxes.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20180830.phriction.02.maxes.php
@@ -0,0 +1,30 @@
+<?php
+
+// Populate the "maxVersion" column by copying the maximum "version" from the
+// content table.
+
+$document_table = new PhrictionDocument();
+$content_table = new PhrictionContent();
+
+$conn = $document_table->establishConnection('w');
+
+$iterator = new LiskRawMigrationIterator(
+ $conn,
+ $document_table->getTableName());
+foreach ($iterator as $row) {
+ $content = queryfx_one(
+ $conn,
+ 'SELECT MAX(version) max FROM %T WHERE documentPHID = %s',
+ $content_table->getTableName(),
+ $row['phid']);
+ if (!$content) {
+ continue;
+ }
+
+ queryfx(
+ $conn,
+ 'UPDATE %T SET maxVersion = %d WHERE id = %d',
+ $document_table->getTableName(),
+ $content['max'],
+ $row['id']);
+}
diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php
--- a/src/applications/phriction/controller/PhrictionDocumentController.php
+++ b/src/applications/phriction/controller/PhrictionDocumentController.php
@@ -66,12 +66,7 @@
->addAction($create_button);
} else {
- $draft_content = id(new PhrictionContentQuery())
- ->setViewer($viewer)
- ->withDocumentPHIDs(array($document->getPHID()))
- ->setLimit(1)
- ->executeOne();
- $max_version = (int)$draft_content->getVersion();
+ $max_version = (int)$document->getMaxVersion();
$version = $request->getInt('v');
if ($version) {
diff --git a/src/applications/phriction/controller/PhrictionEditController.php b/src/applications/phriction/controller/PhrictionEditController.php
--- a/src/applications/phriction/controller/PhrictionEditController.php
+++ b/src/applications/phriction/controller/PhrictionEditController.php
@@ -7,7 +7,7 @@
$viewer = $request->getViewer();
$id = $request->getURIData('id');
- $current_version = null;
+ $max_version = null;
if ($id) {
$is_new = false;
$document = id(new PhrictionDocumentQuery())
@@ -24,7 +24,7 @@
return new Aphront404Response();
}
- $current_version = $document->getContent()->getVersion();
+ $max_version = $document->getMaxVersion();
$revert = $request->getInt('revert');
if ($revert) {
@@ -37,9 +37,12 @@
return new Aphront404Response();
}
} else {
- $content = $document->getContent();
+ $content = id(new PhrictionContentQuery())
+ ->setViewer($viewer)
+ ->withDocumentPHIDs(array($document->getPHID()))
+ ->setLimit(1)
+ ->executeOne();
}
-
} else {
$slug = $request->getStr('slug');
$slug = PhabricatorSlug::normalize($slug);
@@ -54,8 +57,13 @@
->executeOne();
if ($document) {
- $content = $document->getContent();
- $current_version = $content->getVersion();
+ $content = id(new PhrictionContentQuery())
+ ->setViewer($viewer)
+ ->withDocumentPHIDs(array($document->getPHID()))
+ ->setLimit(1)
+ ->executeOne();
+
+ $max_version = $document->getMaxVersion();
$is_new = false;
} else {
$document = PhrictionDocument::initializeNewDocument($viewer, $slug);
@@ -128,7 +136,7 @@
$title = $request->getStr('title');
$content_text = $request->getStr('content');
$notes = $request->getStr('description');
- $current_version = $request->getInt('contentVersion');
+ $max_version = $request->getInt('contentVersion');
$v_view = $request->getStr('viewPolicy');
$v_edit = $request->getStr('editPolicy');
$v_cc = $request->getArr('cc');
@@ -168,7 +176,7 @@
->setContinueOnNoEffect(true)
->setDescription($notes)
->setProcessContentVersionError(!$request->getBool('overwrite'))
- ->setContentVersion($current_version);
+ ->setContentVersion($max_version);
try {
$editor->applyTransactions($document, $xactions);
@@ -232,7 +240,7 @@
->setUser($viewer)
->addHiddenInput('slug', $document->getSlug())
->addHiddenInput('nodraft', $request->getBool('nodraft'))
- ->addHiddenInput('contentVersion', $current_version)
+ ->addHiddenInput('contentVersion', $max_version)
->addHiddenInput('overwrite', $overwrite)
->appendChild(
id(new AphrontFormTextControl())
diff --git a/src/applications/phriction/editor/PhrictionTransactionEditor.php b/src/applications/phriction/editor/PhrictionTransactionEditor.php
--- a/src/applications/phriction/editor/PhrictionTransactionEditor.php
+++ b/src/applications/phriction/editor/PhrictionTransactionEditor.php
@@ -468,7 +468,7 @@
$error = null;
if ($this->getContentVersion() &&
- ($object->getContent()->getVersion() != $this->getContentVersion())) {
+ ($object->getMaxVersion() != $this->getContentVersion())) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Edit Conflict'),
@@ -519,6 +519,7 @@
$document->setContentPHID($content_phid);
$document->attachContent($content);
$document->setEditedEpoch(PhabricatorTime::getNow());
+ $document->setMaxVersion($content->getVersion());
$this->newContent = $content;
}
@@ -539,7 +540,7 @@
$content->setDescription($this->getDescription());
}
- $content->setVersion($this->getOldContent()->getVersion() + 1);
+ $content->setVersion($document->getMaxVersion() + 1);
return $content;
}
diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php
--- a/src/applications/phriction/storage/PhrictionDocument.php
+++ b/src/applications/phriction/storage/PhrictionDocument.php
@@ -23,6 +23,7 @@
protected $editPolicy;
protected $spacePHID;
protected $editedEpoch;
+ protected $maxVersion;
private $contentObject = self::ATTACHABLE;
private $ancestors = array();
@@ -36,6 +37,7 @@
'depth' => 'uint32',
'status' => 'text32',
'editedEpoch' => 'epoch',
+ 'maxVersion' => 'uint32',
),
self::CONFIG_KEY_SCHEMA => array(
'slug' => array(
@@ -89,6 +91,7 @@
}
$document->setEditedEpoch(PhabricatorTime::getNow());
+ $document->setMaxVersion(0);
return $document;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 24, 3:39 AM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7451999
Default Alt Text
D19625.diff (6 KB)
Attached To
Mode
D19625: Store Phriction max version on Document, improve editing rules for editing documents with drafts
Attached
Detach File
Event Timeline
Log In to Comment