1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00
phorge-phorge/resources/sql/autopatches/20180830.phriction.02.maxes.php
epriestley 3b1294cf45 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
2018-08-30 10:12:51 -07:00

30 lines
701 B
PHP

<?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']);
}