Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/patches/20130715.votecomments.php
| <?php | <?php | ||||
| echo "Moving Slowvote comments to transactions...\n"; | echo pht('Moving Slowvote comments to transactions...')."\n"; | ||||
| $viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
| $table_xaction = new PhabricatorSlowvoteTransaction(); | $table_xaction = new PhabricatorSlowvoteTransaction(); | ||||
| $table_comment = new PhabricatorSlowvoteTransactionComment(); | $table_comment = new PhabricatorSlowvoteTransactionComment(); | ||||
| $conn_w = $table_xaction->establishConnection('w'); | $conn_w = $table_xaction->establishConnection('w'); | ||||
| $comments = new LiskRawMigrationIterator($conn_w, 'slowvote_comment'); | $comments = new LiskRawMigrationIterator($conn_w, 'slowvote_comment'); | ||||
| $conn_w->openTransaction(); | $conn_w->openTransaction(); | ||||
| foreach ($comments as $comment) { | foreach ($comments as $comment) { | ||||
| $id = $comment['id']; | $id = $comment['id']; | ||||
| $poll_id = $comment['pollID']; | $poll_id = $comment['pollID']; | ||||
| $author_phid = $comment['authorPHID']; | $author_phid = $comment['authorPHID']; | ||||
| $text = $comment['commentText']; | $text = $comment['commentText']; | ||||
| $date_created = $comment['dateCreated']; | $date_created = $comment['dateCreated']; | ||||
| $date_modified = $comment['dateModified']; | $date_modified = $comment['dateModified']; | ||||
| echo "Migrating comment {$id}.\n"; | echo pht('Migrating comment %d.', $id)."\n"; | ||||
| $poll = id(new PhabricatorSlowvoteQuery()) | $poll = id(new PhabricatorSlowvoteQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($poll_id)) | ->withIDs(array($poll_id)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$poll) { | if (!$poll) { | ||||
| echo "No poll.\n"; | echo pht('No poll.')."\n"; | ||||
| continue; | continue; | ||||
| } | } | ||||
| $user = id(new PhabricatorPeopleQuery()) | $user = id(new PhabricatorPeopleQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withPHIDs(array($author_phid)) | ->withPHIDs(array($author_phid)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$user) { | if (!$user) { | ||||
| echo "No user.\n"; | echo pht('No user.')."\n"; | ||||
| continue; | continue; | ||||
| } | } | ||||
| $comment_phid = PhabricatorPHID::generateNewPHID( | $comment_phid = PhabricatorPHID::generateNewPHID( | ||||
| PhabricatorPHIDConstants::PHID_TYPE_XCMT); | PhabricatorPHIDConstants::PHID_TYPE_XCMT); | ||||
| $xaction_phid = PhabricatorPHID::generateNewPHID( | $xaction_phid = PhabricatorPHID::generateNewPHID( | ||||
| PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST, | PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST, | ||||
| PhabricatorSlowvotePollPHIDType::TYPECONST); | PhabricatorSlowvotePollPHIDType::TYPECONST); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | queryfx( | ||||
| $source, | $source, | ||||
| '{}', | '{}', | ||||
| $date_created, | $date_created, | ||||
| $date_modified); | $date_modified); | ||||
| } | } | ||||
| $conn_w->saveTransaction(); | $conn_w->saveTransaction(); | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||