|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Copyright 2012 Facebook, Inc. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +$root = dirname(dirname(dirname(__FILE__))); |
| 21 | +require_once $root.'/scripts/__init_script__.php'; |
| 22 | + |
| 23 | +echo "Examining users.\n"; |
| 24 | +foreach (new LiskMigrationIterator(new PhabricatorUser()) as $user) { |
| 25 | + $file = id(new PhabricatorFile()) |
| 26 | + ->loadOneWhere('phid = %s', $user->getProfileImagePHID()); |
| 27 | + |
| 28 | + if (!$file) { |
| 29 | + echo 'No pic for user ', $user->getUserName(), "\n"; |
| 30 | + continue; |
| 31 | + } |
| 32 | + |
| 33 | + $data = $file->loadFileData(); |
| 34 | + $img = imagecreatefromstring($data); |
| 35 | + $sx = imagesx($img); |
| 36 | + $sy = imagesy($img); |
| 37 | + |
| 38 | + if ($sx != 50 || $sy != 50) { |
| 39 | + echo 'Found one! User ', $user->getUserName(), "\n"; |
| 40 | + $xformer = new PhabricatorImageTransformer(); |
| 41 | + |
| 42 | + // Resize OAuth image to a reasonable size |
| 43 | + $small_xformed = $xformer->executeProfileTransform( |
| 44 | + $file, |
| 45 | + $width = 50, |
| 46 | + $min_height = 50, |
| 47 | + $max_height = 50); |
| 48 | + |
| 49 | + $user->setProfileImagePHID($small_xformed->getPHID()); |
| 50 | + $user->save(); |
| 51 | + break; |
| 52 | + } else { |
| 53 | + echo '.'; |
| 54 | + } |
| 55 | +} |
| 56 | +echo "\n"; |
| 57 | +echo "Done.\n"; |
0 commit comments