establishConnection('w'); $provider_table = new PhabricatorAuthFactorProvider(); $provider_phid = null; $iterator = new LiskRawMigrationIterator($conn, $table->getTableName()); $totp_key = 'totp'; foreach ($iterator as $row) { // This wasn't a TOTP factor, so skip it. if ($row['factorKey'] !== $totp_key) { continue; } // This factor already has an associated provider. if (strlen($row['factorProviderPHID'])) { continue; } // Find (or create) a suitable TOTP provider. Note that we can't "save()" // an object or this migration will break if the object ever gets new // columns; just INSERT the raw fields instead. if ($provider_phid === null) { $provider_row = queryfx_one( $conn, 'SELECT phid FROM %R WHERE providerFactorKey = %s LIMIT 1', $provider_table, $totp_key); if ($provider_row) { $provider_phid = $provider_row['phid']; } else { $provider_phid = $provider_table->generatePHID(); queryfx( $conn, 'INSERT INTO %R (phid, providerFactorKey, name, status, properties, dateCreated, dateModified) VALUES (%s, %s, %s, %s, %s, %d, %d)', $provider_table, $provider_phid, $totp_key, '', 'active', '{}', PhabricatorTime::getNow(), PhabricatorTime::getNow()); } } queryfx( $conn, 'UPDATE %R SET factorProviderPHID = %s WHERE id = %d', $table, $provider_phid, $row['id']); }