Skip to content
Snippets Groups Projects
Commit f5deab79 authored by Michael Fairchild's avatar Michael Fairchild
Browse files

Add a migration script

parent 205f29ca
Branches
No related tags found
No related merge requests found
vendor
migration.lock
\ No newline at end of file
<?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']);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment