Completed
Push — 16.1 ( 05bf72...884fd0 )
by Hadi
27:28 queued 10:22
created

tables_update.inc.php ➔ api_upgrade16_9()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * EGroupware - API Setup
4
 *
5
 * Update scripts from 16.1 onwards
6
 *
7
 * @link http://www.egroupware.org
8
 * @package api
9
 * @subpackage setup
10
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
11
 * @version $Id$
12
 */
13
14
use EGroupware\Api;
15
16
/**
17
 * Remove rests of EMailAdmin or install 14.1 tables for update from before 14.1
18
 *
19
 * 14.3.907 is the version set by setup, if api is not installed in 16.1 upgrade
20
 *
21
 * @return string
22
 */
23
function api_upgrade14_3_907()
24
{
25
	// check if EMailAdmin tables are there and create them if not
26
	$tables = $GLOBALS['egw_setup']->db->table_names(true);
27
	$phpgw_baseline = array();
28
	include (__DIR__.'/tables_current.inc.php');
29
	foreach($phpgw_baseline as $table => $definition)
30
	{
31
		if (!in_array($table, $tables))
32
		{
33
			$GLOBALS['egw_setup']->oProc->CreateTable($table, $definition);
34
		}
35
	}
36
37
	// uninstall no longer existing EMailAdmin
38
	if (in_array('egw_emailadmin', $tables))
39
	{
40
		$GLOBALS['egw_setup']->oProc->DropTable('egw_emailadmin');
41
	}
42
	$GLOBALS['egw_setup']->deregister_app('emailadmin');
43
44
	// uninstall obsolete FelamiMail tables, if still around
45
	$done = 0;
46
	foreach(array_intersect($tables, array('egw_felamimail_accounts', 'egw_felamimail_displayfilter', 'egw_felamimail_signatures')) as $table)
47
	{
48
		$GLOBALS['egw_setup']->oProc->DropTable($table);
49
50
		if (!$done++) $GLOBALS['egw_setup']->deregister_app('felamimail');
51
	}
52
53
	return $GLOBALS['setup_info']['api']['currentver'] = '16.1';
54
}
55
56
/**
57
 * Add archive folder to mail accounts
58
 *
59
 * @return string
60
 */
61
function api_upgrade16_1()
62
{
63
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_ea_accounts','acc_folder_archive', array(
64
		'type' => 'varchar',
65
		'precision' => '128',
66
		'comment' => 'archive folder'
67
	));
68
69
	return $GLOBALS['setup_info']['api']['currentver'] = '16.1.001';
70
}
71
72
/**
73
 * Fix home-accounts in egw_customfields and egw_links to api-accounts
74
 *
75
 * @return string
76
 */
77
function api_upgrade16_1_001()
78
{
79
	foreach(array(
80
		'cf_type' => 'egw_customfields',
81
		'link_app1' => 'egw_links',
82
		'link_app2' => 'egw_links',
83
	) as $col => $table)
84
	{
85
		$GLOBALS['egw_setup']->db->query("UPDATE $table SET $col='api-accounts' WHERE $col='home-accounts'", __LINE__, __FILE__);
86
	}
87
	return $GLOBALS['setup_info']['api']['currentver'] = '16.1.002';
88
}
89
90
use EGroupware\Api\Vfs;
91
92
/**
93
 * Create /templates and subdirectories, if they dont exist
94
 *
95
 * They are create as part of the installation for new installations and allways exist in EPL.
96
 * If they dont exist, you can not save the preferences of the concerned applications, unless
97
 * you either manually create the directory or remove the path from the default preferences.
98
 *
99
 * @return string
100
 */
101
function api_upgrade16_1_002()
102
{
103
	$admins = $GLOBALS['egw_setup']->add_account('Admins','Admin','Group',False,False);
104
105
	Vfs::$is_root = true;
106
	foreach(array('','addressbook', 'calendar', 'infolog', 'tracker', 'timesheet', 'projectmanager', 'filemanager') as $app)
107
	{
108
		if ($app && !file_exists(EGW_SERVER_ROOT.'/'.$app)) continue;
109
110
		// create directory and set permissions: Admins writable and other readable
111
		$dir = '/templates'.($app ? '/'.$app : '');
112
		if (Vfs::file_exists($dir)) continue;
113
114
		Vfs::mkdir($dir, 075, STREAM_MKDIR_RECURSIVE);
115
		Vfs::chgrp($dir, abs($admins));
116
		Vfs::chmod($dir, 075);
117
	}
118
	Vfs::$is_root = false;
119
120
	return $GLOBALS['setup_info']['api']['currentver'] = '16.1.003';
121
}
122
123
/**
124
 * Change egw_ea_accounts.acc_further_identities from boolean to int(1)
125
 *
126
 * @return string new version
127
 */
128
function api_upgrade16_1_003()
129
{
130
	$GLOBALS['egw_setup']->oProc->RenameColumn('egw_ea_accounts', 'acc_further_identities', 'further_bool');
131
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_ea_accounts','acc_further_identities',array(
132
		'type' => 'int',
133
		'precision' => '1',
134
		'nullable' => False,
135
		'default' => '1',
136
		'comment' => '0=no, 1=yes, 2=only matching aliases'
137
	));
138
	$GLOBALS['egw_setup']->oProc->query('UPDATE egw_ea_accounts SET acc_further_identities=0 WHERE NOT further_bool', __LINE__, __FILE__);
139
	$GLOBALS['egw_setup']->oProc->DropColumn('egw_ea_accounts',
140
		$GLOBALS['egw_setup']->db->get_table_definitions('api', 'egw_ea_accounts'), 'further_bool');
141
142
	return $GLOBALS['setup_info']['api']['currentver'] = '16.1.004';
143
}
144
145
/**
146
 * Fix non-unique multi-column index on egw_sqlfs_props: fs_id, prop_namesape and prop_name
147
 *
148
 * Index needs to be unique as a WebDAV property can only have one value.
149
 *
150
 * MySQL REPLACE used in PROPPATCH otherwise inserts further rows instead of updating them,
151
 * which we also clean up here (MySQL only).
152
 *
153
 * @return string new version
154
 */
155
function api_upgrade16_1_004()
156
{
157
	// delete doublicate rows for identical attributes by only keeping oldest one / highest prop_id
158
	// this is only necessary for MySQL, as other DBs dont have REPLACE
159
	if ($GLOBALS['egw_setup']->db->Type == 'mysql')
160
	{
161
		$junk_size = 100;
162
		$total = 0;
163
		do {
164
			$n = 0;
165
			foreach($GLOBALS['egw_setup']->db->query('SELECT fs_id,prop_namespace,prop_name,MAX(prop_id) AS prop_id
166
FROM egw_sqlfs_props
167
GROUP BY fs_id,prop_namespace,prop_name
168
HAVING COUNT(*) > 1', __LINE__, __FILE__, 0, $junk_size, false, Api\Db::FETCH_ASSOC) as $row)
169
			{
170
				$prop_id = $row['prop_id'];
171
				unset($row['prop_id']);
172
				$GLOBALS['egw_setup']->db->delete('egw_sqlfs_props', $row+array('prop_id != '.(int)$prop_id), __LINE__, __FILE__);
173
				$total += $GLOBALS['egw_setup']->db->affected_rows();
174
				$n++;
175
			}
176
		}
177
		while($n == $junk_size);
178
179 View Code Duplication
		if ($total)
180
		{
181
			echo "Api Update 16.1.005: deleted $total doublicate rows from egw_sqlfs_props table.\n";
182
183
			// drop autoincrement (prop_id) and recreate it, in case it got to close to 32 bit limit
184
			$GLOBALS['egw_setup']->db->query('ALTER TABLE egw_sqlfs_props DROP prop_id', __LINE__, __FILE__);
185
			$GLOBALS['egw_setup']->db->query('ALTER TABLE egw_sqlfs_props ADD prop_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY', __LINE__, __FILE__);
186
		}
187
	}
188
189
	// drop non-unique index and re-create it as unique
190
	$GLOBALS['egw_setup']->oProc->DropIndex('egw_sqlfs_props', array('fs_id', 'prop_namespace', 'prop_name'));
191
	$GLOBALS['egw_setup']->oProc->CreateIndex('egw_sqlfs_props', array('fs_id', 'prop_namespace', 'prop_name'), true);
192
193
	return $GLOBALS['setup_info']['api']['currentver'] = '16.1.005';
194
}
195
196
/**
197
 * Update to 17.1 development as 16.9
198
 *
199
 * @return string
200
 */
201
function api_upgrade16_1_005()
202
{
203
	return $GLOBALS['setup_info']['api']['currentver'] = '16.9';
204
}
205
206
/**
207
 * Give egw_ea_credentials.cred_password size 9600 to accomodate private s/mime keys
208
 *
209
 * @return string
210
 */
211 View Code Duplication
function api_upgrade16_9()
212
{
213
	$GLOBALS['egw_setup']->oProc->AlterColumn('egw_ea_credentials','cred_password',array(
214
		'type' => 'varchar',
215
		'precision' => '9600',
216
		'comment' => 'password encrypted'
217
	));
218
219
	return $GLOBALS['setup_info']['api']['currentver'] = '16.9.001';
220
}
221
222
function api_upgrade16_9_001()
223
{
224
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_ea_accounts','acc_folder_ham',array(
225
		'type' => 'varchar',
226
		'precision' => '128',
227
		'comment' => 'ham folder'
228
	));
229
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_ea_accounts','acc_spam_api',array(
230
		'type' => 'varchar',
231
		'precision' => '128',
232
		'comment' => 'SpamTitan API URL'
233
	));
234
235
	return $GLOBALS['setup_info']['api']['currentver'] = '16.9.002';
236
}
237
238