4 echo "SabreDAV migrate script for version 2.1\n";
10 This
script help you migrate from
a pre-2.1 database to 2.1.
13 The
'calendarobjects' table will be upgraded.
14 'schedulingobjects' will be created.
16 If you don
't use the default PDO CalDAV or CardDAV backend, it's pointless to
19 Keep
in mind
that ALTER TABLE commands will be executed. If you have
a large
20 dataset
this may mean
that this process takes
a while.
23 potential variants
are extremely high, so it
's impossible to deal with every 26 In the worst case, you will lose all your data. This is not an overstatement. 30 php {$argv[0]} [pdo-dsn] [username] [password] 34 php {$argv[0]} "mysql:host=localhost;dbname=sabredav" root password 35 php {$argv[0]} sqlite:data/sabredav.db 43 // There's a bunch
of places where
the autoloader could be, so we
'll try all of 46 __DIR__ . '/../vendor/autoload.php
', 47 __DIR__ . '/../../../autoload.php
', 50 foreach ($paths as $path) { 51 if (file_exists($path)) { 58 $user = isset($argv[2]) ? $argv[2] : null; 59 $pass = isset($argv[3]) ? $argv[3] : null; 61 echo "Connecting to database: " . $dsn . "\n"; 63 $pdo = new PDO($dsn, $user, $pass); 64 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 65 $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); 67 $driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); 72 echo "Detected MySQL.\n"; 75 echo "Detected SQLite.\n"; 78 echo "Error: unsupported driver: " . $driver . "\n"; 82 echo "Upgrading 'calendarobjects
'\n"; 85 $result = $pdo->query('SELECT * FROM calendarobjects LIMIT 1
'); 86 $row = $result->fetch(\PDO::FETCH_ASSOC); 89 echo "No data in table. Going to try to add the uid field anyway.\n"; 91 } elseif (array_key_exists('uid
', $row)) { 92 echo "uid field exists. Assuming that this part of the migration has\n"; 93 echo "Already been completed.\n"; 95 echo "2.0 schema detected.\n"; 99 } catch (Exception $e) { 100 echo "Could not find a calendarobjects table. Skipping this part of the\n"; 108 $pdo->exec('ALTER TABLE calendarobjects ADD uid VARCHAR(200)
'); 111 $pdo->exec('ALTER TABLE calendarobjects ADD uid TEXT
'); 115 $result = $pdo->query('SELECT id, calendardata FROM calendarobjects
'); 116 $stmt = $pdo->prepare('UPDATE calendarobjects SET uid = ? WHERE
id = ?
'); 119 while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { 122 $vobj = \Sabre\VObject\Reader::read($row['calendardata
']); 123 } catch (\Exception $e) { 124 echo "Warning! Item with id $row[id] could not be parsed!\n"; 128 $item = $vobj->getBaseComponent(); 129 if (!isset($item->UID)) { 130 echo "Warning! Item with id $item[id] does NOT have a UID property and this is required.\n"; 133 $uid = (string)$item->UID; 134 $stmt->execute([$uid, $row['id']]); 141 echo "Creating 'schedulingobjects
'\n"; 146 $pdo->exec('CREATE TABLE IF NOT EXISTS schedulingobjects
148 id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
149 principaluri VARCHAR(255),
150 calendardata MEDIUMBLOB,
152 lastmodified INT(11) UNSIGNED,
154 size INT(11) UNSIGNED NOT NULL
155 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
161 $pdo->exec('CREATE TABLE IF NOT EXISTS schedulingobjects (
162 id integer primary key asc,
166 lastmodified integer,
176 echo "Upgrade to 2.1 schema completed.\n";