Esempio n. 1
0
        $qs = array();
        $qs[] = "SET NAMES utf8";
        $qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS";
        $qs[] = "REPLACE INTO {$CONFIG->dbprefix}users_entity\n\t\t\t(guid, name, username, password, salt, email, language, code,\n\t\t\tbanned, admin, last_action, prev_last_action, last_login, prev_last_login)\n\n\t\t\tSELECT guid, name, unhex(hex(convert(username using latin1))),\n\t\t\t\tpassword, salt, email, language, code,\n\t\t\t\tbanned, admin, last_action, prev_last_action, last_login, prev_last_login\n\t\t\tFROM {$CONFIG->dbprefix}users_entity";
        $qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS";
        foreach ($qs as $q) {
            if (!update_data($q)) {
                throw new Exception('Couldn\'t execute upgrade query: ' . $q);
            }
        }
        global $DB_QUERY_CACHE, $DB_PROFILE, $ENTITY_CACHE;
        /**
        			Upgrade file locations
        */
        // new connection to force into utf8 mode to get the old name
        $link = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, TRUE);
        mysql_select_db($CONFIG->dbname, $link);
        // must be the first command
        mysql_query("SET NAMES utf8");
        $users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity\n\t\t\tWHERE username != ''", $link);
        while ($user = mysql_fetch_object($users)) {
            $DB_QUERY_CACHE = $DB_PROFILE = $ENTITY_CACHE = array();
            $to = $CONFIG->dataroot . user_file_matrix($user->guid);
            foreach (array('1_0', '1_1', '1_6') as $version) {
                $function = "file_matrix_{$version}";
                $from = $CONFIG->dataroot . $function($user->username);
                merge_directories($from, $to, $move = TRUE, $preference = 'from');
            }
        }
    }
}
Esempio n. 2
0
/**
 * Scans a directory and moves any files from $from to $to
 * preserving structure and handling existing paths.
 * Will no overwrite files in $to.
 *
 * TRAILING SLASHES REQUIRED.
 *
 * @param string $from       From dir.
 * @param string $to         To dir.
 * @param bool   $move       True to move, false to copy.
 * @param string $preference to|from If file collisions, which dir has preference.
 *
 * @return bool
 */
function merge_directories($from, $to, $move = false, $preference = 'to')
{
    if (!($entries = scandir($from))) {
        return false;
    }
    // character filtering needs to be elsewhere.
    if (!is_dir($to)) {
        mkdir($to, 0700, true);
    }
    if ($move === true) {
        $f = 'rename';
    } else {
        $f = 'copy';
    }
    foreach ($entries as $entry) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        $from_path = $from . $entry;
        $to_path = $to . $entry;
        // check to see if the path exists and is a dir, if so, recurse.
        if (is_dir($from_path) && is_dir($to_path)) {
            $from_path .= '/';
            $to_path .= '/';
            merge_directories($from_path, $to_path, $move, $preference);
            // since it's a dir that already exists we don't need to move it
            continue;
        }
        // only move if target doesn't exist or if preference is for the from dir
        if (!file_exists($to_path) || $preference == 'from') {
            if ($f($from_path, $to_path)) {
                //elgg_dump("Moved/Copied $from_path to $to_path");
            }
        } else {
            //elgg_dump("Ignoring $from_path -> $to_path");
        }
    }
}