Differential D17464 Diff 42000 src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php
- This file was added.
| <?php | |||||
| final class PhabricatorPeopleProfileImageWorkflow | |||||
| extends PhabricatorPeopleManagementWorkflow { | |||||
| protected function didConstruct() { | |||||
| $this | |||||
| ->setName('profileimage') | |||||
| ->setExamples('**profileimage** --users __username__') | |||||
| ->setSynopsis(pht('Generate default profile images.')) | |||||
epriestley: Maybe `**profileimage** --user __username__` or similar since running it without arguments… | |||||
| ->setArguments( | |||||
| array( | |||||
| array( | |||||
| 'name' => 'user', | |||||
| 'help' => pht( | |||||
| 'Generate a default profile image for a specific user'), | |||||
| ), | |||||
| array( | |||||
Done Inline ActionsI think this is unused / doesn't work? epriestley: I think this is unused / doesn't work? | |||||
| 'name' => 'all', | |||||
| 'help' => pht( | |||||
| 'Generate default profile images for all users.'), | |||||
| ), | |||||
| array( | |||||
| 'name' => 'force', | |||||
| 'short' => 'f', | |||||
| 'help' => pht( | |||||
| 'Force a default profile image to be replaced.'), | |||||
| ), | |||||
| array( | |||||
| 'name' => 'users', | |||||
| 'wildcard' => true, | |||||
| ), | |||||
| )); | |||||
| } | |||||
| public function execute(PhutilArgumentParser $args) { | |||||
| $console = PhutilConsole::getConsole(); | |||||
| $is_force = $args->getArg('force'); | |||||
| $is_all = $args->getArg('all'); | |||||
| $is_user = $args->getArg('user'); | |||||
| $gd = function_exists('imagecreatefromstring'); | |||||
| if (!$gd) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
| 'GD is not installed for php-cli. Aborting.')); | |||||
| } | |||||
| $iterator = $this->buildIterator($args); | |||||
| if (!$iterator) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
| 'Either specify a list of users to update, or use `%s` '. | |||||
| 'to update all users.', | |||||
| '--all')); | |||||
| } | |||||
| $version = PhabricatorFilesComposeAvatarBuiltinFile::VERSION; | |||||
| foreach ($iterator as $user) { | |||||
| $username = $user->getUsername(); | |||||
| $default_phid = $user->getDefaultProfileImagePHID(); | |||||
| if ($default_phid == null || $is_force) { | |||||
| $file = id(new PhabricatorFilesComposeAvatarBuiltinFile()) | |||||
Done Inline ActionsI think it would be OK to auto-regenerate if the version was old, too. epriestley: I think it would be OK to auto-regenerate if the version was old, too. | |||||
Done Inline ActionsOh, I thought maybe we didn't want to force people to get a new image if we alter the formula? chad: Oh, I thought maybe we didn't want to force people to get a new image if we alter the formula? | |||||
| ->getUserProfileImageFile($username); | |||||
| $user->setDefaultProfileImagePHID($file->getPHID()); | |||||
| $user->setDefaultProfileImageVersion($version); | |||||
| $user->save(); | |||||
| $console->writeOut( | |||||
| "%s\n", | |||||
| pht( | |||||
| 'Generating profile image for "%s".', | |||||
| $username)); | |||||
| } else { | |||||
| $console->writeOut( | |||||
Done Inline ActionsFor consistency, prefer to format messages as full sentences (with punctuation) and quote parameters/usernames/etc where reasonable: - Generating profile image for %s + Generating profile image for "%s". epriestley: For consistency, prefer to format messages as full sentences (with punctuation) and quote… | |||||
| "%s\n", | |||||
| pht( | |||||
| 'Default profile image "%s" already set for "%s".', | |||||
| $version, | |||||
| $username)); | |||||
| } | |||||
Done Inline ActionsI don't think this is possible -- getUserProfileImageFile() always throws on error and never returns null, I believe? epriestley: I don't think this is possible -- `getUserProfileImageFile()` always throws on error and never… | |||||
| } | |||||
| } | |||||
| } | |||||
Maybe **profileimage** --user __username__ or similar since running it without arguments doesn't work so it isn't a great example?