Blame view

sources/apps/calendar/appinfo/update.php 2.7 KB
d1bafeea1   Kload   [fix] Upgrade to ...
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
  <?php
  
  $installedVersion=OCP\Config::getAppValue('calendar', 'installed_version');
  if (version_compare($installedVersion, '0.2.1', '<')) {
  	$stmt = OCP\DB::prepare( 'SELECT `id`, `calendarcolor` FROM `*PREFIX*clndr_calendars` WHERE `calendarcolor` IS NOT NULL' );
  	$result = $stmt->execute();
  	while( $row = $result->fetchRow()) {
  		$id = $row['id'];
  		$color = $row['calendarcolor'];
  		if ($color[0] == '#' || strlen($color) < 6) {
  			continue;
  		}
  		$color = '#' .$color;
  		$stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*clndr_calendars` SET `calendarcolor`=? WHERE `id`=?' );
  		$r = $stmt->execute(array($color,$id));
  	}
  }
  if (version_compare($installedVersion, '0.5', '<')) {
  	$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
  	foreach($calendars as $calendar) {
  		OC_Calendar_Repeat::cleanCalendar($calendar['id']);
  		OC_Calendar_Repeat::generateCalendar($calendar['id']);
  	}
  }
  if ($installedVersion == '0.6') {
  	// the update script in this version was not correct
  	// also sharing of calendars did not work
  	//$query = OCP\DB::prepare("DELETE FROM `*PREFIX*share` WHERE `item_type` IN ('calendar', 'event')");
  	//$query->execute();
  }
  if (version_compare($installedVersion, '0.6.1', '<=')) {
  	$calendar_stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*clndr_share_calendar`');
  	$calendar_result = $calendar_stmt->execute();
  	while( $cal = $calendar_result->fetchRow()) {
  		$shareType = OCP\Share::SHARE_TYPE_USER;
  		if ($cal['sharetype'] == 'group') {
  			$shareType = OCP\Share::SHARE_TYPE_GROUP;
  		}
  		else if ($cal['sharetype'] == 'public') {
  			$shareType = OCP\Share::SHARE_TYPE_LINK;
  		}
  		OC_User::setUserId($cal['owner']);
  		try {
  			OCP\Share::shareItem('calendar', $cal['calendarid'], $shareType, $cal['share'], $cal['permissions']?31:17); // CRUDS:RS
  		}
  		catch (Exception $e) {
  			// nothing to do, the exception is already written to the log
  		}
  	}
  	$event_stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*clndr_share_event`');
  	$event_result = $event_stmt->execute();
  	while( $event = $event_result->fetchRow()) {
  		$shareType = OCP\Share::SHARE_TYPE_USER;
  		if ($event['sharetype'] == 'group') {
  			$shareType = OCP\Share::SHARE_TYPE_GROUP;
  		}
  		else if ($event['sharetype'] == 'public') {
  			$shareType = OCP\Share::SHARE_TYPE_LINK;
  		}
  		OC_User::setUserId($event['owner']);
  		try {
  			OCP\Share::shareItem('event', $event['eventid'], $shareType, $event['share'], $event['permissions']?31:17); // CRUDS:RS
  		}
  		catch (Exception $e) {
  			// nothing to do, the exception is already written to the log
  		}
  	}
  	//logout and login - fix wrong calendar permissions from oc-1914
  	$user = OCP\User::getUser();
  	session_unset();
  	session_destroy();
  	OC_User::unsetMagicInCookie();
  	session_regenerate_id(true);
  	OC_User::setUserId($user);
  }