@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a profileimage generation workflow for the cli

Summary: Ref T10319. This adds a basic means of generating default profile images for users. You can generate them for everyone, a group of users, or force updates. This only generated images and stores them in files. It does not assign them to users.

Test Plan:
`bin/people profileimage --all` to generate all images.
`bin/people profileimage --users chad` to generate a user.
`bin/people profileimage --all --force` to force rebuilding all images.

{F3662810}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T10319

Differential Revision: https://secure.phabricator.com/D17464

+161
+1
bin/people
··· 1 + ../scripts/people/manage_people.php
+20
scripts/people/manage_people.php
··· 1 + #!/usr/bin/env php 2 + <?php 3 + 4 + $root = dirname(dirname(dirname(__FILE__))); 5 + require_once $root.'/scripts/__init_script__.php'; 6 + 7 + $args = new PhutilArgumentParser($argv); 8 + $args->setSynopsis(<<<EOSYNOPSIS 9 + **people** __command__ [__options__] 10 + Manage user profiles and accounts. 11 + 12 + EOSYNOPSIS 13 + ); 14 + $args->parseStandardArguments(); 15 + 16 + $workflows = id(new PhutilClassMapQuery()) 17 + ->setAncestorClass('PhabricatorPeopleManagementWorkflow') 18 + ->execute(); 19 + $workflows[] = new PhutilHelpArgumentWorkflow(); 20 + $args->parseWorkflows($workflows);
+4
src/__phutil_library_map__.php
··· 3359 3359 'PhabricatorPeopleLogSearchEngine' => 'applications/people/query/PhabricatorPeopleLogSearchEngine.php', 3360 3360 'PhabricatorPeopleLogsController' => 'applications/people/controller/PhabricatorPeopleLogsController.php', 3361 3361 'PhabricatorPeopleManageProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php', 3362 + 'PhabricatorPeopleManagementWorkflow' => 'applications/people/management/PhabricatorPeopleManagementWorkflow.php', 3362 3363 'PhabricatorPeopleNewController' => 'applications/people/controller/PhabricatorPeopleNewController.php', 3363 3364 'PhabricatorPeopleNoOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php', 3364 3365 'PhabricatorPeopleOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleOwnerDatasource.php', ··· 3366 3367 'PhabricatorPeopleProfileBadgesController' => 'applications/people/controller/PhabricatorPeopleProfileBadgesController.php', 3367 3368 'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php', 3368 3369 'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php', 3370 + 'PhabricatorPeopleProfileImageWorkflow' => 'applications/people/management/PhabricatorPeopleProfileImageWorkflow.php', 3369 3371 'PhabricatorPeopleProfileManageController' => 'applications/people/controller/PhabricatorPeopleProfileManageController.php', 3370 3372 'PhabricatorPeopleProfileMenuEngine' => 'applications/people/engine/PhabricatorPeopleProfileMenuEngine.php', 3371 3373 'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php', ··· 8545 8547 'PhabricatorPeopleLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 8546 8548 'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController', 8547 8549 'PhabricatorPeopleManageProfileMenuItem' => 'PhabricatorProfileMenuItem', 8550 + 'PhabricatorPeopleManagementWorkflow' => 'PhabricatorManagementWorkflow', 8548 8551 'PhabricatorPeopleNewController' => 'PhabricatorPeopleController', 8549 8552 'PhabricatorPeopleNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource', 8550 8553 'PhabricatorPeopleOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource', ··· 8552 8555 'PhabricatorPeopleProfileBadgesController' => 'PhabricatorPeopleProfileController', 8553 8556 'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController', 8554 8557 'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleProfileController', 8558 + 'PhabricatorPeopleProfileImageWorkflow' => 'PhabricatorPeopleManagementWorkflow', 8555 8559 'PhabricatorPeopleProfileManageController' => 'PhabricatorPeopleProfileController', 8556 8560 'PhabricatorPeopleProfileMenuEngine' => 'PhabricatorProfileMenuEngine', 8557 8561 'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleProfileController',
+2
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
··· 7 7 private $color; 8 8 private $border; 9 9 10 + const VERSION = 'v1'; 11 + 10 12 public function setIcon($icon) { 11 13 $this->icon = $icon; 12 14 return $this;
+47
src/applications/people/management/PhabricatorPeopleManagementWorkflow.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorPeopleManagementWorkflow 4 + extends PhabricatorManagementWorkflow { 5 + 6 + protected function buildIterator(PhutilArgumentParser $args) { 7 + $usernames = $args->getArg('users'); 8 + 9 + if ($args->getArg('all')) { 10 + if ($usernames) { 11 + throw new PhutilArgumentUsageException( 12 + pht( 13 + 'Specify either a list of users or `%s`, but not both.', 14 + '--all')); 15 + } 16 + return new LiskMigrationIterator(new PhabricatorUser()); 17 + } 18 + 19 + if ($usernames) { 20 + return $this->loadUsersWithUsernames($usernames); 21 + } 22 + 23 + return null; 24 + } 25 + 26 + protected function loadUsersWithUsernames(array $usernames) { 27 + $users = array(); 28 + foreach($usernames as $username) { 29 + $query = id(new PhabricatorPeopleQuery()) 30 + ->setViewer($this->getViewer()) 31 + ->withUsernames(array($username)) 32 + ->executeOne(); 33 + 34 + if (!$query) { 35 + throw new PhutilArgumentUsageException( 36 + pht( 37 + '"%s" is not a valid username.', 38 + $username)); 39 + } 40 + $users[] = $query; 41 + } 42 + 43 + return $users; 44 + } 45 + 46 + 47 + }
+87
src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorPeopleProfileImageWorkflow 4 + extends PhabricatorPeopleManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('profileimage') 9 + ->setExamples('**profileimage** --users __username__') 10 + ->setSynopsis(pht('Generate default profile images.')) 11 + ->setArguments( 12 + array( 13 + array( 14 + 'name' => 'user', 15 + 'help' => pht( 16 + 'Generate a default profile image for a specific user'), 17 + ), 18 + array( 19 + 'name' => 'all', 20 + 'help' => pht( 21 + 'Generate default profile images for all users.'), 22 + ), 23 + array( 24 + 'name' => 'force', 25 + 'short' => 'f', 26 + 'help' => pht( 27 + 'Force a default profile image to be replaced.'), 28 + ), 29 + array( 30 + 'name' => 'users', 31 + 'wildcard' => true, 32 + ), 33 + )); 34 + } 35 + 36 + public function execute(PhutilArgumentParser $args) { 37 + $console = PhutilConsole::getConsole(); 38 + 39 + $is_force = $args->getArg('force'); 40 + $is_all = $args->getArg('all'); 41 + $is_user = $args->getArg('user'); 42 + 43 + $gd = function_exists('imagecreatefromstring'); 44 + if (!$gd) { 45 + throw new PhutilArgumentUsageException( 46 + pht( 47 + 'GD is not installed for php-cli. Aborting.')); 48 + } 49 + 50 + $iterator = $this->buildIterator($args); 51 + if (!$iterator) { 52 + throw new PhutilArgumentUsageException( 53 + pht( 54 + 'Either specify a list of users to update, or use `%s` '. 55 + 'to update all users.', 56 + '--all')); 57 + } 58 + 59 + $version = PhabricatorFilesComposeAvatarBuiltinFile::VERSION; 60 + 61 + foreach ($iterator as $user) { 62 + $username = $user->getUsername(); 63 + $default_phid = $user->getDefaultProfileImagePHID(); 64 + 65 + if ($default_phid == null || $is_force) { 66 + $file = id(new PhabricatorFilesComposeAvatarBuiltinFile()) 67 + ->getUserProfileImageFile($username); 68 + $user->setDefaultProfileImagePHID($file->getPHID()); 69 + $user->setDefaultProfileImageVersion($version); 70 + $user->save(); 71 + $console->writeOut( 72 + "%s\n", 73 + pht( 74 + 'Generating profile image for "%s".', 75 + $username)); 76 + } else { 77 + $console->writeOut( 78 + "%s\n", 79 + pht( 80 + 'Default profile image "%s" already set for "%s".', 81 + $version, 82 + $username)); 83 + } 84 + } 85 + } 86 + 87 + }