4 echo "SabreDAV migrate script for version 3.0\n";
10 This
script help you migrate from
a pre-3.0 database to 3.0
and later
13 * The propertystorage table has changed to allow storage
of complex
15 *
the vcardurl field
in the principals table
is no more. This was moved to
16 the propertystorage table.
18 Keep
in mind
that ALTER TABLE commands will be executed. If you have
a large
19 dataset
this may mean
that this process takes
a while.
22 potential variants
are extremely high, so it
's impossible to deal with every 25 In the worst case, you will lose all your data. This is not an overstatement. 29 php {$argv[0]} [pdo-dsn] [username] [password] 33 php {$argv[0]} "mysql:host=localhost;dbname=sabredav" root password 34 php {$argv[0]} sqlite:data/sabredav.db 42 // There's a bunch
of places where
the autoloader could be, so we
'll try all of 45 __DIR__ . '/../vendor/autoload.php
', 46 __DIR__ . '/../../../autoload.php
', 49 foreach ($paths as $path) { 50 if (file_exists($path)) { 57 $user = isset($argv[2]) ? $argv[2] : null; 58 $pass = isset($argv[3]) ? $argv[3] : null; 60 echo "Connecting to database: " . $dsn . "\n"; 62 $pdo = new PDO($dsn, $user, $pass); 63 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 64 $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); 66 $driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); 71 echo "Detected MySQL.\n"; 74 echo "Detected SQLite.\n"; 77 echo "Error: unsupported driver: " . $driver . "\n"; 81 echo "Upgrading 'propertystorage
'\n"; 82 $addValueType = false; 84 $result = $pdo->query('SELECT * FROM propertystorage LIMIT 1
'); 85 $row = $result->fetch(\PDO::FETCH_ASSOC); 88 echo "No data in table. Going to re-create the table.\n"; 89 $random = mt_rand(1000, 9999); 90 echo "Renaming propertystorage -> propertystorage_old$random and creating new table.\n"; 95 $pdo->exec('RENAME TABLE propertystorage TO propertystorage_old
' . $random); 97 CREATE TABLE propertystorage (
98 id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
99 path VARBINARY(1024) NOT NULL,
100 name VARBINARY(100) NOT NULL,
101 valuetype INT UNSIGNED,
105 $pdo->exec('CREATE UNIQUE INDEX path_property_
' . $random . ' ON propertystorage (path(600), name(100));
'); 108 $pdo->exec('ALTER TABLE propertystorage RENAME TO propertystorage_old
' . $random); 110 CREATE TABLE propertystorage (
111 id integer primary key asc,
118 $pdo->exec('CREATE UNIQUE INDEX path_property_
' . $random . ' ON propertystorage (path, name);
'); 122 } elseif (array_key_exists('valuetype
', $row)) { 123 echo "valuetype field exists. Assuming that this part of the migration has\n"; 124 echo "Already been completed.\n"; 126 echo "2.1 schema detected. Going to perform upgrade.\n"; 127 $addValueType = true; 130 } catch (Exception $e) { 131 echo "Could not find a propertystorage table. Skipping this part of the\n"; 133 echo $e->getMessage(), "\n"; 140 $pdo->exec('ALTER TABLE propertystorage ADD valuetype INT UNSIGNED
'); 143 $pdo->exec('ALTER TABLE propertystorage ADD valuetype INT
'); 148 $pdo->exec('UPDATE propertystorage SET valuetype = 1 WHERE valuetype IS NULL
'); 152 echo "Migrating vcardurl\n"; 154 $result = $pdo->query('SELECT id, uri, vcardurl FROM principals WHERE vcardurl IS NOT NULL
'); 155 $stmt1 = $pdo->prepare('INSERT INTO propertystorage (path, name, valuetype, value) VALUES (?, ?, 3, ?)
'); 157 while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { 159 // Inserting the new record 161 'addressbooks/
' . basename($row['uri
']), 163 serialize(
new Sabre\DAV\Xml\Property\Href(
$row[
'vcardurl']))
166 echo serialize(
new Sabre\DAV\Xml\Property\Href(
$row[
'vcardurl']));
171 echo "Upgrade to 3.0 schema completed.\n";
static http()
Fetches the global http state from ILIAS.