Skip to content

Commit 3a86894

Browse files
author
Chad Little
committedMar 4, 2017
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
1 parent be16f9b commit 3a86894

6 files changed

+161
-0
lines changed
 

‎bin/people

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/people/manage_people.php

‎scripts/people/manage_people.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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);

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -3359,13 +3359,15 @@
33593359
'PhabricatorPeopleLogSearchEngine' => 'applications/people/query/PhabricatorPeopleLogSearchEngine.php',
33603360
'PhabricatorPeopleLogsController' => 'applications/people/controller/PhabricatorPeopleLogsController.php',
33613361
'PhabricatorPeopleManageProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php',
3362+
'PhabricatorPeopleManagementWorkflow' => 'applications/people/management/PhabricatorPeopleManagementWorkflow.php',
33623363
'PhabricatorPeopleNewController' => 'applications/people/controller/PhabricatorPeopleNewController.php',
33633364
'PhabricatorPeopleNoOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php',
33643365
'PhabricatorPeopleOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleOwnerDatasource.php',
33653366
'PhabricatorPeoplePictureProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php',
33663367
'PhabricatorPeopleProfileBadgesController' => 'applications/people/controller/PhabricatorPeopleProfileBadgesController.php',
33673368
'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php',
33683369
'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php',
3370+
'PhabricatorPeopleProfileImageWorkflow' => 'applications/people/management/PhabricatorPeopleProfileImageWorkflow.php',
33693371
'PhabricatorPeopleProfileManageController' => 'applications/people/controller/PhabricatorPeopleProfileManageController.php',
33703372
'PhabricatorPeopleProfileMenuEngine' => 'applications/people/engine/PhabricatorPeopleProfileMenuEngine.php',
33713373
'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php',
@@ -8545,13 +8547,15 @@
85458547
'PhabricatorPeopleLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
85468548
'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController',
85478549
'PhabricatorPeopleManageProfileMenuItem' => 'PhabricatorProfileMenuItem',
8550+
'PhabricatorPeopleManagementWorkflow' => 'PhabricatorManagementWorkflow',
85488551
'PhabricatorPeopleNewController' => 'PhabricatorPeopleController',
85498552
'PhabricatorPeopleNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
85508553
'PhabricatorPeopleOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
85518554
'PhabricatorPeoplePictureProfileMenuItem' => 'PhabricatorProfileMenuItem',
85528555
'PhabricatorPeopleProfileBadgesController' => 'PhabricatorPeopleProfileController',
85538556
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
85548557
'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleProfileController',
8558+
'PhabricatorPeopleProfileImageWorkflow' => 'PhabricatorPeopleManagementWorkflow',
85558559
'PhabricatorPeopleProfileManageController' => 'PhabricatorPeopleProfileController',
85568560
'PhabricatorPeopleProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
85578561
'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleProfileController',

‎src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ final class PhabricatorFilesComposeAvatarBuiltinFile
77
private $color;
88
private $border;
99

10+
const VERSION = 'v1';
11+
1012
public function setIcon($icon) {
1113
$this->icon = $icon;
1214
return $this;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
}

0 commit comments

Comments
 (0)
Failed to load comments.