diff --git a/bin/people b/bin/people new file mode 120000 index 0000000000..985dc4849a --- /dev/null +++ b/bin/people @@ -0,0 +1 @@ +../scripts/people/manage_people.php \ No newline at end of file diff --git a/scripts/people/manage_people.php b/scripts/people/manage_people.php new file mode 100755 index 0000000000..aeada86da0 --- /dev/null +++ b/scripts/people/manage_people.php @@ -0,0 +1,20 @@ +#!/usr/bin/env php +setSynopsis(<<parseStandardArguments(); + +$workflows = id(new PhutilClassMapQuery()) + ->setAncestorClass('PhabricatorPeopleManagementWorkflow') + ->execute(); +$workflows[] = new PhutilHelpArgumentWorkflow(); +$args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7edaf5b486..600f30601c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3359,6 +3359,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleLogSearchEngine' => 'applications/people/query/PhabricatorPeopleLogSearchEngine.php', 'PhabricatorPeopleLogsController' => 'applications/people/controller/PhabricatorPeopleLogsController.php', 'PhabricatorPeopleManageProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php', + 'PhabricatorPeopleManagementWorkflow' => 'applications/people/management/PhabricatorPeopleManagementWorkflow.php', 'PhabricatorPeopleNewController' => 'applications/people/controller/PhabricatorPeopleNewController.php', 'PhabricatorPeopleNoOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php', 'PhabricatorPeopleOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleOwnerDatasource.php', @@ -3366,6 +3367,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleProfileBadgesController' => 'applications/people/controller/PhabricatorPeopleProfileBadgesController.php', 'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php', 'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php', + 'PhabricatorPeopleProfileImageWorkflow' => 'applications/people/management/PhabricatorPeopleProfileImageWorkflow.php', 'PhabricatorPeopleProfileManageController' => 'applications/people/controller/PhabricatorPeopleProfileManageController.php', 'PhabricatorPeopleProfileMenuEngine' => 'applications/people/engine/PhabricatorPeopleProfileMenuEngine.php', 'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php', @@ -8545,6 +8547,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController', 'PhabricatorPeopleManageProfileMenuItem' => 'PhabricatorProfileMenuItem', + 'PhabricatorPeopleManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorPeopleNewController' => 'PhabricatorPeopleController', 'PhabricatorPeopleNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorPeopleOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource', @@ -8552,6 +8555,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleProfileBadgesController' => 'PhabricatorPeopleProfileController', 'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController', 'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleProfileController', + 'PhabricatorPeopleProfileImageWorkflow' => 'PhabricatorPeopleManagementWorkflow', 'PhabricatorPeopleProfileManageController' => 'PhabricatorPeopleProfileController', 'PhabricatorPeopleProfileMenuEngine' => 'PhabricatorProfileMenuEngine', 'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleProfileController', diff --git a/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php b/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php index 29acacc188..7eca716e34 100644 --- a/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php +++ b/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php @@ -7,6 +7,8 @@ final class PhabricatorFilesComposeAvatarBuiltinFile private $color; private $border; + const VERSION = 'v1'; + public function setIcon($icon) { $this->icon = $icon; return $this; diff --git a/src/applications/people/management/PhabricatorPeopleManagementWorkflow.php b/src/applications/people/management/PhabricatorPeopleManagementWorkflow.php new file mode 100644 index 0000000000..67b474f7e2 --- /dev/null +++ b/src/applications/people/management/PhabricatorPeopleManagementWorkflow.php @@ -0,0 +1,47 @@ +getArg('users'); + + if ($args->getArg('all')) { + if ($usernames) { + throw new PhutilArgumentUsageException( + pht( + 'Specify either a list of users or `%s`, but not both.', + '--all')); + } + return new LiskMigrationIterator(new PhabricatorUser()); + } + + if ($usernames) { + return $this->loadUsersWithUsernames($usernames); + } + + return null; + } + + protected function loadUsersWithUsernames(array $usernames) { + $users = array(); + foreach($usernames as $username) { + $query = id(new PhabricatorPeopleQuery()) + ->setViewer($this->getViewer()) + ->withUsernames(array($username)) + ->executeOne(); + + if (!$query) { + throw new PhutilArgumentUsageException( + pht( + '"%s" is not a valid username.', + $username)); + } + $users[] = $query; + } + + return $users; + } + + +} diff --git a/src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php b/src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php new file mode 100644 index 0000000000..069f5c01f0 --- /dev/null +++ b/src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php @@ -0,0 +1,87 @@ +setName('profileimage') + ->setExamples('**profileimage** --users __username__') + ->setSynopsis(pht('Generate default profile images.')) + ->setArguments( + array( + array( + 'name' => 'user', + 'help' => pht( + 'Generate a default profile image for a specific user'), + ), + array( + '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()) + ->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( + "%s\n", + pht( + 'Default profile image "%s" already set for "%s".', + $version, + $username)); + } + } + } + +}