1: <?php
2: /**
3: * Login system task for automated upgrade tasks.
4: *
5: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file LICENSE for license information (BSD). If you
8: * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
9: *
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @category Horde
12: * @license http://www.horde.org/licenses/bsdl.php BSDL
13: * @package Whups
14: */
15: class Whups_LoginTasks_SystemTask_Upgrade extends Horde_Core_LoginTasks_SystemTask_Upgrade
16: {
17: /**
18: */
19: protected $_app = 'whups';
20:
21: /**
22: */
23: protected $_versions = array(
24: '2.0'
25: );
26:
27: /**
28: */
29: protected function _upgrade($version)
30: {
31: switch ($version) {
32: case '2.0':
33: $this->_upgradeAbookPrefs();
34: $this->_upgradeLayout();
35: break;
36: }
37: }
38:
39: /**
40: * Upgrade to the new addressbook preferences.
41: */
42: protected function _upgradeAbookPrefs()
43: {
44: global $prefs;
45:
46: if (!$prefs->isDefault('search_sources')) {
47: $src = $prefs->getValue('search_sources');
48: if (!is_array(json_decode($src))) {
49: $prefs->setValue('search_sources', json_encode(explode("\t", $src)));
50: }
51: }
52:
53: if (!$prefs->isDefault('search_fields')) {
54: $val = $prefs->getValue('search_fields');
55: if (!is_array(json_decode($val, true))) {
56: $fields = array();
57: foreach (explode("\n", $val) as $field) {
58: $field = trim($field);
59: if (!empty($field)) {
60: $tmp = explode("\t", $field);
61: if (count($tmp) > 1) {
62: $source = array_splice($tmp, 0, 1);
63: $fields[$source[0]] = $tmp;
64: }
65: }
66: }
67: $prefs->setValue('search_fields', $fields);
68: }
69: }
70: }
71:
72: /**
73: * Upgrade mybugs_layout preference.
74: */
75: protected function _upgradeLayout()
76: {
77: $bu = new Horde_Core_Block_Upgrade();
78: $bu->upgrade('mybugs_layout');
79: }
80:
81: }
82: