[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/autopatches/ -> 20141106.uniqdrafts.php (source)

   1  <?php
   2  
   3  // Destroy duplicate drafts before storage adjustment adds a unique key to this
   4  // table. See T1191. We retain the newest draft.
   5  
   6  // (We can't easily do this in a single SQL statement because MySQL won't let us
   7  // modify a table that's joined in a subquery.)
   8  
   9  $table = new DifferentialDraft();
  10  $conn_w = $table->establishConnection('w');
  11  
  12  $duplicates = queryfx_all(
  13    $conn_w,
  14    'SELECT DISTINCT u.id id FROM %T u
  15      JOIN %T v
  16        ON u.objectPHID = v.objectPHID
  17        AND u.authorPHID = v.authorPHID
  18        AND u.draftKey = v.draftKey
  19        AND u.id < v.id',
  20    $table->getTableName(),
  21    $table->getTableName());
  22  
  23  $duplicates = ipull($duplicates, 'id');
  24  foreach (PhabricatorLiskDAO::chunkSQL($duplicates) as $chunk) {
  25    queryfx(
  26      $conn_w,
  27      'DELETE FROM %T WHERE id IN (%Q)',
  28      $table->getTableName(),
  29      $chunk);
  30  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1