File: migrate_to_sql_driver.php

package info (click to toggle)
kronolith2 2.1.4-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 5,560 kB
  • ctags: 2,171
  • sloc: php: 8,755; xml: 1,049; sql: 258; makefile: 65
file content (58 lines) | stat: -rwxr-xr-x 1,570 bytes parent folder | download | duplicates (2)
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
#!/usr/local/bin/php
<?php
/**
 * $Horde: kronolith/scripts/migrate_to_sql_driver.php,v 1.1.10.2 2006/01/01 21:29:04 jan Exp $
 *
 * Copyright 1999-2006 Charles J. Hagenbuch <chuck@horde.org>
 *
 * See the enclosed file COPYING for license information (GPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 */

@define('AUTH_HANDLER', true);
@define('KRONOLITH_BASE', dirname(__FILE__) . '/..');
require_once KRONOLITH_BASE . '/lib/base.php';

// Set these as required.
$sqlparams = $conf['sql'];

// Create a calendar backend object.
$sqlcal = &Kronolith_Driver::factory('sql', $sqlparams);
$mcal = $kronolith;

// Run through every calendar.
$cals = $kronolith_shares->listAllShares();
foreach ($cals as $calid => $calshare) {
    echo "Converting $calid ...\n";

    if ($mcal->getCalendar() != $calid) {
        $mcal->close();
        $mcal->open($calid);
    }
    if ($sqlcal->getCalendar() != $calid) {
        $sqlcal->close();
        $sqlcal->open($calid);
    }

    // List all events.
    $events = $mcal->listEvents();
    echo count($events) . "\n\n";

    foreach ($events as $eventId) {
        $event = $mcal->getEvent($eventId);
        $newevent = $sqlcal->getEvent();

        foreach ((array)$event as $key => $value) {
            if ($key != 'eventID') {
                $newevent->$key = $value;
            }
        }

        $kronolith = $sqlcal;
        $success = $newevent->save();
        if (is_a($success, 'PEAR_Error')) {
            var_dump($success);
        }
        $kronolith = $mcal;
    }
}