Remove product literal strings in "pht()", part 21
[phabricator.git] / resources / sql / autopatches / 20170316.rawfiles.01.php
blobdf2fa93c9a3c03ee99361db617daf129baa5d270
1 <?php
3 // Previously, files generated by "View Raw File" were written as permanent
4 // files with excessively wide view permissions. This destroys these files
5 // so they are recreated as temporary files with correct permissions when
6 // next accessed.
8 $table = new DifferentialChangeset();
9 $conn = $table->establishConnection('w');
10 $viewer = PhabricatorUser::getOmnipotentUser();
12 $iterator = new LiskRawMigrationIterator(
13 $conn,
14 $table->getTableName());
16 echo tsprintf(
17 "%s\n",
18 pht('Purging old raw changeset file caches...'));
20 $keys = array(
21 'raw:new:phid',
22 'raw:old:phid',
25 foreach ($iterator as $changeset) {
26 try {
27 $metadata = phutil_json_decode($changeset['metadata']);
29 $phids = array();
30 foreach ($keys as $key) {
31 if (isset($metadata[$key])) {
32 $phids[] = $metadata[$key];
36 foreach ($phids as $phid) {
37 $file = id(new PhabricatorFileQuery())
38 ->setViewer($viewer)
39 ->withPHIDs(array($phid))
40 ->executeOne();
41 if ($file) {
42 id(new PhabricatorDestructionEngine())
43 ->destroyObject($file);
47 // NOTE: We don't bother updating the changeset record itself: we already
48 // regenerate the cache properly if the stored value isn't valid.
50 } catch (Exception $ex) {
51 // Just move on if we run into trouble.