Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PlanetRed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jeff Sturek
PlanetRed
Commits
f5deab79
Commit
f5deab79
authored
9 years ago
by
Michael Fairchild
Browse files
Options
Downloads
Patches
Plain Diff
Add a migration script
parent
205f29ca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/cas_auth_unl/.gitignore
+2
-1
2 additions, 1 deletion
plugins/cas_auth_unl/.gitignore
plugins/cas_auth_unl/migration.php
+90
-0
90 additions, 0 deletions
plugins/cas_auth_unl/migration.php
with
92 additions
and
1 deletion
plugins/cas_auth_unl/.gitignore
+
2
−
1
View file @
f5deab79
vendor
migration.lock
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/cas_auth_unl/migration.php
0 → 100644
+
90
−
0
View file @
f5deab79
<?php
require_once
__DIR__
.
'/../../elgg/vendor/autoload.php'
;
\Elgg\Application
::
start
();
$lock_file
=
__DIR__
.
'/migration.lock'
;
$lock
=
@
file_get_contents
(
$lock_file
);
if
(
!
$lock
)
{
$lock
=
0
;
}
if
(
!
$users
=
@
file_get_contents
(
'http://planetred.unl.edu/sync.php?start='
.
$lock
))
{
echo
'FAILED TO CONNECT'
.
PHP_EOL
;
exit
();
}
$users
=
json_decode
(
$users
,
true
);
if
(
!
$users
)
{
echo
'FAILED TO DECODE'
.
PHP_EOL
;
exit
();
}
//Copy over avatar stuffs
$context
=
stream_context_create
(
array
(
'http'
=>
array
(
'follow_location'
=>
false
)
)
);
$icon_sizes
=
array
(
'master'
,
'large'
,
'medium'
,
'small'
,
'tiny'
,
'topbar'
);
foreach
(
$users
as
$source_user
)
{
if
(
0
!==
stripos
(
$source_user
[
'username'
],
'unl_'
))
{
//Not a UNL authenticated user
continue
;
}
$target_user
=
get_user_by_username
(
$source_user
[
'username'
]);
if
(
!
$target_user
)
{
//create user
echo
'creating user: '
.
$source_user
[
'username'
]
.
PHP_EOL
;
$password
=
generate_random_cleartext_password
();
try
{
$target_guid
=
register_user
(
$source_user
[
'username'
],
$password
,
$source_user
[
'name'
],
$source_user
[
'email'
],
false
);
}
catch
(
RegistrationException
$e
)
{
echo
"
\t
Unable to create user: "
.
$e
->
getMessage
()
.
PHP_EOL
;
continue
;
}
$target_user
=
get_user
(
$user_guid
);
}
foreach
(
$icon_sizes
as
$size
)
{
if
(
!
$icon
=
@
file_get_contents
(
'http://planetred.unl.edu/pg/icon/'
.
$source_user
[
'username'
]
.
'/'
.
$size
,
false
,
$context
))
{
//No icon was found, skip.
echo
'SKIP'
.
PHP_EOL
;
continue
;
}
echo
'Creating '
.
$size
.
' icon for '
.
$source_user
[
'username'
]
.
PHP_EOL
;
$file
=
new
ElggFile
();
$file
->
owner_guid
=
$target_user
->
guid
;
$file
->
setFilename
(
"profile/
{
$target_user
->
guid
}{
$size
}
.jpg"
);
$file
->
open
(
'write'
);
$file
->
write
(
$icon
);
$file
->
close
();
//Don't overload the server
usleep
(
500000
);
}
// reset crop coordinates
$target_user
->
x1
=
0
;
$target_user
->
x2
=
0
;
$target_user
->
y1
=
0
;
$target_user
->
y2
=
0
;
$target_user
->
icontime
=
time
();
//Update the lock file
file_put_contents
(
$lock_file
,
$source_user
[
'guid'
]);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment