1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
<?php
/**
* Maintenance task for upgrading user prefs after upgrading to Turba 2.2
*
* $Horde: turba/lib/Maintenance/Task/upgradeprefs.php,v 1.11.2.2 2008/06/09 03:28:08 chuck Exp $
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Turba
* @since Turba 2.2
*/
class Maintenance_Task_Turba_upgradeprefs {
/**
* Holds an array of Horde_Share_Object objects.
*
* @var array
*/
var $_shares;
/**
* Perform all functions for this task.
*
* @return mixed True | PEAR_Error
*/
function doMaintenance()
{
global $registry;
if (!empty($_SESSION['turba']['has_share'])) {
$this->_doAddressbooks();
$this->_doColumns();
$this->_doAddSource();
// Now take care of non-Turba prefs.
$apps = $registry->listApps(null, true);
if (!empty($apps['imp'])) {
$registry->loadPrefs('imp');
$this->_doImp();
}
if (!empty($apps['kronolith'])) {
$registry->loadPrefs('kronolith');
$this->_doKronolith();
}
$registry->loadPrefs('turba');
}
return true;
}
/**
* Update Turba's addressbooks pref
*/
function _doAddressbooks()
{
global $prefs;
$abooks = explode("\n", $prefs->getValue('addressbooks'));
if (is_array($abooks) && !empty($abooks[0])) {
$new_prefs = array();
foreach ($abooks as $abook) {
$new_prefs[] = $this->_updateShareName($abook);
}
return $prefs->setValue('addressbooks', implode("\n", $new_prefs));
}
return true;
}
/**
* Update Turba's columns pref
*/
function _doColumns()
{
global $prefs;
// Turba's columns pref
$abooks = explode("\n", $prefs->getValue('columns'));
if (is_array($abooks) && !empty($abooks[0])) {
$new_prefs = array();
$cnt = count($abooks);
for ($i = 0; $i < $cnt; ++$i) {
$colpref = explode("\t", $abooks[$i]);
$colpref[0] = $this->_updateShareName($colpref[0]);
$abooks[$i] = implode("\t", $colpref);
}
return $prefs->setValue('columns', implode("\n", $abooks));
}
return true;
}
function _doAddsource()
{
global $prefs;
$newName = $this->_updateShareName($prefs->getValue('add_source'));
if (!empty($newName)) {
return $prefs->setValue('add_source', $newName);
}
}
/**
* Helper function to update a 'legacy' share name
* to the new flattened share style.
*/
function _updateShareName($book)
{
static $cache = array();
// No sense going through all the logic if we know we're empty.
if (empty($book)) {
return $book;
}
if (empty($this->_shares)) {
$this->_shares = Turba::listShares();
}
// Have we seen this one yet?
if (!empty($cache[$book])) {
return $cache[$book];
}
// Is it an unmodified share key already?
if (strpos($book, ':') !== false) {
list($source, $key) = explode(':', $book, 2);
$source = trim($source);
$key = trim($key);
if (isset($this->_shares[$key])) {
$params = @unserialize($this->_shares[$key]->get('params'));
// I'm not sure if this would ever be not true, but...
if ($params['source'] == $source) {
$cache[$book] = $key;
return $key;
}
} else {
// Maybe a key the upgrade script modified?
foreach ($this->_shares as $skey => $share) {
$params = @unserialize($share->get('params'));
if (!empty($params['name']) && $params['name'] == $key &&
$params['source'] == $source) {
$cache[$book] = $skey;
return $skey;
}
}
}
} else {
// Need to check if this is a default address book for
// one of our sources that is share enabled.
foreach ($this->_shares as $skey => $share) {
$params = @unserialize($share->get('params'));
if ($params['source'] == $book &&
!empty($params['default'])) {
$cache[$book] = $skey;
return $skey;
}
}
}
// Must be a normal, non-shared source, just pass it back.
$cache[$book] = $book;
return $book;
}
/**
* Update IMP's search_sources pref
*/
function _doImp()
{
global $prefs;
$imp_pref = $prefs->getValue('search_sources');
if (!empty($imp_pref)) {
$books = explode("\t", $imp_pref);
$new_books = array();
foreach ($books as $book) {
$new_books[] = $this->_updateShareName($book);
}
$books = implode("\t", $new_books);
return $prefs->setValue('search_sources', $books);
}
return true;
}
function _doKronolith()
{
global $prefs;
$books = @unserialize($prefs->getValue('search_abook'));
if (!empty($books)) {
$new_books = array();
foreach ($books as $book) {
$new_books[] = $this->_updateShareName($book);
}
return $prefs->setValue('search_abook', serialize($new_books));
}
return true;
}
function describeMaintenance()
{
}
}
|