From 66effbfe0827fc61fff6d248797a894213ad20d6 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sat, 28 May 2016 17:46:24 +0200 Subject: upgrade to sabre32 --- vendor/sabre/dav/bin/build.php | 2 +- vendor/sabre/dav/bin/migrateto17.php | 52 +++---- vendor/sabre/dav/bin/migrateto21.php | 4 - vendor/sabre/dav/bin/migrateto32.php | 268 ++++++++++++++++++++++++++++++++++ vendor/sabre/dav/bin/naturalselection | 2 +- 5 files changed, 296 insertions(+), 32 deletions(-) create mode 100755 vendor/sabre/dav/bin/migrateto32.php (limited to 'vendor/sabre/dav/bin') diff --git a/vendor/sabre/dav/bin/build.php b/vendor/sabre/dav/bin/build.php index 82b1e7530..c4ba20941 100755 --- a/vendor/sabre/dav/bin/build.php +++ b/vendor/sabre/dav/bin/build.php @@ -110,7 +110,7 @@ function test() { echo " Running all unittests.\n"; echo " This may take a while.\n\n"; - system(__DIR__ . '/phpunit --configuration ' . $baseDir . '/tests/phpunit.xml --stop-on-failure', $code); + system(__DIR__ . '/phpunit --configuration ' . $baseDir . '/tests/phpunit.xml.dist --stop-on-failure', $code); if ($code != 0) { echo "PHPUnit reported error code $code\n"; die(1); diff --git a/vendor/sabre/dav/bin/migrateto17.php b/vendor/sabre/dav/bin/migrateto17.php index a1173c584..3ccf0a380 100755 --- a/vendor/sabre/dav/bin/migrateto17.php +++ b/vendor/sabre/dav/bin/migrateto17.php @@ -3,7 +3,7 @@ echo "SabreDAV migrate script for version 1.7\n"; -if ($argc < 2) { +if ($argc<2) { echo <<getAttribute(PDO::ATTR_DRIVER_NAME)) { + switch($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) { case 'mysql' : @@ -150,7 +150,7 @@ $stmt = $pdo->prepare('UPDATE calendarobjects SET etag = ?, size = ?, componentt echo "Total records found: " . $result->rowCount() . "\n"; $done = 0; $total = $result->rowCount(); -while ($row = $result->fetch()) { +while($row = $result->fetch()) { try { $newData = getDenormalizedData($row['calendardata']); @@ -161,14 +161,14 @@ while ($row = $result->fetch()) { echo "This record is ignored, you should inspect it to see if there's anything wrong.\n===\n"; continue; } - $stmt->execute([ + $stmt->execute(array( $newData['etag'], $newData['size'], $newData['componentType'], $newData['firstOccurence'], $newData['lastOccurence'], $row['id'], - ]); + )); $done++; if ($done % 500 === 0) { @@ -188,7 +188,7 @@ if (array_key_exists('transparent', $row)) { echo "Adding the 'transparent' field to the calendars table\n"; - switch ($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) { + switch($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) { case 'mysql' : $pdo->exec("ALTER TABLE calendars ADD transparent TINYINT(1) NOT NULL DEFAULT '0'"); @@ -229,8 +229,8 @@ function getDenormalizedData($calendarData) { $component = null; $firstOccurence = null; $lastOccurence = null; - foreach ($vObject->getComponents() as $component) { - if ($component->name !== 'VTIMEZONE') { + foreach($vObject->getComponents() as $component) { + if ($component->name!=='VTIMEZONE') { $componentType = $component->name; break; } @@ -262,7 +262,7 @@ function getDenormalizedData($calendarData) { $lastOccurence = $maxDate->getTimeStamp(); } else { $end = $it->getDtEnd(); - while ($it->valid() && $end < $maxDate) { + while($it->valid() && $end < $maxDate) { $end = $it->getDtEnd(); $it->next(); @@ -273,12 +273,12 @@ function getDenormalizedData($calendarData) { } } - return [ - 'etag' => md5($calendarData), - 'size' => strlen($calendarData), - 'componentType' => $componentType, + return array( + 'etag' => md5($calendarData), + 'size' => strlen($calendarData), + 'componentType' => $componentType, 'firstOccurence' => $firstOccurence, 'lastOccurence' => $lastOccurence, - ]; + ); } diff --git a/vendor/sabre/dav/bin/migrateto21.php b/vendor/sabre/dav/bin/migrateto21.php index f42c4cf88..c81ee5cca 100755 --- a/vendor/sabre/dav/bin/migrateto21.php +++ b/vendor/sabre/dav/bin/migrateto21.php @@ -169,10 +169,6 @@ switch ($driver) { ) '); break; - $pdo->exec(' - CREATE INDEX principaluri_uri ON calendarsubscriptions (principaluri, uri); - '); - break; } echo "Done.\n"; diff --git a/vendor/sabre/dav/bin/migrateto32.php b/vendor/sabre/dav/bin/migrateto32.php new file mode 100755 index 000000000..59732b511 --- /dev/null +++ b/vendor/sabre/dav/bin/migrateto32.php @@ -0,0 +1,268 @@ +#!/usr/bin/env php +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + +$driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); + +switch ($driver) { + + case 'mysql' : + echo "Detected MySQL.\n"; + break; + case 'sqlite' : + echo "Detected SQLite.\n"; + break; + default : + echo "Error: unsupported driver: " . $driver . "\n"; + die(-1); +} + +echo "Creating 'calendarinstances'\n"; +$addValueType = false; +try { + $result = $pdo->query('SELECT * FROM calendarinstances LIMIT 1'); + $result->fetch(\PDO::FETCH_ASSOC); + echo "calendarinstances exists. Assuming this part of the migration has already been done.\n"; +} catch (Exception $e) { + echo "calendarinstances does not yet exist. Creating table and migrating data.\n"; + + switch ($driver) { + case 'mysql' : + $pdo->exec(<<exec(" +INSERT INTO calendarinstances + ( + calendarid, + principaluri, + access, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent + ) +SELECT + id, + principaluri, + 1, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent +FROM calendars +"); + break; + case 'sqlite' : + $pdo->exec(<<exec(" +INSERT INTO calendarinstances + ( + calendarid, + principaluri, + access, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent + ) +SELECT + id, + principaluri, + 1, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent +FROM calendars +"); + break; + } + +} +try { + $result = $pdo->query('SELECT * FROM calendars LIMIT 1'); + $row = $result->fetch(\PDO::FETCH_ASSOC); + + if (!$row) { + echo "Source table is empty.\n"; + $migrateCalendars = true; + } + + $columnCount = count($row); + if ($columnCount === 3) { + echo "The calendars table has 3 columns already. Assuming this part of the migration was already done.\n"; + $migrateCalendars = false; + } else { + echo "The calendars table has " . $columnCount . " columns.\n"; + $migrateCalendars = true; + } + +} catch (Exception $e) { + echo "calendars table does not exist. This is a major problem. Exiting.\n"; + exit(-1); +} + +if ($migrateCalendars) { + + $calendarBackup = 'calendars_3_1_' . $backupPostfix; + echo "Backing up 'calendars' to '", $calendarBackup, "'\n"; + + switch ($driver) { + case 'mysql' : + $pdo->exec('RENAME TABLE calendars TO ' . $calendarBackup); + break; + case 'sqlite' : + $pdo->exec('ALTER TABLE calendars RENAME TO ' . $calendarBackup); + break; + + } + + echo "Creating new calendars table.\n"; + switch ($driver) { + case 'mysql' : + $pdo->exec(<<exec(<<exec(<<