Skip to content

Commit

Permalink
Adds new upgrade script to fix bad paths in user profile extensions a…
Browse files Browse the repository at this point in the history
…nd default avatar. Also updates the fix_database upgrade script to only run when upgrading from OLD versions. [#456 #458 state:resolved]
  • Loading branch information
dleffler committed Jan 10, 2012
1 parent 32ab5d7 commit 4210714
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion install/upgrades/fix_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class fix_database extends upgradescript {
protected $from_version = '0.96.3';
// protected $to_version = '2.0.1';
protected $to_version = '2.0.1'; // we no longer need to do this for every upgrade, only from OLD ones

/**
* name/title of upgrade script
Expand Down
92 changes: 92 additions & 0 deletions install/upgrades/update_profile_paths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

##################################################
#
# Copyright (c) 2004-2011 OIC Group, Inc.
# Written and Designed by James Hunt
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################

/**
* @subpackage Upgrade
* @package Installation
*/

/**
* This is the class update_profile_paths
*/
class update_profile_paths extends upgradescript {
protected $from_version = '1.99.0';
protected $to_version = '2.0.3'; // code was corrected in 2.0.4

/**
* name/title of upgrade script
* @return string
*/
function name() { return "Corrects bad user profile extension path entries"; }

/**
* generic description of upgrade script
* @return string
*/
function description() { return "Prior to Exponent 2.0.4, the User profile extension table contained full paths which prevented moving Exponent to a new folder after a test install.
There was also an issue with the default user avatar path entry. This Script deletes the bad entry placing the correct ones"; }

/**
* additional test(s) to see if upgrade script should be run
* @return bool
*/
function needed() {
return true; // we'll just do it ine very instance instead of testing if user profile extensions are active
}

/**
* coverts all headline modules/items into text modules/items and deletes headline controller files
* @return bool
*/
function upgrade() {
global $db;

// update each bad default avatar reference to default
$badavatarurls = $db->selectObjects('user_avatar',"image = ''URL_FULL .'");
foreach ($badavatarurls as $badavatarurl) {
$badavatarurl->image = URL_FULL.'framework/modules/users/assets/images/avatar_not_found.jpg';
$db->updateObject($badavatarurl,'user_avatar');
}

// convert each active user profile extension path from a full to relative path
$extdirs = array(
'framework/modules/users/extensions',
'themes/'.DISPLAY_THEME.'framework/modules/users/extensions'
);
foreach ($extdirs as $dir) {
if (is_readable(BASE.$dir)) {
$dh = opendir(BASE.$dir);
while (($file = readdir($dh)) !== false) {
if (is_file(BASE."$dir/$file") && is_readable(BASE."$dir/$file") && substr($file, 0, 1) != '_' && substr($file, 0, 1) != '.') {
$classname = substr($file,0,-4);
$extension = $db->selectObject('profileextension', "classname='".$classname."'");
if (!empty($extension->id)) {
$extension->classfile = "$dir/$file";
$db->updateObject($extension,'profileextension');
}
}
}
}
}

return gt('User Profile Extension Paths Corrected');
}
}

?>

0 comments on commit 4210714

Please sign in to comment.