123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- $shortoptions = '';
- $longoptions = array();
- $helptext = <<<END_OF_UPDATEURLS_HELP
- updateurls.php [options]
- update stored URLs in the system
- END_OF_UPDATEURLS_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- function main()
- {
- updateUserUrls();
- updateGroupUrls();
- }
- function updateUserUrls()
- {
- printfnq("Updating user URLs...\n");
-
- $user = new User();
- if ($user->find()) {
- while ($user->fetch()) {
- printfv("Updating user {$user->nickname}...");
- try {
- $profile = $user->getProfile();
- updateProfileUrl($profile);
- updateAvatarUrls($profile);
- } catch (Exception $e) {
- echo "Error updating URLs: " . $e->getMessage();
- }
- printfv("DONE.");
- }
- }
- }
- function updateProfileUrl($profile)
- {
- $orig = clone($profile);
- $profile->profileurl = common_profile_url($profile->nickname);
- $profile->update($orig);
- }
- function updateAvatarUrls($profile)
- {
- $avatar = new Avatar();
- $avatar->profile_id = $profile->id;
- if ($avatar->find()) {
- while ($avatar->fetch()) {
- $orig_url = $avatar->url;
- $avatar->url = Avatar::url($avatar->filename);
- if ($avatar->url != $orig_url) {
- $sql =
- "UPDATE avatar SET url = '" . $avatar->url . "' ".
- "WHERE profile_id = " . $avatar->profile_id . " ".
- "AND width = " . $avatar->width . " " .
- "AND height = " . $avatar->height . " ";
- if ($avatar->original) {
- $sql .= "AND original = 1 ";
- }
- if (!$avatar->query($sql)) {
- throw new Exception("Can't update avatar for user " . $profile->nickname . ".");
- } else {
- $touched = true;
- }
- }
- }
- }
- }
- function updateGroupUrls()
- {
- printfnq("Updating group URLs...\n");
- $group = new User_group();
- if ($group->find()) {
- while ($group->fetch()) {
- try {
- printfv("Updating group {$group->nickname}...");
- $orig = User_group::getKV('id', $group->id);
- if (!empty($group->original_logo)) {
- $group->original_logo = Avatar::url(basename($group->original_logo));
- $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
- $group->stream_logo = Avatar::url(basename($group->stream_logo));
- $group->mini_logo = Avatar::url(basename($group->mini_logo));
- }
-
- $localUri = common_local_url('groupbyid',
- array('id' => $group->id));
- if ($group->getUri() != $localUri) {
- $group->mainpage = common_local_url('showgroup',
- array('nickname' => $group->nickname));
- }
- $group->update($orig);
- printfv("DONE.");
- } catch (Exception $e) {
- echo "Can't update avatars for group " . $group->nickname . ": ". $e->getMessage();
- }
- }
- }
- }
- main();
|