Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/autopatches/20141107.phriction.popkeys.php
| <?php | <?php | ||||
| $table = new PhrictionDocument(); | $table = new PhrictionDocument(); | ||||
| $conn_w = $table->establishConnection('w'); | $conn_w = $table->establishConnection('w'); | ||||
| echo "Populating Phriction mailkeys.\n"; | echo pht('Populating Phriction mailkeys.')."\n"; | ||||
| foreach (new LiskMigrationIterator($table) as $doc) { | foreach (new LiskMigrationIterator($table) as $doc) { | ||||
| $id = $doc->getID(); | $id = $doc->getID(); | ||||
| $key = $doc->getMailKey(); | $key = $doc->getMailKey(); | ||||
| if ((strlen($key) == 20) && (strpos($key, "\0") === false)) { | if ((strlen($key) == 20) && (strpos($key, "\0") === false)) { | ||||
| // To be valid, keys must have length 20 and not contain any null bytes. | // To be valid, keys must have length 20 and not contain any null bytes. | ||||
| // See T6487. | // See T6487. | ||||
| echo "Document has valid mailkey.\n"; | echo pht('Document has valid mailkey.')."\n"; | ||||
| continue; | continue; | ||||
| } else { | } else { | ||||
| echo "Populating mailkey for document {$id}...\n"; | echo pht('Populating mailkey for document %d...', $id)."\n"; | ||||
| $mail_key = Filesystem::readRandomCharacters(20); | $mail_key = Filesystem::readRandomCharacters(20); | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET mailKey = %s WHERE id = %d', | 'UPDATE %T SET mailKey = %s WHERE id = %d', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| $mail_key, | $mail_key, | ||||
| $id); | $id); | ||||
| } | } | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||